Page 1 of 1

Compilation error when activating the same peripheral for Serial and UART drivers

Posted: Mon Jul 21, 2025 6:28 pm
by ych
What is the reason for the compilation error when activating the same peripheral for both Serial and UART drivers?

I'm referring to this message:

Code: Select all

  
#error "SD1 requires USART1 but it is already used" 

...and similar checks involving [font=Courier New]STM32_USART*_IS_USED[/font].

Is this just a safeguard to prevent accidentally enabling the same peripheral for different drivers — which could result in unexpected memory usage or calling functions from different drivers on the same hardware peripheral? Or is there a deeper, low-level hardware limitation that prevents such usage?

In my case, the device can be connected to different external modules via a serial interface, each using a completely different protocol. Some of these protocols are best implemented using the Serial Driver (variable-length packets), while others are more efficient and better suited for the UART Driver (fixed-length packets).

I want to support both drivers, but only one will be used at a time depending on the connected device. The configuration is stored in EEPROM and applied after reboot. I can guarantee that functions from different drivers will not be called simultaneously on the same peripheral. The additional memory used by having both driver structures is acceptable in my case.

I can manually patch the HAL checks, but I want to be sure this won’t cause any unintended side effects when using these drivers in such way.

Re: Compilation error when activating the same peripheral for Serial and UART drivers

Posted: Mon Jul 21, 2025 7:35 pm
by Giovanni
Hi,

Assigning the same peripheral to different drivers is not supported.

It is a safeguard to prevent a more mysterious linker error. The 2 drivers would define the same ISR and there would be a symbol collision.

Giovanni