Search code examples
cembeddedstm32uart

UART5 on stm32F429-DISCOVERY - not initialized


I ran into some issues configuring my stm32f429-DISCO board for a UART transmission on UART5. I used the example project provided by st. To be exact, the UART/UART_TwoBoards_ComDMA in version 1.7.0. In this example the USART1 is used to circle one data package around. When the DISCO-board is programmed with the original code, I can see the USART1 output message on my oscilloscope.

On the other hand, when I try the same thing with the UART5, because the pins for USART1 will be blocked in my final configuration it won't work.

I narrowed the problem down to the initialization process.

HAL_UART_MspInit(huart);

This function is not setting the TC and RXNE bit in UART1->SR, and therefore the UART5 is not configured. I know for UART1 you need to enable the clock, because it can be a synchronous transmission.

__HAL_RCC_USART1_CLK_ENABLE();

I can't seem to find a similar function for UART5. Has somebody an idea or a hint for me?

In case a bigger problem is underlying this issue, here are the changed settings for the UART5 configuration of the example.

/* Definition for USARTx clock resources */
#define USARTx                           UART5
//#define USARTx_CLK_ENABLE()            __HAL_RCC_USART1_CLK_ENABLE();
#define DMAx_CLK_ENABLE()                __HAL_RCC_DMA1_CLK_ENABLE()
#define USARTx_RX_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOD_CLK_ENABLE()
#define USARTx_TX_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOC_CLK_ENABLE() 

//#define USARTx_FORCE_RESET()           __HAL_RCC_USART1_FORCE_RESET()
//#define USARTx_RELEASE_RESET()         __HAL_RCC_USART1_RELEASE_RESET()

/* Definition for USARTx Pins */
#define USARTx_TX_PIN                    GPIO_PIN_12
#define USARTx_TX_GPIO_PORT              GPIOC
#define USARTx_TX_AF                     GPIO_AF8_UART5
#define USARTx_RX_PIN                    GPIO_PIN_2
#define USARTx_RX_GPIO_PORT              GPIOD
#define USARTx_RX_AF                     GPIO_AF8_UART5

/* Definition for USARTx's DMA */
#define USARTx_TX_DMA_CHANNEL            DMA_CHANNEL_4
#define USARTx_TX_DMA_STREAM             DMA1_Stream7
#define USARTx_RX_DMA_CHANNEL            DMA_CHANNEL_4
#define USARTx_RX_DMA_STREAM             DMA1_Stream0

/* Definition for USARTx's NVIC */
#define USARTx_DMA_TX_IRQn               DMA1_Stream7_IRQn
#define USARTx_DMA_RX_IRQn               DMA1_Stream0_IRQn
#define USARTx_DMA_TX_IRQHandler         DMA1_Stream7_IRQHandler
#define USARTx_DMA_RX_IRQHandler         DMA1_Stream0_IRQHandler
#define USARTx_IRQn                      UART5_IRQn
#define USARTx_IRQHandler                UART5_IRQHandler

I'm happy for any suggestion and help that guides me in the right direction.

Thank you for your time,

eimer


Solution

  • UART5 has no S, so the function to enable the clock is called __HAL_RCC_UART5_CLK_ENABLE();, like e.g. there: Receiving data from 2 UARTs, STM32F4-Discovery, HAL drivers