cancel
Showing results for 
Search instead for 
Did you mean: 

interrupt

Crane
Associate III

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.)

9 REPLIES 9

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
Up vote any posts that you find helpful, it shows what's working..
Crane
Associate III

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.

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
Up vote any posts that you find helpful, it shows what's working..
Crane
Associate III

Anyone is managing the community?

Thank you very much. Let me take a look.

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
Up vote any posts that you find helpful, it shows what's working..

I didn't see anywhere the UART interrupt is enabled.

Actually I ported the UART interrupt feature to my STM32 Nucleo board and the interrupt didn't happen. I am using USART2 as it is connected to virtual COM port.

Anything I missed?

I saw where the interrupt is enabled.

Although I didn't see the UART interrupt is set as DMA mode, but the comment in the source code says that, so does the readme.txt. So I am wondering if it would work for MCU to communicate with PC through UART by using this example. After porting to STM32F411RE-Nucleo, I didn't see the transmission and receive completion interrupt happening. What could be the potential reasons that I can look into?