7 years, 7 months ago.

KL25Z USB Keyboard I/O Problem

I am using the USBDevice libraries with the KL25Z, to provide a USB Keyboard device.

As soon as Include the keyboard code with:

USBKeyboard keyboard;

the other I/O ports do not work correctly.

For instance, just declaring the DigitalOutput for the LED's means I have no control over the LED's, setting high or low, they are always on.

I also use PTB9 as an input, it always reads high.

The code below demonstrates the issue, the LED is orange if the USBKeyboard line is included, but flashes red/green if commented out

#include "mbed.h"
#include "USBKeyboard.h"

DigitalOut green (LED_GREEN);
DigitalOut red (LED_RED);
DigitalIn  sensor (PTB9);
USBKeyboard keyboard;

int main()
    while (1) {
        green = 1;
        red = 0;
        wait (1);
        green = 0;
        red = 1;
        wait (1);

Hello Dave Kelly,

your application gets trapped (blocking call) inside connect function (USBDevice::Connect). It is invoked inside the USBKeyboard's constructor.

Here's it's definition: <<code> void USBDevice::connect(void) { /* Connect device */ USBHAL::connect(); /* Block if not configured */ while (!configured()); } <</code>


posted by Martin Kojtal 11 Sep 2013

1 Answer

Dave Kelly
7 years, 7 months ago.


All I needed to do was plug it in the other USB socket!

I had trouble debugging originally, which is why I switched to using the SDA to power/program the board

Accepted Answer