STM32F4 design

Language & Programming

STM32F4 design

Last month ( CUAV published their newest hardware design as well: I collected some ideas regarding software/hardware projects. This month I would like to focus on designing an own PCB containing a STM32F4.

What I would like to achieve/learn:

USB OTG with STM32F4

A reference implementation can be found in Another open source implementation of the STM32F4 is the Olimex STM32 Development board. The schematics can be found under From there we copy the USB OTG handling:

connecting USB port to STM32F4 pins

The following integrated chips are used for the USB connection:


STM32F4 is able to run NuttX RTOS. In the following video we learn about some USB capabilities of NuttX. CDC/ACM addon for NuttX:

In the PX4 Firmware we find following CDC/ACM settings:


The USB host can see the device as /dev/ttyACM0. On NuttX side, data can be sent/received via /dev/ttyACM0 as well. A short snippet out of PX4:

if (strcmp(_device_name, "/dev/ttyACM0") == OK || strcmp(_device_name, "/dev/ttyACM1") == OK) {
                if (_datarate == 0) {
                        _datarate = 800000;
_uart_fd = mavlink_open_uart(_baudrate, _device_name, _force_flow_control);

UART with STM32/NuttX

If USART3 is available, the correct register gets set to enable it.

uint32_t regval;
regval = getreg32(STM32_RCC_APB1ENR);
  /* USART3 clock enable */

  regval |= RCC_APB1ENR_USART3EN;

In the Kconfig file, we find that the STM32F407 does have USART3:

config STM32_STM32F407
        default n
        select STM32_HAVE_FSMC
        select STM32_HAVE_CCM
        select STM32_HAVE_USART3

The STM32F407 can put USART3 on three different ports. This is reflected in the following NuttX code:


By selecting a specific board, the ports get assigned to their function. For example for the stm32f4discovery board, PB10/11 handle the USART3_TX/RX:

#define GPIO_USART3_TX    GPIO_USART3_TX_1     /* PB10, P1 pin 34 (also MP45DT02 CLK_IN) */
#define GPIO_USART3_RX    GPIO_USART3_RX_1     /* PB11, P1 pin 35 */
#define GPIO_USART3_CTS   GPIO_USART3_CTS_1    /* PB13, P1 pin 37 */
#define GPIO_USART3_RTS   GPIO_USART3_RTS_1    /* PB14, P1 pin 38 */

Following, after building nuttx:

$ st-flash write nuttx.bin 0x8000000
$ screen /dev/ttyACM0 115200 8N1

help usage:  help [-v] [<cmd>]

  [         cd        echo      hexdump   mkrd      pwd       sleep     umount    
  ?         cp        exec      kill      mh        rm        test      unset     
  basename  cmp       exit      ls        mount     rmdir     time      usleep    
  break     dirname   false     mb        mv        set       true      xd        
  cat       dd        help      mkdir     mw        sh        uname     

Builtin Apps:
  ostest  nsh

Leave a Reply

Your email address will not be published. Required fields are marked *