So, The Wemos D1 Mini pro is the board I use to program the NONOS SDK right now currently. The downside is it only exposes one UART interface (UART0) and with that comes some minor issues.
1: If you connect an FTDI chip to this port the TX line from the FTDI is always HIGH and will keep the RX Pin on the ESP8266 HIGH and will stop new firmware from being loaded until you physically disconnect the FTDI chip.
2: The Line is not dedicated so sending Debug in on this line may interfere with other external devices connected to this line.
So the first issue is solved by calling system_uart_swap() thus swapping the RX/TX line with D7 and D8 for the RTS CTS lines freeing the TX/RX labeled pins on the Wemos
The 2nd one can use GPIO2 and use UART1 to transmit the data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
LOCAL void ICACHE_FLASH_ATTR uart_config(uint8 uart_no, void * callback(uint8)) { os_printf("uart_config:%d", uart_no); if (uart_no == UART0) { /* UART0 */ ETS_UART_INTR_ATTACH(uart0_rx_intr_handler, callback); PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U); PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD); //Enable RxD pin PIN_PULLUP_EN(PERIPHS_IO_MUX_U0RXD_U); PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD); //PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_U0RTS); //We don't use RTS } else { PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO2_U); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK); //D4 used for Debug out. PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO2_U); } uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate)); WRITE_PERI_REG(UART_CONF0(uart_no), CALC_UARTMODE(EIGHT_BITS, NONE_BITS, ONE_STOP_BIT)); //clear rx and tx fifo,not ready SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST); CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST); WRITE_PERI_REG(UART_CONF1(uart_no), ((UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S)); //clear all interrupt WRITE_PERI_REG(UART_INT_CLR(uart_no), 0xffff); //enable rx_interrupt SET_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_FULL_INT_ENA); } void ICACHE_FLASH_ATTR uart_init(UartBautRate uart0_br, UartBautRate uart1_br, void * callback) { // rom use 74880 baut_rate, here reinitialize UartDev.baut_rate = uart0_br; uart_config(UART0, callback); UartDev.baut_rate = uart1_br; uart_config(UART1, callback); ETS_UART_INTR_ENABLE(); // install uart1 putc callback //system_uart_swap(); //http://smallbits.marshall-tribe.net/blog/2016/11/13/esp8266-quiet-uart //PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK); //os_install_putc1((void *)uart1_write_char); } void ICACHE_FLASH_ATTR sdk_init_done_cb(void) { os_printf("[%s] initializing ESP8266!\n", __func__); while(true) { os_printf("test"); 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 delay_second(); delay_second(); } } void ICACHE_FLASH_ATTR SetupUART(void) { //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(); //http://smallbits.marshall-tribe.net/blog/2016/11/13/esp8266-quiet-uart - 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() { SetupUART(); system_init_done_cb(sdk_init_done_cb); wifi_set_opmode(0); wifi_set_sleep_type( NONE_SLEEP_T ); ETS_GPIO_INTR_DISABLE();// Disable gpio interrupts gpio_init(); SetAllGPIOPinsAsOutput(); /* 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 //PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); //gpio_output_set((1 << 2), 0, 0, 0); //Start os task system_init_done_cb(sdk_init_done_cb); //system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen); //Task to Signal for later } |