Repository navigation
Conversation
|
I have accidentally added an extra commit ( |
Hi @Santynolo |
3885c7e to
7a8db1e
Compare
|
I've updated your branch. Simply do a git fetch. |
|
Thanks. |
|
One issue is to disable some handler managing several U(S)ART. In that case you can't use Arduino part for all impacted one. |
|
That could be possible, but i think it would require a deeper integration into the Serial implementation that i'm not that familiar with, and a way to switch between calling HAL_USART_IRQHandler() or HAL_UART_IRQHandler() |
288ec52 to
0845fd7
Compare
|
Hi @Santynolo Thanks a lot for this first PR, and for the discussion that led to a better understanding of the issue. As discussed in the review, disabling a handler shared by several U(S)ART removes Arduino support for all of them, and the build flags would have to be maintained for each handler. I've opened #3124 which instead lets the sketch register its own handler for one U(S)ART instance ( Since the code you modify was moved ( Thanks for your contribution! |
Allow a sketch to manage the interrupt of one U(S)ART instance, for example a USART in synchronous mode served by HAL_USART_IRQHandler(), while Serial keeps working on the other instances. The core USARTx_IRQHandler() only served the instances initialized by HardwareSerial: for another instance nothing acknowledged the interrupt, which fired again and again. Defining its own handler in the sketch is not possible when Serial is used, as the core handlers are linked. uart_attach_irq_handler(instance, handler) registers a function called by the core interrupt handler of the instance instead of HAL_UART_IRQHandler(); NULL unregisters it. The registration is by instance, so it also works when several U(S)ART share a vector (e.g. USART3_4 on STM32G0), the others are still served by the core. The handlers now all go through uart_irq_dispatch(), which also checks that the instance has a HAL handle (USART1, UART4... did not). Document it in API.md. Fixes stm32duino#2899. Replace stm32duino#2902. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> Assisted-by: GitHub Copilot: Claude Sonnet 5.5
Allow a sketch to manage the interrupt of one U(S)ART instance, for example a USART in synchronous mode served by HAL_USART_IRQHandler(), while Serial keeps working on the other instances. The core USARTx_IRQHandler() only served the instances initialized by HardwareSerial: for another instance nothing acknowledged the interrupt, which fired again and again. Defining its own handler in the sketch is not possible when Serial is used, as the core handlers are linked. uart_attach_irq_handler(instance, handler) registers a function called by the core interrupt handler of the instance instead of HAL_UART_IRQHandler(); NULL unregisters it. The registration is by instance, so it also works when several U(S)ART share a vector (e.g. USART3_4 on STM32G0), the others are still served by the core. The handlers now all go through uart_irq_dispatch(), which also checks that the instance has a HAL handle (USART1, UART4... did not). Document it in API.md. Fixes #2899. Replace #2902. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> Assisted-by: GitHub Copilot: Claude Sonnet 5.5
Summary
This PR implements build flags for disabling
IRQHandlers used in theuart.cfile in theSrcWrapper/src/stm32folder allowing the user to write and use their own implementations of differentUSARTx_IRQHandlerdefinitions while keepingHardwareSerialfunctionality in other USART/UART peripherals.New build flags
I propose implementing the following build flags:
A build flag for each IRQHandler.
Why
This change would allow using custom implementations of for example, the USART2 and USART3 peripherals in synchronous mode (using a clock signal), while leaving the USART1 interface or others as a HardwareSerial port for printing to a serial monitor, or for use by libraries that use the standard Print class for debugging.
Here's an example of a build flag (in platformio) and a standard USART3_IRQHandler user definition (that compiles).


This code compiles (and the

USART3_IRQHandlertriggers correctly) with no errors (that i know of), and allows using USART1 as the Serial port and printing with no issues.This is my first PR, please suggest improvements.
Implementation
I have implemented this by surrounding all of the
IRQHandlers defined inuart.cin#ifndef [FLAG]NOTE that this can break or cause unexpected behaviour if this build flag is defined and the user attempts to use the corresponding
HardwareSerialclass. Trying to use HardwareSerial on the USART2 while the build flagHAL_DISABLE_USART2_IRQHANDLERis defined will cause crashes and other behaviour i'm sure (Have not attempted). So i would suggest warning about this on the Wiki if this PR is merged.Fixes
Fixes #2899