Add new comment

Adding Bluetooth support to a WEC7 kernel

Recently I had to add Bluetooth support to a custom board running Windows Embedded Compact 7. The Bluetooth module was CSR compatible connected to UART2. To enable the driver for this module you'll have to add the following registry settings to platform.reg:

; @CESYSGEN IF CE_MODULES_BTHCSR
[HKEY_LOCAL_MACHINE\Software\Microsoft\Bluetooth\Transports\BuiltIn\1]
    "driver"="bthcsr.dll"
    "flags"=dword:1
    "name"="COM2:"
    "baud"=dword:1c200
    "resetdelay"=dword:300
; @CESYSGEN ENDIF

You'll have to adjust the baudrate and COM port to match your configuration. The Bluetooth universal loader (SYSGEN_BTH) first looks for PnP devices (like USB/SDIO) and if it can't find any of those it will look for devices listed in the above Bluetooth\Transports\BuiltIn key in the order they are listed.

When I first added support for Bluetooth I just clicked all of the available items in the catalog:

  • Bluetooth Profile Management APIs (SYSGEN_BTH_BTHUTIL)
  • Bluetooth Stack with Universal Loadable Driver (SYSGEN_BTH)
  • Bluetooth HID - Keyboard (SYSGEN_BTH_HID_KEYBOARD)
  • Bluetooth HID - Mouse (SYSGEN_BTH_HID_MOUSE)
  • Bluetooth HS/HF and Audio Gateway Service (SYSGEN_BTH_AG)
  • Bluetooth PAN (SYSGEN_BTH_PAN)
  • Bluetooth Settings UI (SYSGEN_BTH_SETTINGS)

After rebuilding the OS Design the universal loader just did not want to load the driver I specified under the Bluetooth\Transports\BuiltIn key. Without (premium shared) source code of the universal loader it was very difficult to find out what was going wrong. All I could go on was the debug messages outputted by the Bluetooth Module, which I enabled by adding this key to the device's registry (in OSDesign.reg):

; Debug Zones
[HKEY_LOCAL_MACHINE\DebugZones]
        "BTD"=dword:E404

Unfortunately the debug messages did not give any clue as to why it did not want to load the driver I specified. In the end I decided to just select the Universal Loadable Driver (SYSGEN_BTH) in the catalog and deselect everything else, just to get rid of all other unrelated Bluetooth messages. To my surprise all of a sudden the driver did load!

I copied the reginit.ini from the release folder to a temporary folder, selected all Bluetooth components again and rebuilt the kernel. I then compared the reginit.ini of the kernel with only the universal loader component selected with the reginit of the kernel with all Bluetooth components selected. That way I discovered the culprit component was the Bluetooth Profile Management APIs (SYSGEN_BTH_BTHUTIL) component.

This component adds the following registry settings:

[HKEY_LOCAL_MACHINE\Software\Microsoft\Bluetooth\sys]
   "Power"=dword:0                  ; Radio off by default
   "ScanMode"=dword:0               ; Radio is not discoverable
   "DisableAutoSuspend"=dword:1     ; Allow suspend when connected

This disables the radio by default, hence the driver did not load.

So, when you want to enable Bluetooth at boot and you include the Bluetooth Profile Management APIs component, you'll have to override these registry values either inside platform.reg or OSDesign.reg:

; @CESYSGEN IF CE_MODULES_BTD
; @CESYSGEN IF OSSVCS_MODULES_BTHUTIL
[HKEY_LOCAL_MACHINE\Software\Microsoft\Bluetooth\sys]
   "Power"=dword:1                  ; Radio on by default
   "ScanMode"=dword:3               ; Radio is discoverable
   "DisableAutoSuspend"=dword:1     ; Allow suspend when connected
; @CESYSGEN ENDIF OSSVCS_MODULES_BTHUTIL
; @CESYSGEN ENDIF CE_MODULES_BTD