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

Parents Reply
  • 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

Children
More questions in this forum