STM32F4 design

Language & Programming

STM32F4 design

Last month (https://dayjaby.wordpress.com/2020/03/02/february-2020-collecting-ideas/). CUAV published their newest hardware design as well: https://github.com/cuav/hardware/blob/master/X7_Autopilot/Nora_AP/Nora_AP.pdf 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 https://www.st.com/resource/en/user_manual/dm00022972-stm3220g-eval-evaluation-board-stmicroelectronics.pdf. Another open source implementation of the STM32F4 is the Olimex STM32 Development board. The schematics can be found under https://github.com/OLIMEX/STM32F4/blob/master/HARDWARE/STM32-E407/STM32-E407_Rev_F.pdf. From there we copy the USB OTG handling:

connecting USB port to STM32F4 pins

The following integrated chips are used for the USB connection:

NuttX RTOS

STM32F4 is able to run NuttX RTOS. In the following video we learn about some USB capabilities of NuttX. https://www.youtube.com/watch?v=rgZJPZh_po8. CDC/ACM addon for NuttX: https://github.com/jodersky/nuttx/tree/master/apps/system/cdcacm

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

CONFIG_CDCACM=y
CONFIG_CDCACM_PRODUCTID=0x0032
CONFIG_CDCACM_PRODUCTSTR="PX4 FMU v5.x"
CONFIG_CDCACM_RXBUFSIZE=600
CONFIG_CDCACM_TXBUFSIZE=12000
CONFIG_CDCACM_VENDORID=0x26ac
CONFIG_CDCACM_VENDORSTR="3D Robotics"

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);
#ifdef CONFIG_STM32_USART3
  /* USART3 clock enable */

  regval |= RCC_APB1ENR_USART3EN;
#endif

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

config STM32_STM32F407
        bool
        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:

#define GPIO_USART3_TX_1      (GPIO_ALT|GPIO_AF7|GPIO_PULLUP|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN10)
#define GPIO_USART3_TX_2      (GPIO_ALT|GPIO_AF7|GPIO_PULLUP|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN10)
#define GPIO_USART3_TX_3      (GPIO_ALT|GPIO_AF7|GPIO_PULLUP|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTD|GPIO_PIN8)

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 https://nathan.vertile.com/blog/2017/12/08/nuttx-getting-started/, after building nuttx:

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

help
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 *