cancel
Showing results for 
Search instead for 
Did you mean: 

Mixing Polling Mode Modules with UART Interrupt Mode on STM32: Is It Safe?

durna
Associate III

I'm developing a project using an STM32 Nucleo board. At the core of this project is a UART-based communication protocol running in interrupt (IT) mode — not polling or DMA. This protocol is responsible for controlling multiple subsystems such as a relay module and a fan speed controller.

However, most of these subsystem modules were previously written in polling mode.

My question is:
Can I integrate these polling-based modules into my current UART IT-mode communication system without causing issues? Or should I consider converting them to interrupt or DMA mode to prevent CPU blocking or communication delays?

Additionally:
What should I watch out for to ensure the CPU doesn't get blocked and UART interrupts don't get delayed in this mixed-mode setup?

Extra context:
There are 20 NTC temperature sensors in the system, and temperature from all of them is read once every second using ADC. The highest temperature value is selected and stored in a variable. Based on this value, the fan speed is adjusted accordingly.

Note: The polling-based modules do not contain any infinite loops like while(1) or other blocking code. For example, the ntc reader and fan control logic looks like:

 

 

NTC_Read_Temperatures(temps);
HAL_Delay(1000);


if(max_temp == 54.23f ){
speed_of_fan = mode_2;
hal_delay(1);
}

3 REPLIES 3
mbarg.1
Senior III

At first look, I would suggest move UART to DMA and keep all program as it is.

Polling DMA result at intervals, allow to detect what happened on UART without disturbing other functions.

Remember that DMA must be stopped on error or timeout.

mike

Thank you. Yes, moving the communication module to DMA would at least ensure its functionality. But what would happen if I left it in IT mode as it is now? What potential dangers would there be in this case?

If you are playing only TX, no problems, but with RX you will need to manage rx buffer before oveflowing - you already bought a device with DMA, use it,it is free, and you will be much more reliable.