This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STM32L USB Driver for Keil

A good day to all,

does anybody know about an USB low level driver file for the Keil lib on STM32L chips?

Unfortunately Keil supports - up to now - only the F-Types in full and high speed.

The ones I find are:

usbd_STM32F103.c
usbd_STM32F10x_cl.c
usbd_STM32F2xx_FS.c
usbd_STM32F2xx_HS.c
usbd_STM32F4xx_FS.c
usbd_STM32F4xx_HS.c

thanks in advance,
Uli

  • The USB device engine on STM32L is almost same as STM32F103.
    The only difference is the D+ pull-up resistor: STM32L has on-chip pull-up.
    But this pull-up isn't compliant to the USB spec, as this errata tells, on all revision.

    STM32L15xx errata sheet
    www.st.com/.../CD00278726.pdf
    2.5.1 Pull-up resistor has a value lower than 1.5kOhm
    Description: The pull-up resistor on USB line is requested to have a nominal value of 1.5kOhm, whereas the characterization of the internal pull-up shows a value between 0.81 and 0.95 kOhm o the full temperature range.
    Workaround: An external pull-up resistor controlled by a GPIO can be used.

    After all, STM32L requires an external pull-up resistor. In this configuration, there is no difference from STM32F103.

    Therefore, you may start with usbd_STM32F103.c for STM32F103

    Tsuneo

  • Auu, copy-paste mistake..
    > Therefore, you may start with usbd_STM32F103.c for STM32F103

    Therefore, you may start with usbd_STM32F103.c for STM32L

    Tsuneo

  • Hi to all and thanx to Tsuneo, as usual.

    This is an obvious starting point. So - of course - I inspected the usbd_STM32F103.c source.
    Unfortunately there seem to be so many major differences between F and L line.
    If only looking at the ST usb core, there are about 70 "#ifdef STM32F10X_CL"
    statements distinguishing between the chips.

    Although I feel quite safe and experienced at the "Report-Level" I am certainly not the driver god to code such a thing in a wink.

    I am not satisfied with the support that Keil gives in this particular area.
    Long time ago (16 Nov 2010) they claimed to support this ST-line
    (see http://www.keil.com/pr/article/1225.htm)
    but as of today, there is still no more than just a blinky sample and no USB at all.

    best regards
    Uli

  • I am also looking at the ST32L for a project and really need to use the USB port.

    There seems to be plenty of support for the 'F' series with examples etc but hardly anything for the 'L' series.

    I think that it should not be too much work for Keil to port the F driver over to the 'L' devices.

    Trev

  • Hi, here is a port of KEIL RL-USB HID to STM32L-DISCOVERY board.

    homepage2.nifty.com/.../STM32L_DISC_KEIL_RL_HID.zip

    A couple of notes of porting,

    A) Hardware - USB connector
    STM32L-DISCOVERY doesn't have USB receptacle. A USB B type receptacle is connected as follows. Also, an external 1k5 D+ pull-up resistor is placed across PC12 and D+. As mentioned on above post, the on-chip pull-up is not recommended.

     STM32L               USB
    DISCOVERY          receptacle
    
     PA11 --------------- D-
    
     PA12 -----------+--- D+
                     |
     PC12 --- 1k5 ---+
    
     GND  --------------- GND
    

    B) Hardware - Crystal
    STM32L-DISCOVERY board has pads for a crystal, but not populated.
    These components are added.
    - X3: 8 MHz crystal
    - C21, C22: 22pF
    - R30: 220 Ohm

    The external crystal is required, because the tolerance of HSI OSC (+/-1%) is not enough for USB operation.

    C) Firmware - porting steps
    1) Start on MCBSTM32 RL-USB HID example C:\Keil\ARM\Boards\Keil\MCBSTM32\RL\USB\Device\HID

    2) Replace "startup" and "system" file with those of STM32L, on Blinky example.
    (C:\Keil\ARM\Boards\ST\STM32L-Discovery\Blinky)
    - startup_stm32f10x_md.s --> startup_stm32l1xx_md.s
    - system_stm32f10x.c --> system_stm32l1xx.c

    Fortunately, Blinky "system" file has been already tuned for USB operation (8MHz crystal - HSE OSC and 96MHz PLL), without any change.

    3) Modify usbd_STM32F103.c for STM32L differences.
    USB Interrupt
    - USBD_IntrEna() Replace USB_LP_CAN1_RX0_IRQn with USB_LP_IRQn
    - USB_LP_CAN1_RX0_IRQHandler() Rename this function name with USB_LP_IRQHandler()

    USB Connection port (PC12)
    - USBD_Init() Enable GPIO C
    - USBD_Connect() Switch PC12 between floating input and push-pull output, to emulate high-side open-drain switch.

    4) Change port assignment of LEDs and a switch on usbd_user_hid.c
    - usbd_hid_init()
    - usbd_hid_get_report()
    - usbd_hid_set_report()

    5) Replace #include of stm32f10x.h with stm32l1xx.h on USBD_Demo.c, usbd_user_hid.c and usbd_STM32F103.c

    6) Delete LCD support
    - LCD_4bit.c
    - USBD_Demo.c, main()

    7) On uVision, Project menu > Options dialog
    - Device tab: select STM32L152RB
    - C/C++ tab: enter STM32L1XX_MD on Define box
    - Debug tab: Use "ST-Link debugger", Setting > Port: JTAG -> SW
    - Utilities tab: Use "ST-Link debugger", Setting > Programming algorithm: STM32L15x Low Power Flash

    I believe I've listed up all of changes, but to make it sure, compare the source files with a "diff" utility ;-)

    Enjoy!

    Tsuneo

  • Tsuneo,

    for now many thanks. Your assistance is really invaluable. I will check the project shortly and return here with results.

    Uli

  • Has anyone already done it or have any guidence on what I may have to do to take the stm32F2xx HS USB port driver and remove the external Phy from it

    Curerntly I am using the ST code and ETFS and thopuhgj I have no problems at the moment with it I would prefer eventually move to just one FS.

    thanks in advance

  • Thanks Tsuneo!

    I'm totally a newbie with microcontroller and currently trying to play with the USB function on STM32L-Discovery. I got stuck on how to port the STM USB library to the discovery board for a couple days and found your post a very helpful guide!

    I wonder if you used the licensed version of Keil toolchain? I downloaded your code and ran it with Keil, it showed the following error:

     .\Test.axf: Error: L9937E: RL-ARM is not allowed with this license
    

    Thanks a lot!

    Vicki

  • Hello!

    I'm trying to get my STM32L USB device to communicate with PC. Actually i'm stuck at just building the project files for Tsuneo's example HID project and I've come across a problem already.

    .\Flash\HID.axf: Error: L9937E: RL-ARM is not allowed with this license

    I have MDK-ARM Standard license. So, does that mean I can't use USB device if I dont have pro license? I don't use RTX (BTW: it is possible to use USBd without RTOS/RTX, right?)

    Thanks for answers.

    J