This may be a fool's errand, but I'd like to create a custom serial driver (more on that in a moment) and I'd prefer not to monkey patch any of the ASF4 / START source files. However, run-time modification is permissible.
My application requires byte-at-a-time asynch processing, so I need to install custom interrupt handlers on SERCOM3 (for a SAMD21). But I haven't found a way to get control of the interrupt handlers without patching the START-generated source files, which I want to avoid. Things that DON'T work:
- If I include the HAL:Driver:USART_Async driver, it installs SERCOM3_Handler in the exception_table and gives me useful hal and hpl files to work with. But I can't define my own SERCOM3_Handler because that results in multiple definition of `SERCOM3_Handler`. And calling exception_table.pfnSERCOM3_Handler = (void *)MyHandler; results in an error (as expected) because exception_table is declared `const`.
- If I don't include a USART module at all in START, none of the hal and hpl files get added to the project. I don't mind copying and pasting SOME code, but manually installing all the required files defeats the purpose of working with START rather than fighting it.
- If I include the HAL:Driver:USART_Sync driver, I get *most* of the hal and hpl files, but again, I cannot install an interrupt handler in the exception_table because it's read-only.
(Nerdy details for those who have looked at the code: It *almost* works to replace the tx_byte_sent, tx_done_cb, rx_done_cb and error_cb callback functions in hpl_sercom.c, except for one thing: the top-level interrupt function _sercom_usart_interrupt_handler() reads the USART data register, which has the effect of clearing the RXC bit. I need to RXC to stay set.)
One way to accomplish what I need is to install my own callbacks at runtime. The rx_done_cb could cache the RX data and the RXC bit to work around the fact that _sercom_usart_interrupt_handler() has already read the data register and cleared the RXC bit.
But what approaches have others taken when tackling this sort of problem?