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

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
ych
Posts: 45
Joined: Tue Mar 03, 2015 11:38 pm
Has thanked: 17 times
Been thanked: 11 times

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

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

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

Post 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
Post Reply