How to use UART0 temporarily for other purposes than logging and printf output

Zingemneire
Posts: 68
Joined: Tue Apr 17, 2018 7:35 am

How to use UART0 temporarily for other purposes than logging and printf output

Postby Zingemneire » 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:

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);
   }
}
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.

Zingemneire
Posts: 68
Joined: Tue Apr 17, 2018 7:35 am

Re: How to use UART0 temporarily for other purposes than logging and printf output

Postby Zingemneire » Thu Oct 04, 2018 2:24 pm

Hi Again,

As I did not get a reply yet I started doing some testing myself and this is what I found:
  • (1) I got the bit of code above to work by adding a bit of code to perform proper uart_param_config and uart_driver_install for UART_NUM_0.
    (2) If I then call function uart_get_buffered_data_len I do get the proper reply: 0 if I have sent nothing and however many bytes I have sent during the reception window time.
    (3) For testing purposes I decided to try the following instruction to prevent any further logging activity: esp_log_level_set( TAG, ESP_LOG_NONE); but that does not work, presumably because something else somewhere sets it back to a higher level.
    (4) Because item 3 does not work and I keep getting the usual logging info generated by ESP_LOGx and printf functions it does prove that installing or reinstalling the uart does not interfere with the nomal logging activity.
End result: I can happily introduce some code that enables reception of the "TestMode" command at startup and if it does not come run the application as before while retaining full logging and printf functionality. In case the "TestMode" command does arrive I can happily run some code that emulates a command line console and does not perform any logging or printf functionality, thereby reserving use of UART0 for receiving test mode instructions and providing reply data.

Hope somebody finds this useful some day.

wowa86
Posts: 1
Joined: Wed May 22, 2019 8:36 pm

Re: How to use UART0 temporarily for other purposes than logging and printf output

Postby wowa86 » Tue Aug 13, 2019 10:31 am

An alternative would be to disable UART logging within the config and write your own log function with esp_log_set_vprintf.

Who is online

Users browsing this forum: No registered users and 82 guests