O'Reilly logo

Embedded Systems Architecture by Daniele Lacamera

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Programming the controller

Development boards usually provide multiple UARTs, and our reference STM32F407 is not an exception. According to the manual, UART3 can be associated to the pins PD8 (TX) and PD9 (RX), which we will use in this example. This is the code needed to turn on the clock for the GPIO group D, and set the 8 and 9 pins in alternate mode, with an alternate function of 7:

#define AHB1_CLOCK_ER (*(volatile uint32_t *)(0x40023830))#define GPIOD_AHB1_CLOCK_ER (1 << 3)#define GPIOD_BASE 0x40020c00#define GPIOD_MODE (*(volatile uint32_t *)(GPIOD_BASE + 0x00))#define GPIOD_AFL (*(volatile uint32_t *)(GPIOD_BASE + 0x20))#define GPIOD_AFH (*(volatile uint32_t *)(GPIOD_BASE + 0x24))#define GPIO_MODE_AF (2)#define UART3_PIN_AF (7)#define ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required