2022-09-14 08:53 PM
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.)
2022-09-14 09:12 PM
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
2022-09-15 06:01 PM
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.
2022-09-15 06:33 PM
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);
}
2022-09-17 06:17 AM
Anyone is managing the community?
2022-09-17 06:19 AM
Thank you very much. Let me take a look.
2022-09-17 07:48 AM
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.
2022-09-17 02:03 PM
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?
2022-09-18 08:42 AM
I saw where the interrupt is enabled.
2022-09-19 08:13 PM
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?