You are on page 1of 52

WinHEC

Download WinHEC presentations here:


http://channel9.msdn.com/Events/WinHEC/2015
GPIO I2C, SPI UART
Used as an interrupt or Simple Peripheral High Speed UART
for general I/O Buses (SPB) = I2C, SPI Up to 20Mbps
Buttons, switches, I2C: 100Kbps-3.4Mbps, No COM ports
lights, system wake, SPI: Up to 160Mbps Typically used for:
etc. Typically used for: Bluetooth,
Interrupts for SPB, Input / HID GPS
serial, and other buses Radios
Sensors
Power management
System Chipset

I2C 1 I2C 2

Accelerometer Ambient Light Touchpad Bluetooth


Sensor Radio
ACPI

I2C GPIO I2C UART

Resource Hub

IHV
SoC Vendor
Microsoft
Ambient Light Bluetooth
Accelerometer Touchpad
Sensor Radio
UMDF Class Extension Driver (e.g. Sensor Class Extension)

Peripheral Device Driver


UMDF

KMDF Class Extension Bus KMDF Class Extension Bus


Driver Driver

Bus Controller Driver Bus Controller Driver


KMDF
IHV
SoC Vendor
Peripheral Hardware
Microsoft
Device Driver

GPIO Class Extension


Driver (GpioClx.sys)

GPIO Controller Driver

Physical Hardware
Device Driver

SPB Framework Extension


(SpbCx.sys)

I2C or SPI Controller Driver

Physical Hardware
Device Driver

Serial Framework Extension


(SerCx2.sys)

Serial (UART) Controller


Driver

Physical Hardware
UMDF V2 Sensors Class Extension

ADXL345Acc Driver
(UMDF V2.0)

SpbCx.sys GpioClx.sys

I2C Controller GPIO Controller


Driver Driver

ADXL345Acc Peripheral
Sharkscove Minnowboard Qualcomm Raspberry Pi 2
Max Reference
Board
OS Architecture X86 X86, x64 ARM ARM
Operating System SKU Supported Desktop, IOT Desktop, IOT Mobile, IOT IOT
GPIO Capabilities 2 dedicated GPIO, 3 dedicated GPIO @
Supported 40 Pins
- # available GPIO Lines 6 assigned 1.8-4.2V 3.3V

I2C Capabilities 5 shared controllers


