You can chat about native SDK questions and issues here.

User avatar
By hilogic
#81921 How to receive UART0 interrupt bytes in user_main.c. As of now i have to directly modify the uart_recvTask function in uart.c file in the SDK directory. uart.c is a peripheral driver and should not be modified or this is the way it is done in ESP8266 nonos SDK.
User avatar
By Agentsmithers
#81973 Hey Hilogic!
I've reviewed a grip of uart.c and .h files and it appears there are a lot of custom versions out there including my own. I plan to be back in my office later today. I'll post my samples that worked for me currently and in the past as well here later today to see if that'll help ya get going.
User avatar
By Agentsmithers
#89489 Still need it? I can post it if still required, The OP has not come back?

*Update* I posted the rest of my code here in the next post.. Here is a UserLevel of UART

Code: Select all//
#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "ip_addr.h"
#include "mem.h"
#include "user_interface.h"
#include "lwip/stats.h"
#include "espconn.h"

#include "c_types.h" ////ONE WIRE

#include "../library/uart.h" //Copy these from your Driver Lib to your local folder
#include "../library/gpio16.h" //Copy these from your Driver Lib to your local folder

#include "../library/common.h"


#define user_procTaskPrio        0
#define user_procTaskQueueLen    1
os_event_t user_procTaskQueue[user_procTaskQueueLen];

void uart0_tx_buffer(uint8 *buf, uint16 len);

char rxbuff[31];
char rxindex = 0;

void UartReceive(char ByteReceived)
   os_printf("[%s] Got UART Callback!\r\n", __func__);
   os_printf("Byte Recevied: %c\r\n", ByteReceived);

   rxbuff[rxindex++] = ByteReceived;
   if (rxindex == sizeof(rxbuff))
      rxindex = 0;
      os_printf("%d != %d\r\n", rxindex, sizeof(rxbuff));
   os_printf("Buffer: %s\r\n", rxbuff);


void ICACHE_FLASH_ATTR sdk_init_done_cb(void)
   os_printf("[%s] initializing ESP8266!\n", __func__);
      uart0_tx_buffer("page 1\xff\xff\xff", 9); //This is our Prod Port
      uart1_tx_buffer("page 2\xff\xff\xff", 9); //This is our Debug Port

   //Careful when the callback is triggered that it does not kick off any premature events like sending network packets before the network is connected, thus crashing your app
   uart_init(BIT_RATE_115200, BIT_RATE_115200, &UartReceive); //This only seems to be kicked off via the COM-USB onboard, Not the TX/RX port
   system_set_os_print(1); //Turns os_PrintF Log Printing On or Off
   //We use UART swap because the RXpin is always High from external outputs causing issues when loading new firmware.
   //Keep in mind uart swap only swaps the RTS and CTS of the same UART to the RX and TX of the same UART, NOT UART1 to UART0
   //"UART0 swap. Use MTCK as UART0 Rx, MTDO as UART0 Tx, so ROM log will not output from this new UART0. MTDO (U0RTS) and MTCK (U0CTS) also need to be used as UART0 in hardware
   system_uart_swap(); // - Makes D7 RX (MTCK) and D8 TX (MTDO)
   os_install_putc1((void *)uart1_write_char); //Redirect OS_PRINTF to UART1, our debug port

void ICACHE_FLASH_ATTR user_init()


   wifi_set_sleep_type( NONE_SLEEP_T );

   ETS_GPIO_INTR_DISABLE();// Disable gpio interrupts


   /* Need to fix this to display value   */
   uint32 VDDADCByte[4] = {0};
   spi_flash_read(0x3fc06b, (uint32 *)&VDDADCByte, 1); //Read pads the other 3 bytes with FF

   os_printf("\r\n\r\nStarting ESP8266 OTA!\r\nSDK version:%s\r\nLoaded from: %02x\r\nVdd33_Const: %02x\r\n", system_get_sdk_version(), system_get_userbin_addr(), (VDDADCByte[0] & 0xff));

   //Turn off LED, We cannot touch this pin as this is our debug pin D4/GPIO2
   //gpio_output_set((1 << 2), 0, 0, 0);

   //Start os task
   //system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen); //Task to Signal for later
Last edited by Agentsmithers on Tue Nov 17, 2020 8:41 pm, edited 1 time in total.