Skip to main content
Crane
Associate II
Sep 15, 2022 3:53 AM UTC
Question

interrupt

I am working on STM32 NUCLEO - F411RE and want to use the interrupt. If not using STM32CubeMX to generate IOC and code, is there any example which uses UART interrupt? ( I have problem using MX to generate code right now.)

This topic has been closed for replies.

9 replies

Tesla DeLorean
Guru
Sep 15, 2022 4:12 AM UTC

Should port

STM32Cube_FW_F4_V1.24.2\Projects\STM32F411E-Discovery\Examples\UART\UART_TwoBoards_ComIT

Should have board specific configuration

STM32Cube_FW_F4_V1.24.2\Projects\STM32F411RE-Nucleo\Examples\UART\UART_Printf

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Crane
CraneAuthor
Associate II
Sep 16, 2022 1:01 AM UTC

Thanks Tesla for your reply.

I didn't see the interrupt service routine registration in the example for STM32F411E-Discovery. Are you sure it uses interrupt mode to receive UART information?

The example for STM32F411RE-Nucleo doesn't use interrupt and it doesn't have the configuration for UART interrupt.

Tesla DeLorean
Guru
Sep 16, 2022 1:33 AM UTC

The first has an IRQ Handler, and the second initializes the UART, its clocks, and pins, for your board.

STM32Cube_FW_F4_V1.24.2\Projects\STM32F411E-Discovery\Examples\UART\UART_TwoBoards_ComIT\Src\stm32f4xx_it.c

void USARTx_IRQHandler(void)
{
 HAL_UART_IRQHandler(& UartHandle);
}

STM32Cube_FW_F4_V1.24.2\Projects\STM32F411E-Discovery\Examples\UART\UART_TwoBoards_ComIT\Inc\main.h

/* User can use this section to tailor USARTx/UARTx instance used and associated
 resources */
/* Definition for USARTx clock resources */
#define USARTx USART2
#define USARTx_CLK_ENABLE() __HAL_RCC_USART2_CLK_ENABLE();
#define USARTx_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define USARTx_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
 
#define USARTx_FORCE_RESET() __HAL_RCC_USART2_FORCE_RESET()
#define USARTx_RELEASE_RESET() __HAL_RCC_USART2_RELEASE_RESET()
 
/* Definition for USARTx Pins */
#define USARTx_TX_PIN GPIO_PIN_2
#define USARTx_TX_GPIO_PORT GPIOA
#define USARTx_TX_AF GPIO_AF7_USART2
#define USARTx_RX_PIN GPIO_PIN_3
#define USARTx_RX_GPIO_PORT GPIOA
#define USARTx_RX_AF GPIO_AF7_USART2
 
/* Definition for USARTx's NVIC */
#define USARTx_IRQn USART2_IRQn
#define USARTx_IRQHandler USART2_IRQHandler

STM32Cube_FW_F4_V1.24.2\Projects\STM32F411E-Discovery\Examples\UART\UART_TwoBoards_ComIT\Src\main.c

/**
 * @brief Tx Transfer completed callback
 * @param UartHandle: UART handle.
 * @note This example shows a simple way to report end of IT Tx transfer, and
 * you can add your own implementation.
 * @retval None
 */
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *UartHandle)
{
 /* Set transmission flag: transfer complete*/
 UartReady = SET;
 
 /* Turn LED6 on: Transfer in transmission process is correct */
 BSP_LED_On(LED6);
}
 
/**
 * @brief Rx Transfer completed callback
 * @param UartHandle: UART handle
 * @note This example shows a simple way to report end of IT Rx transfer, and
 * you can add your own implementation.
 * @retval None
 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
 /* Set transmission flag: transfer complete*/
 UartReady = SET;
 
 /* Turn LED4 on: Transfer in reception process is correct */
 BSP_LED_On(LED4);
}
 
/**
 * @brief UART error callbacks
 * @param UartHandle: UART handle
 * @note This example shows a simple way to report transfer error, and you can
 * add your own implementation.
 * @retval None
 */
 void HAL_UART_ErrorCallback(UART_HandleTypeDef *UartHandle)
{
 /* Turn LED3 on: Transfer error in reception/transmission process */
 BSP_LED_On(LED3);
}

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Crane
CraneAuthor
Associate II
Sep 17, 2022 1:19 PM UTC

Thank you very much. Let me take a look.

Crane
CraneAuthor
Associate II
Sep 17, 2022 1:17 PM UTC

Anyone is managing the community?

Tesla DeLorean
Guru
Sep 17, 2022 2:48 PM UTC

Their primary guy left, not sure if there is an official replacement, and the rest of us are uncompensated, and have no moderation control. Best we can do is flag posts, and hopefully someone will check the In-Box occasionally.

@Laura C.​ can you look into the RGome.7 spam, this is her material copied from other forums, out of context, likely for the purpose of editing/modifying with link spam later.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..