I need to enable UART1 in runtime in order to be able to read some data coming on that device.
In order to be able to use the uart functionality, I need to set CONFIG_SERIAL=y, otherwise I get compilation errors. So I wonder how can I disable all uart devices and then enable them back on runtime.
I read this thread, but when I tried to implement it for both UART0 and UART1, the application hang.
This how I try to do it:
while(NRF_UARTE1_NS->EVENTS_RXTO == 0);
NRF_UARTE1_NS->EVENTS_RXTO = 0;
NRF_UARTE1_NS->TASKS_STOPTX = 1;
while(NRF_UARTE1_NS->EVENTS_TXSTOPPED == 0);
NRF_UARTE1_NS->EVENTS_TXSTOPPED = 0;
NRF_UARTE1_NS->ENABLE = 0;
NRF_UARTE1_NS->PSEL.TXD = 0xFFFFFFFF;
NRF_P0_NS->OUTCLR = (1 << 1);
while(NRF_UARTE0_NS->EVENTS_RXTO == 0);
NRF_UARTE0_NS->EVENTS_RXTO = 0;
NRF_UARTE0_NS->TASKS_STOPTX = 1;
while(NRF_UARTE0_NS->EVENTS_TXSTOPPED == 0);
NRF_UARTE0_NS->EVENTS_TXSTOPPED = 0;
NRF_UARTE0_NS->ENABLE = 0;
NRF_UARTE0_NS->PSEL.TXD = 0xFFFFFFFF;
NRF_P0_NS->OUTCLR = (1 << 29);
NRF_UARTE1_NS->ENABLE = 8;
NRF_UARTE1_NS->TASKS_STARTRX = 1;
NRF_UARTE1_NS->TASKS_STARTTX = 1;
NRF_UARTE0_NS->ENABLE = 8;
NRF_UARTE0_NS->TASKS_STARTRX = 1;
NRF_UARTE0_NS->TASKS_STARTTX = 1;
You could try this and see if this helps:
Thank you very much for your response.
I also tried this solution, but I think that CONFIG_PRINTK=n, simply ignores printk in the code and CONFIG_BOOT_BANNER=n suppresses the print of the boot message of the device in the beginning, but I am not convinced that your answer actually disables and then enables the UART devices. At least in the case of UART0, using that logic, I never see anything printed out.But the way I want it to work is the following:Disable both UART0 and 1 in the beginning of the program, then enable UART0 and 1, get my data from the sensor, print them using printk and then disable them again.