7 years, 4 months ago.

Are there any USB Host libraries for K64F?

Hello, I wanted to connect USB keyboard to my board but official USB Host library does not support K64F. I found another USB Host library (http://mbed.org/users/va009039/code/F401RE-USBHost/) for FRDM-KL46Z/FRDM-KL25Z which are quite similar to K64F in my opinion. I successfully compiled USB Host Keyboard example using that library but the LEDs on my keyboard do not light up. Did I do something wrong and can I even use that library for K64F?

If not, are there any libraries or examples for using USB Host capability of K64F?

Thanks in advance for help.

Question relating to:

The Freedom-K64F is an ultra-low-cost development platform for Kinetis K64, K63, and K24 MCUs.

I want the blue led to toggle when a key is pressed andto say what key was pressed in terminal. Here is the code I am using. By the way, I am still using the USB Host library mentioned in my first post.

My program

#include "mbed.h"
#include "USBHostKeyboard.h"
#include "rtos.h"
DigitalOut led_green(LED_GREEN);
DigitalOut led_blue(LED_BLUE);
USBHostKeyboard keyboard;
void onKey(uint8_t key) {
    printf("Key: %c\r\n", key);
    led_blue=!led_blue;
    
}
 
void keyboard_task(void const *) {
    
    while(1) {
        // try to connect a USB keyboard
        while(!keyboard.connect())
            Thread::wait(500);
    
        // when connected, attach handler called on keyboard event
        keyboard.attach(onKey);
        
        // wait until the keyboard is disconnected
        while(keyboard.connected())
            Thread::wait(500);
    }
}
 
int main() {
    Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 256 * 4);
    led_blue=1;
    led_green=1;
    
    keyboard.attach(onKey);
    while(1) {
        
        led_green=!led_green;
        if(keyboard.connected())
        {
           printf("Connected\n");
        }
        Thread::wait(500);
    }
}
posted by Simonas Ju 28 Jul 2014

2 Answers

7 years, 4 months ago.

Hello,

yes, K64F using the same usb peripheral (I compared it to other kinetis platforms availble here on mbed). The difference is the MPU unit for K64F, which caused an issue for USB Device.

Can you test the application with MPU disabled? The code is : MPU->CESR = 0;

Regards,
0xc0170

Thanks for quick answer, I added that line and now in terminal it recognizes the keyboard but it still doesn't work (no LEDs light up and terminal does not show key presses). I guess the board cannot supply enough power? Or is it software related?

posted by Simonas Ju 23 Jun 2014

There's external power source, you can try to use that. I am familiar with usb host power specification. Check User Manual for the board which specifies the power management on the board. I believe this is SW related

posted by Martin Kojtal 23 Jun 2014

Well, I finally got a powered USB hub but I tried using my program and it still didn't work. What else I can try to solve this problem?

posted by Simonas Ju 28 Jul 2014

You may have known this already (and if not, you probably don't care any more), but J21 must be closed (jumper seated) in order to power the K64 USB port on the FRDM-K64F.

posted by Aaron Campbell 22 Jan 2016
5 years, 10 months ago.

There is no solution and there will be no solution in the MBED world. I spent many days to find one and it's frustrating. Hopefully someday in the new MBED 3.0 release. Unfortunately not available in the Technology Preview 3.0. But hey, with other boards the situation is not better. For instance LPC4088 QSP and LPC1768 do not work as expected too. And if someone makes the proposal "try to use an example of KDS/KSDK ", he should try to add Ethernet functionality. Good luck. The hardware is quite good, but the software libraries and the documentation in particular are not like expected.

Check: https://developer.mbed.org/users/va009039/code/F401RE-USBHost/.

Ethernet should be supported using the normal Ethernet lib. LPC4088 could be that second usb port is not supported, for the LPC1768 it should work.

That said I do think it is sad to see that all mbed stuff seems to be ignored and only mbed 3.0 apparantly they work on.

posted by Erik - 29 Nov 2015

I know this library from Norimasa Okamoto and tried it to debug many times. No success using a FDRM-K64F. In my case I connected a barcode scanner. LPC4088 and LPC1768 have a delay in processing the data, because the interrupt rx handler processes many calls with size=0. The only board which works well is KL46Z. But I need Ethernet in addition...

posted by Mary Jane 01 Dec 2015