How to use UART0 temporarily for other purposes than logging and printf output
Posted: Thu Oct 04, 2018 8:39 am
Hi,
I am currently using an ESP32 WROVER module on a board we are developing. The hardware setup on the board is such that I can only connect to UART0. I use that port for the usual purposes of flashing the WROVER module and observing the logging output from it.
However, I would like to temporarily use that port as well for unit testing etc... so I have a few questions about this:
From information I found provided by kolban I know it is possible to redirect the log output etc... by selecting the UART you want by running make MENUCONFIG but that is not what I am looking for as I would usually want to retain the log output etc... on UART0. It would be only under certain conditions that I would want to use UART0 for other purposes. So I would need to do that "on the fly" when the application is running.
I have thought of a simple solution: replace all ESP_LOGx and printf function calls by calls to other functions I could make and in those send the specified output to UART0 conditionally.
Currently UART0 is only used to transmit logging data etc... I assume though it is also capable of receiving data which is simply not used for now. If that is the case sending something specific to the ESP32 module via UART0 would be the perfect trigger to activate the alternative operating mode. Does anyone know whether reception of data is possible ?
Another assumption I am not 100% sure of is that the current UART output is driver based and if I stop the usual output I could use the uart_write_bytes and uart_read_bytes functions to send and receive bytes when working in my alternative mode, can anyone confirm whether or not that is the case?
Edit: well, this proves to be a bad assumption as I have tried to do this:
That tells me that although the UART works well enough to run the printf function I get the "uart_get_buffered_data_len returned an error" message so presumably the UART operation is not uart driver based.
Any tips/suggestions would be much appreciated.
I am currently using an ESP32 WROVER module on a board we are developing. The hardware setup on the board is such that I can only connect to UART0. I use that port for the usual purposes of flashing the WROVER module and observing the logging output from it.
However, I would like to temporarily use that port as well for unit testing etc... so I have a few questions about this:
From information I found provided by kolban I know it is possible to redirect the log output etc... by selecting the UART you want by running make MENUCONFIG but that is not what I am looking for as I would usually want to retain the log output etc... on UART0. It would be only under certain conditions that I would want to use UART0 for other purposes. So I would need to do that "on the fly" when the application is running.
I have thought of a simple solution: replace all ESP_LOGx and printf function calls by calls to other functions I could make and in those send the specified output to UART0 conditionally.
Currently UART0 is only used to transmit logging data etc... I assume though it is also capable of receiving data which is simply not used for now. If that is the case sending something specific to the ESP32 module via UART0 would be the perfect trigger to activate the alternative operating mode. Does anyone know whether reception of data is possible ?
Another assumption I am not 100% sure of is that the current UART output is driver based and if I stop the usual output I could use the uart_write_bytes and uart_read_bytes functions to send and receive bytes when working in my alternative mode, can anyone confirm whether or not that is the case?
Edit: well, this proves to be a bad assumption as I have tried to do this:
Code: Select all
char *TestModeCommand = "TestMode";
void Rxtx_CheckforTestModeCommand ( void )
{
esp_err_t espError = ESP_OK;
int32_t i, testModeRxDelayTicks = TEST_MODE_CMD_RX_DELAY * 10;
size_t receivedBytes;
for ( i = 0 ; (i < testModeRxDelayTicks) && ( espError == ESP_OK ); i++ )
{
espError = uart_get_buffered_data_len ( UART_NUM_0, &receivedBytes );
}
if ( espError != ESP_OK)
{
printf ( "uart_get_buffered_data_len returned an error");
}
else
{
printf ( "uart_get_buffered_data_len returned %d bytes received", receivedBytes);
}
}
Any tips/suggestions would be much appreciated.