Skip to content

Stm32 usb project creation

Wayne Roberts edited this page Dec 9, 2013 · 11 revisions

Guideline for using example projects in STM32_USB-FS-Device_Lib_V4.0.0/

be sure to first have read STM32 tools

using example VirtualComport_Loopback:

  • from directory STM32_USB-FS-Device_Lib_V4.0.0/Projects/VirtualComport_Loopback/

    • copy appropriate source & header files from inc/ and src/ into your own project directory.
  • from STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32L1xx_StdPeriph_Driver

    • cp -r src/ directory into your project directory with name such as StdPeriph_src
  • from STM32_USB-FS-Device_Lib_V4.0.0/Libraries/CMSIS/Device/ST/STM32L1xx/Source/Templates/TrueSTUDIO copy startup_stm32l1xx_?.s depending on flash size (family) of device rename to .S

  • from STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32_USB-FS-Device_Driver/src/: usb_mem.c usb_regs.c usb_init.c usb_core.c usb_sil.c

  • linker script:

    copy the .ld file from a STM32*-EVAL/ directory best matching your target device.

include paths:

<parentdir>/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32_USB-FS-Device_Driver/inc/
..
<parentdir>/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/CMSIS/Device/ST/STM32L1xx/Include/
<parentdir>/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/CMSIS/Include/
<parentdir>/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32L1xx_StdPeriph_Driver/inc/

The .. directory references your project directory in workspace.

preprocessor defines (for STM32L1xx):

STM32L1XX_MD_PLUS           // for stm32l152rct6
    or
STM32L1XX_MD                // for stm32l152vbt6

USE_STDPERIPH_DRIVER

board support

  • In platform_config.h:

    comment out #define (USE_STM32303C_EVAL) if thats not your board

    In the includes section, create a USE_ ifdef for your board in the appropriate processor family section.

    depending on whether your board uses DP+ pullup internally or externally, you need to make sure the appropriate preprocessor directives are set for USB_CONNECT/DISCONNECT defines.

crystal frequency

ensure HSE_VALUE matches your crystal, default is 8MHz