Autobaudrate detection by default -- to reduce problems with speed change (#1215)
* Auto autobaud detection by default * Added stopping the autobaud if explicitly configured * Add note about auto-baud to the uart.md
This commit is contained in:
parent
f428897810
commit
5b4b1e0388
|
@ -96,6 +96,9 @@ editing `BIT_RATE_DEFAULT` in `app/include/user_config.h`:
|
||||||
#define BIT_RATE_DEFAULT BIT_RATE_115200
|
#define BIT_RATE_DEFAULT BIT_RATE_115200
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note that, by default, the firmware runs an auto-baudrate detection algorithm so that typing a few characters at boot time will cause
|
||||||
|
the firmware to lock onto that baud rate (between 1200 and 230400).
|
||||||
|
|
||||||
### Debugging
|
### Debugging
|
||||||
|
|
||||||
To enable runtime debug messages to serial console edit `app/include/user_config.h`
|
To enable runtime debug messages to serial console edit `app/include/user_config.h`
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "task/task.h"
|
#include "task/task.h"
|
||||||
#include "user_config.h"
|
#include "user_config.h"
|
||||||
#include "user_interface.h"
|
#include "user_interface.h"
|
||||||
|
#include "osapi.h"
|
||||||
|
|
||||||
#define UART0 0
|
#define UART0 0
|
||||||
#define UART1 1
|
#define UART1 1
|
||||||
|
@ -33,6 +34,8 @@ static task_handle_t sig = 0;
|
||||||
// UartDev is defined and initialized in rom code.
|
// UartDev is defined and initialized in rom code.
|
||||||
extern UartDevice UartDev;
|
extern UartDevice UartDev;
|
||||||
|
|
||||||
|
static os_timer_t autobaud_timer;
|
||||||
|
|
||||||
LOCAL void ICACHE_RAM_ATTR
|
LOCAL void ICACHE_RAM_ATTR
|
||||||
uart0_rx_intr_handler(void *para);
|
uart0_rx_intr_handler(void *para);
|
||||||
|
|
||||||
|
@ -271,6 +274,36 @@ uart0_rx_intr_handler(void *para)
|
||||||
task_post_low (sig, false);
|
task_post_low (sig, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
uart_autobaud_timeout(void *timer_arg)
|
||||||
|
{
|
||||||
|
uint32_t uart_no = (uint32_t) timer_arg;
|
||||||
|
uint32_t divisor = uart_baudrate_detect(uart_no, 1);
|
||||||
|
static int called_count = 0;
|
||||||
|
|
||||||
|
// Shut off after two minutes to stop wasting CPU cycles if insufficient input received
|
||||||
|
if (called_count++ > 10 * 60 * 2 || divisor) {
|
||||||
|
os_timer_disarm(&autobaud_timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (divisor) {
|
||||||
|
uart_div_modify(uart_no, divisor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
uart_init_autobaud(uint32_t uart_no)
|
||||||
|
{
|
||||||
|
os_timer_setfn(&autobaud_timer, uart_autobaud_timeout, (void *) uart_no);
|
||||||
|
os_timer_arm(&autobaud_timer, 100, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
uart_stop_autobaud()
|
||||||
|
{
|
||||||
|
os_timer_disarm(&autobaud_timer);
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* FunctionName : uart_init
|
* FunctionName : uart_init
|
||||||
* Description : user interface for init uart
|
* Description : user interface for init uart
|
||||||
|
@ -291,11 +324,17 @@ uart_init(UartBautRate uart0_br, UartBautRate uart1_br, os_signal_t sig_input)
|
||||||
UartDev.baut_rate = uart1_br;
|
UartDev.baut_rate = uart1_br;
|
||||||
uart_config(UART1);
|
uart_config(UART1);
|
||||||
ETS_UART_INTR_ENABLE();
|
ETS_UART_INTR_ENABLE();
|
||||||
|
#ifdef BIT_RATE_AUTOBAUD
|
||||||
|
uart_init_autobaud(0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ICACHE_FLASH_ATTR
|
void ICACHE_FLASH_ATTR
|
||||||
uart_setup(uint8 uart_no)
|
uart_setup(uint8 uart_no)
|
||||||
{
|
{
|
||||||
|
#ifdef BIT_RATE_AUTOBAUD
|
||||||
|
uart_stop_autobaud();
|
||||||
|
#endif
|
||||||
ETS_UART_INTR_DISABLE();
|
ETS_UART_INTR_DISABLE();
|
||||||
uart_config(uart_no);
|
uart_config(uart_no);
|
||||||
ETS_UART_INTR_ENABLE();
|
ETS_UART_INTR_ENABLE();
|
||||||
|
|
|
@ -34,10 +34,12 @@ extern void luaL_assertfail(const char *file, int line, const char *message);
|
||||||
#ifdef DEVELOP_VERSION
|
#ifdef DEVELOP_VERSION
|
||||||
#define NODE_DEBUG
|
#define NODE_DEBUG
|
||||||
#define COAP_DEBUG
|
#define COAP_DEBUG
|
||||||
#else
|
|
||||||
#define BIT_RATE_DEFAULT BIT_RATE_115200
|
|
||||||
#endif /* DEVELOP_VERSION */
|
#endif /* DEVELOP_VERSION */
|
||||||
|
|
||||||
|
#define BIT_RATE_DEFAULT BIT_RATE_115200
|
||||||
|
|
||||||
|
// This enables automatic baud rate detection at startup
|
||||||
|
#define BIT_RATE_AUTOBAUD
|
||||||
|
|
||||||
#define NODE_ERROR
|
#define NODE_ERROR
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
The [UART](https://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter) (Universal asynchronous receiver/transmitter) module allows configuration of and communication over the UART serial port.
|
The [UART](https://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter) (Universal asynchronous receiver/transmitter) module allows configuration of and communication over the UART serial port.
|
||||||
|
|
||||||
|
The default setup for the uart is controlled by build-time settings. The default rate is 115,200 bps. In addition, auto-baudrate detection is enabled for the first two minutes
|
||||||
|
after platform boot. This will cause a switch to the correct baud rate once a few characters are received. Auto-baudrate detection is disabled when `uart.setup` is called.
|
||||||
## uart.alt()
|
## uart.alt()
|
||||||
Change UART pin assignment.
|
Change UART pin assignment.
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ int atoi(const char *nptr);
|
||||||
int os_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
|
int os_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
|
||||||
int os_printf_plus(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
|
int os_printf_plus(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
|
||||||
|
|
||||||
|
unsigned int uart_baudrate_detect(unsigned int uart_no, unsigned int async);
|
||||||
|
|
||||||
void NmiTimSetFunc(void (*func)(void));
|
void NmiTimSetFunc(void (*func)(void));
|
||||||
|
|
||||||
#include_next "osapi.h"
|
#include_next "osapi.h"
|
||||||
|
|
Loading…
Reference in New Issue