change baurd rate and restart shell on the fly

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

change baurd rate and restart shell on the fly

634 Views
hetul
Contributor I

Hello,

 

I have a project that requires changing of baud rate on serial port from 115200 to 9600 with Command List being different for two.  We have a diagnostic mode that runs shell at 115200 with debug commands and disabling diagnostic mode(from HMI task) aborts shell task and starts it again with baud rate set to 9600 and selects rs232 commands list.

 

I am running into a trouble as to how can i change the baud rate and restart shell task without impacting nio_serial drivers from stop working.  Currently I abort the shell_task and start it again with a parameter indicating switch from 115200 to 9600, and shell task function does this:

_int_disable();

    UART_HAL_DisableTransmitter(base);

    UART_HAL_DisableReceiver(base);

    UART_HAL_SetBaudRate(base, uartSourceClock, param?9600:115200);

    UART_HAL_SetTxFifoCmd(base, true);

    UART_HAL_SetRxFifoCmd(base, true);

    UART_HAL_FlushTxFifo(base);

    UART_HAL_FlushRxFifo(base);

    _int_enable();

    UART_HAL_EnableTransmitter(base);

    UART_HAL_EnableReceiver(base);

 

And then calls Shell() function with corresponding Command List.  But the Shell() function returns because fgets function inside returns < 0 value.  I have tried changing baud rate without disabling interrupts or transmitter or receiver but none of the patter has yielded working result.  If  someone has any experience where baud rate is changed on the fly please share with me.  I appreciate all the inputs on how i could implement such feature. Thank you very much.

Labels (1)
0 Kudos
1 Reply

389 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

Have you tried to call the UART high level driver:

UART_DRV_Deinit(); & UART_DRV_Init();

Wish it helps.


Have a great day,
Ma Hui

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos