Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Creating my own IRQ_Handler

I am looking to write my own IRQ handler for the UART.  I read the post https://devzone.nordicsemi.com/f/nordic-q-a/46822/nvic-table/184731#184731

and  added my own definition of UARTE0_UART0_IRQHandler in main.c  (my version of the NUS example program),  the compiler aborts with a duplicate function definition error. Then I commented-out the call to uart_init() just to prove that nothing will change until I prevent inclusion of the “other” driver.

 I edited sdk_config.h (in my NUS example tree) and disabled the UART0 driver inclusion (NRFX_UARTE_ENABLED, NRFX_UART_ENABLED, UART_ENABLED, UART_EASY_DMA_SUPPORT, UART_LEGACY_SUPPORT, UART0_ENABLED, UART0_CONFIG_USE_EASY_DMA, and APP_UART_ENABLED.)  similar to the

https://devzone.nordicsemi.com/f/nordic-q-a/55810/low-level-uart-using-the-registers

I built it again, and this time the error is more subtle – in nrf_drv_uart.h it complains about the typedef on line 122 (“unknown type name”) 

How do i write my own IRQ handler?

  • Hi,

    If you do not intend to use the legacy UART driver (nrf_drv_uart.h), you should remove the include of the header file from your application. Disabling the configs in your sdk_config.h file may cause compile errors like this if the header is included.

    You could also remove the nrfx_uart.c and nrfx_uarte.c files from your project, although the content of these should not be built with the configs disabled.

    Best regards,
    Jørgen

  • thanks

    it appears that the NUS uses the legacy driver.  I guess i am a little lost on the driver architecture and how the new and legacy interact with dependencies

  • NUS itself (the BLE service) does not use UART at all. The usage of UART is part of the example application, where data from the hardware UART is transmitted over NUS, and received data is also forwarded back to the hardware UART.

    If you remove the calls to app_uart_put() in nus_data_handler() and app_uart_get() inside uart_event_handle(), there should not be any dependencies on the HW UART in the example.

  • i appreciate your help.  and apologize if i'm not understanding.  so if i want to use the HW UART in the NUS example, but i want to write my own IRQ Handler.  I need to remove all references to the HW UART in SDK_CONFIG.h by disabling the UART0 driver inclusion (NRFX_UARTE_ENABLED, NRFX_UART_ENABLED, UART_ENABLED, UART_EASY_DMA_SUPPORT, UART_LEGACY_SUPPORT, UART0_ENABLED, UART0_CONFIG_USE_EASY_DMA, and APP_UART_ENABLED.

    i will also need to remove the #include for nrf_drv_uart.h

    i can then create my own handler named  nrfx_uart_0_irq_handler(void). within this IRQ Handler i need to write all the Event responses for the interrupt? but i will need to use the driver for function calls like rx_byte() and tx_byte()? or do i need to rewrtie the drvier?

  • You either have to rewrite the full driver to implement your own IRQ handler inside the driver, or not use the driver functions at all. If you take over the IRQ handling from the driver, the driver will not be able to function correctly, as the interrupts is what causes state-changes inside the driver.

    It is fully possible to control the UART peripheral from the application using HAL functions, or writing directly to the registers, if you do not want to use the driver functions, or want to write your own IRQ handler.

Related