Supported
100Kbps - 3.4Mb/s 2Mb/s @3.3 V Supported
(# Controllers; Max Speed) (Bitbang)
@1.8V
SPI Capabilities 2 controllers Supported
N/A Supported
(# Controllers; Max Speed) 15Mb/s @ 3.3V (low speed bitbang)

UART Capabilities 2 controllers, 1


2 controllers Supported
header Supported
- Max BAUD Rates 3,686,400 @ 3.3V (1Mbps)
3,686,400
Visual Studio
IC
2 Accelerometer
Code Sample
UEFI
Device(SPBA)
{
Name (_HID, "ADXL0345")
Name(_CRS, ResourceTemplate ()
{
I2CSerialBus(0x53, ControllerInitiated, 400000,
AddressingMode7Bit, "\\_SB.I2C3", 0, ResourceConsumer)
GpioInt(Edge, ActiveHigh, Exclusive, PullDown, 0,
"\\_SB.GPO2") {0x17}
})
}
var platform = Platforms.Createx86Platform(
"PWIE", "EDK2", "PWIE", 1, "SSDT");
var sensor = platform.AddGenericDevice(
"ADXL", @"ADXL0345", 1);

sensor.AddI2CSerialBus(
SlaveAddress: 0x53,
Mode: SlaveMode.ControllerInitiated,
ConnectionSpeed: 400 * 1000,
addressmode: AddressMode._7Bit,
controllername: @"\_SB_.I2C3");

sensor.AddGPIOInterrupt(
Type: InterruptType.Level,
ActiveLevel: InterruptActiveLevel.ActiveHigh,
Shared: SharingLevel.Exclusive,
PinConfiguration: PinConfiguration.Down,
DebounceTimeout: 0,
PinNumber: 1,
Source: @"\_SB_.GPO2");

platform.WriteAsl();
ASL is difficult to debug, but with ACPIGenFx developers will experience fewer bugs at runtime.
INF

[Version]
Signature = "$Windows NT$"
Class = Sensor
ClassGuid= {5175D334-C371-4806-B3BA-71FD53C9258D}
Provider=%ManufacturerName%
CatalogFile=ADXL345Acc.cat
DriverVer=

[Manufacturer]
%ManufacturerName%=Standard,NT$ARCH$

[Standard.NT$ARCH$]
%DeviceName%=MyDevice_Install, ACPI\ADXL0345

[Strings]
ManufacturerName="Me"
DeviceName="ADXL345Acc Device"
[Version]
Signature = "$Windows NT$"
Class = Sensor
ClassGuid= {5175D334-C371-4806-B3BA-71FD53C9258D}
Provider=%ManufacturerName%
CatalogFile=ADXL345Acc.cat
DriverVer=

[Manufacturer]
%ManufacturerName%=Standard,NT$ARCH$

[Standard.NT$ARCH$]
%DeviceName%=MyDevice_Install, ACPI\ADXL0345

[Strings]
ManufacturerName="Me"
DeviceName="ADXL345Acc Device"
[Version]
Signature = "$Windows NT$"
Class = Sensor
ClassGuid= {5175D334-C371-4806-B3BA-71FD53C9258D}
Provider=%ManufacturerName%
CatalogFile=ADXL345Acc.cat
DriverVer=

[Manufacturer]
%ManufacturerName%=Standard,NT$ARCH$

[Standard.NT$ARCH$]
%DeviceName%=MyDevice_Install, ACPI\ADXL0345

[Strings]
ManufacturerName="Me"
DeviceName="ADXL345Acc Device"
Windows Sample Driver enabling the Tips and Tricks
following developer scenarios: 1. Device you intend
Opens a handle to the SPB controller, use to load SpbTestTool
the SPB interface from a KMDF driver, and driver on must be
employ GPIO passive-level interrupts.
It implements a set of commands for
defined in ACPI (e.g
ACPI\HWID1234).
communicating with a peripheral device to
aid in debugging. 2. See spbtesttool.asl
References: in the source code
https://code.msdn.microsoft.com/windo for a complete
wshardware/SpbTestTool- example.
adda6d71#content
Windows Apps and Low Power Buses
Provide Windows Apps access to low level I2C, SPI
and GPIO devices for IOT scenarios and
diagnosability.

WinRT APIs in the Windows.Devices namespace


that provide easy access to these devices to
Windows Apps.

Available first on Windows Athens (IoT) OS


editions and then on other editions too.
WinRT APIs Details
Windows.Devices.[GPIO|SPI|I2C]
APIs follow existing Windows.Devices API patterns and give direct
access to these busses either in shared or exclusive access mode
Samples available identifying the common use-cases.
// Blink the LED 10 times.
for (int i = 0; i < 10; ++i)
{
pin.Write(GpioPinValue.Low);
await Task.Delay(200);
pin.Write(GpioPinValue.High);
await Task.Delay(200);
}
Hardware Lab Kit Content Tips and Tricks for OEMs
1. HLK version targeted
Device Testing IHVs at SoC Vendors QA
No LPB specific assessments needed. team. Simpler UI and
Each Device Class has its own streamlined
requirements and associated
assessments in HLK to exercise the code 2. MSDN provides
headless versions (no
UI / command line).
Controller testing OEMs 1. Richer command line
Primarily targeted for SOC silicon Vendors options
OEMs can optionally run the tests but 2. Tests can be run
need open chassis systems individually
3. No need for HLK server
Multiple Interface Test Tool (MITT)
GPIO
Microsoft developed test tool for validating
Hardware/Software
Supported buses : I2C, GPIO, UART, SPI.
Firmware and software provided by Microsoft
Framework for additional development by the
hardware developer available.
Available at Diligent and JJG Technologies
References: https://msdn.microsoft.com/en-
us/library/windows/hardware/dn919874%2 I2C
8v=vs.85%29.aspx
SPI
Troubleshooting
INF Errors
Topic: Driver not loading
correctly on hardware
Design
SetupAPI logs information about
device installation. Use it to verify
or troubleshoot device installation
Filename: SetupAPI.dev.log (in
%SystemRoot%\inf)
References:
https://msdn.microsoft.com/en-
us/library/windows/hardware/ff
547657(v=vs.85).aspx
Troubleshooting
I2C Removable Devices
ACPI tables must identify devices that may be attached in future.
a. Device present at boot? Set _STA == 0x0F; else Set _STA == 0x00
b. Device removed/connected after boot: the platform triggers a Platform Event
(GPIO interrupt or GPE Event). The handler (_Lxx/_Exx/_EVT) must:
i. Change accordingly the value of _STA for each device that arrived/disappeared
ii. Signal the OS that a BUS CHECK event has occurred using the Notify() operator. Send the
notification to the lowest parent of ALL CHANGED DEVICES in the table.

ACPI will re-enumerate devices below the notified device (e.g. ALS,),
removing or adding Windows device nodes as appropriate.
Windows will load drivers, or ADD_DEVICE to already loaded drivers.
Troubleshooting
WPP Tracing
Topic: How to debug loading and
runtime errors in your driver
Design
Trace GUID (in SensorsTrace.h)
Sensor device unique GUID (in
device.cpp)

Traceview: configures and controls


trace sessions and displays
formatted trace messages from
real-time trace sessions
Code 10,
why?
Demo :
Debugging an
issue in the SPB
Peripheral Driver
Common Errors & Best Practices
HID I2C Specific Errors: Best Practices for LPB drivers:
Hid I2C Class driver Code 10 Test your peripheral on a
Errors in HID or Report development board first.
Descriptor. LPB Peripherals drivers should
Hid I2C Class driver Code 28 start with UMDF (ensure that
Device failed the Set_power HID Major Version is 2).
I2C command. Try to have dedicated GPIO line
Turn on ETW/WPP Tracing in for peripheral reset. This helps
HIDI2C to debug specifics issues. hard reset a stuck device.
Get a jump-start on writing LPB peripheral
drivers
1. Visit the sensors talk and lab at WinHEC to
practice what you learned today.
2. Attend the sensors booth to review our custom
sensors demo
3. Review our samples and documentation on
MSDN. Send us feedback / questions
4. Run HLK and validation tools
GPIO https://msdn.microsoft.com/en-us/library/windows/hardware/hh439509(v=vs.85).aspx
SPB https://msdn.microsoft.com/en-us/library/windows/hardware/hh450906(v=vs.85).aspx
UART https://msdn.microsoft.com/en-us/library/windows/hardware/ff547453(v=vs.85).aspx
Spb cookbook https://msdn.microsoft.com/en-us/library/windows/hardware/dn760712(v=vs.85).aspx
MITT https://msdn.microsoft.com/en-us/library/windows/hardware/dn919874%28v=vs.85%29.aspx
WPP Tracing https://msdn.microsoft.com/en-us/library/windows/hardware/ff547657(v=vs.85).aspx
Grand Ballroom III Mansion VIII
12:30 Introduction to Hardware Lifecycle
13:40 Tools for Windows Driver Development

15:00 Intro to Windows Driver Development


16:10 Writing Drivers with the WDF

<Day 2>

10:30 Lab: Getting Started with Driver Dev


11:30 Lunch Lunch
12:30 Accessing GPIO, I2C, and UART devices Lab: Driver Testing and Debugging
13:40 Driver Testing and Debugging Lab: Sensor Driver on Sharks Cove

15:00 Testing with the Hardware Lab Kit Lab: Sensor Driver on Sharks Cove
16:10 Intro to Driver Signing, Distribution, Servicing Lab: Testing with the Hardware Lab Kit
17:20 Lab: Testing with the Hardware Lab Kit
<Day 3>

09:00 Lab: Getting Started with Driver Dev


10:10 Lab: Driver Testing and Debugging
WinHEC
(c) 2015 Microsoft Corporation. All rights reserved. This document is provided "as-is." Information and views
expressed in this document, including URL and other Internet Web site references, may change without notice. You
bear the risk of using it. This document does not provide you with any legal rights to any intellectual property in any
Microsoft product. You may copy and use this document for your internal, reference purposes.

Some information relates to pre-released product which may be substantially modified before its commercially
released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
ISSUE: HIDI2C driver is not loaded in Device Manager for
the DEVICE (I2C Peripheral), but I2C Controller driver is
loaded
REASON: Invalid ASL Code for HOST or DEVICE. Errors in
ASL manifest as:
The HIDI2C driver will not load (INF match failed - see
setupapi.dev.log)
The HIDI2C driver will load with Error Code 10. (More
details to follow).
OEM must ensure highlighted items are valid
_HID (Vendor specific) and _CID ( fixed to PNP0C50)
I2C Controller and Device characteristics are accurate
HID Descriptor Address is correctly Identified for that specific
DEVICE
Please pay special attention to the following
GPIO Interrupt is correctly identified and marked as Exclusive,
Level, ActiveLow
ISSUE: HIDI2C driver is Error Code 10 in Device
Byte Field VALUE Notes
Offset (HEX)
Manager
REASON: If the DEVICE has an invalid HID 0 wHIDDescLength 00 18 Fixed

Descriptor, the HIDI2C driver loads with Error 2 bcdVersion 01 00 Fixed


Code 10. 4 wReportDescLength TBD Device IHV must set correctly
Did the HOST retrieve correct HID Descriptor
from DEVICE. If not, focus on the following
6 wReportDescRegister TBD Device IHV must set correctly

Validate HID Descriptor Address entry in ASL. 8 wInputRegister TBD Device IHV must set correctly

Observe I2C traffic to DEVICE to see if HOST is 10 wMaxInputLength TBD Device IHV must set correctly
requesting correctly.
12 wOutputRegister TBD Device IHV must set correctly
Did the HOST retrieve correct response to Reset
(HIR) from the DEVICE. If not, focus on the 14 wMaxOutputLength TBD Device IHV must set correctly

following 16 wCommandRegister TBD Device IHV must set correctly

Validate entries in Byte Offset 16 and 18 of HID Descriptor 18 wDataRegister TBD Device IHV must set correctly
Validate the DEVICE responded correctly to HIR request
(asserted GPIO Interrupt + 0x00 0x00 in Input Register) 20 RESERVED 00 00 00 00 Fixed

<Continued on next page>


SAMPLE ACCELEROMETER REPORT DESCRIPTOR
======================================

Did the HOST retrieve correct Report Descriptor


USAGE_PAGE (Sensors) 05 15
USAGE (Motion: Accelerometer 3D) 09 73
from DEVICE and did HIDPARSE succeed in COLLECTION (Physical) A1 00
parsing the Report Descriptor. If not, focus on //<FEATURES>

the following USAGE (Property: Connection Type)


LOGICAL_MINIMUM (0)
0A
15
09 03
00
If Report Descriptor is NOT retrieved from the LOGICAL_MAXIMUM (255) 26 FF 00
DEVICE, REPORT_SIZE (16) 75 10
1. Ensure enumeration sequence has passed all REPORT_COUNT (1) 95 01
steps before Report Descriptor retrieval. FEATURE (Data,Var,Abs) B1 02

2. Ensure Byte Offset 4 and 6 in HID Descriptor


are valid and correct (especially length).
If the Report Descriptor is retrieved from the DEVICE
but still fails //Shake Event Notification
1. Validate the wReportDescLength field to USAGE (Data: Motion Intensity) 0A 51 04
ensure that the entire Report Descriptor was LOGICAL_MINIMUM (0) 15 00
retrieved. LOGICAL_MAXIMUM (64)
REPORT_SIZE (8)
25
75
40
08
2. Validate HID Report is correctly formatted INPUT (Data,Var,Abs) 81 02
based on the device class driver specifications. //</INPUT>
Test on an alternative bus like USB to validate END_COLLECTION C0
conformance.
ISSUE: HIDI2C driver is not receiving any input reports
when device has data
REASON: Please review the following in order
Incorrect values in Byte Offset 8 and 10 of HID Descriptor.
GPIO line not being asserted by the DEVICE or being
acknowledged by the HOST driver.
The Input Report is malformed (doesnt conform to the
Report Descriptor) and is being discarded by the operating
systems HID Parser
The Input Report is not is accordance with the requirements
of the class driver for that HID device class and hence is not
being utilized.
(c) 2015 Microsoft Corporation. All rights reserved. This document is provided "as-is." Information and views
expressed in this document, including URL and other Internet Web site references, may change without notice. You
bear the risk of using it. This document does not provide you with any legal rights to any intellectual property in any
Microsoft product. You may copy and use this document for your internal, reference purposes.

Some information relates to pre-released product which may be substantially modified before its commercially
released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

You might also like