AnsweredAssumed Answered

change baurd rate and restart shell on the fly

Question asked by Hetul Patel on Oct 6, 2015
Latest reply on Oct 11, 2015 by Hui_Ma

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.

Outcomes