diff --git a/core/app_main.c b/core/app_main.c index 88ac743..cae881c 100644 --- a/core/app_main.c +++ b/core/app_main.c @@ -16,8 +16,8 @@ #include "common_macros.h" #include "xtensa_ops.h" #include "esp/rom.h" +#include "esp/uart.h" #include "esp/iomux_regs.h" -#include "esp/uart_regs.h" #include "esp/spi_regs.h" #include "esp/dport_regs.h" #include "esp/wdev_regs.h" @@ -30,7 +30,6 @@ void user_init(void); -#define UART_DIVISOR 1068 // 74906 bps (yeah, I don't understand it either) #define BOOT_INFO_SIZE 28 //TODO: phy_info should probably be a struct (no idea about its organization, though) #define PHY_INFO_SIZE 128 @@ -293,8 +292,8 @@ static void init_networking(uint8_t *phy_info, uint8_t *mac_addr) { printf("FATAL: sdk_register_chipv6_phy failed"); halt(); } - sdk_uart_div_modify(0, UART_DIVISOR); - sdk_uart_div_modify(1, UART_DIVISOR); + uart_set_baud(0, 115200); + uart_set_baud(1, 115200); sdk_phy_disable_agc(); sdk_ieee80211_phy_init(sdk_g_ic.s.phy_mode); sdk_lmacInit(); diff --git a/core/include/esp/uart.h b/core/include/esp/uart.h index e2d068b..9d72dc3 100644 --- a/core/include/esp/uart.h +++ b/core/include/esp/uart.h @@ -11,6 +11,7 @@ #include "esp/types.h" #include "esp/uart_regs.h" +#include "esp/clocks.h" #define UART_FIFO_MAX 127 @@ -110,4 +111,17 @@ static inline void uart_flush_rxfifo(int uart_num) { uart_clear_rxfifo(uart_num); } +/* Set uart baud rate to the desired value */ +static inline void uart_set_baud(int uart_num, int bps) +{ + uint32_t divider = APB_CLK_FREQ / bps; + UART(uart_num).CLOCK_DIVIDER = divider; +} + +/* Returns the current baud rate for the UART */ +static inline int uart_get_baud(int uart_num) +{ + return APB_CLK_FREQ / FIELD2VAL(UART_CLOCK_DIVIDER_VALUE, UART(uart_num).CLOCK_DIVIDER); +} + #endif /* _ESP_UART_H */ diff --git a/examples/blink/blink.c b/examples/blink/blink.c index 52d69a5..8f34ee5 100644 --- a/examples/blink/blink.c +++ b/examples/blink/blink.c @@ -3,7 +3,6 @@ * This sample code is in the public domain. */ #include "espressif/esp_common.h" -#include "espressif/sdk_private.h" #include "FreeRTOS.h" #include "task.h" #include "esp8266.h" @@ -53,7 +52,6 @@ void blinkenRegisterTask(void *pvParameters) void user_init(void) { - sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); xTaskCreate(blinkenTask, (signed char *)"blinkenTask", 256, NULL, 2, NULL); //xTaskCreate(blinkenRegisterTask, (signed char *)"blinkenRegisterTask", 256, NULL, 2, NULL); } diff --git a/examples/blink_timers/blink_timers.c b/examples/blink_timers/blink_timers.c index 5b6b7a2..fd9b000 100644 --- a/examples/blink_timers/blink_timers.c +++ b/examples/blink_timers/blink_timers.c @@ -3,7 +3,6 @@ * This sample code is in the public domain. */ #include "espressif/esp_common.h" -#include "espressif/sdk_private.h" #include "FreeRTOS.h" #include "task.h" #include "esp8266.h" @@ -33,8 +32,6 @@ void frc2_interrupt_handler(void) void user_init(void) { - sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); - /* configure GPIOs */ gpio_enable(gpio_frc1, GPIO_OUTPUT); gpio_enable(gpio_frc2, GPIO_OUTPUT); diff --git a/examples/bmp180_i2c/bmp180_i2c.c b/examples/bmp180_i2c/bmp180_i2c.c index 578db67..073fc55 100644 --- a/examples/bmp180_i2c/bmp180_i2c.c +++ b/examples/bmp180_i2c/bmp180_i2c.c @@ -3,7 +3,6 @@ * This sample code is in the public domain. */ #include "espressif/esp_common.h" -#include "espressif/sdk_private.h" #include "FreeRTOS.h" #include "task.h" @@ -83,22 +82,9 @@ void bmp180_task(void *pvParameters) } } -// Setup HW -void user_setup(void) -{ - // Set UART Parameter - sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); - - // Give the UART some time to settle - sdk_os_delay_us(500); -} - void user_init(void) { - // Setup HW - user_setup(); - - // Just some infomations + // Just some informations printf("\n"); printf("SDK version : %s\n", sdk_system_get_sdk_version()); printf("GIT version : %s\n", GITSHORTREV); diff --git a/examples/button/button.c b/examples/button/button.c index e197ffc..b8c7fdd 100644 --- a/examples/button/button.c +++ b/examples/button/button.c @@ -6,7 +6,6 @@ * This sample code is in the public domain. */ #include "espressif/esp_common.h" -#include "espressif/sdk_private.h" #include "FreeRTOS.h" #include "task.h" #include "queue.h" @@ -75,7 +74,6 @@ void GPIO_HANDLER(void) void user_init(void) { - sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); gpio_enable(gpio, GPIO_INPUT); tsqueue = xQueueCreate(2, sizeof(uint32_t)); diff --git a/examples/cpp_01_tasks/cpp_tasks.cpp b/examples/cpp_01_tasks/cpp_tasks.cpp index 9e381b9..13b0cbc 100644 --- a/examples/cpp_01_tasks/cpp_tasks.cpp +++ b/examples/cpp_01_tasks/cpp_tasks.cpp @@ -94,8 +94,6 @@ esp_open_rtos::thread::queue_t MyQueue; */ extern "C" void user_init(void) { - sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); - MyQueue.queue_create(10); task_1.queue = MyQueue; diff --git a/examples/experiments/timers/timers.c b/examples/experiments/timers/timers.c index 2a11bec..8c1bca8 100644 --- a/examples/experiments/timers/timers.c +++ b/examples/experiments/timers/timers.c @@ -7,7 +7,6 @@ * This experimental reverse engineering code is in the public domain. */ #include "espressif/esp_common.h" -#include "espressif/sdk_private.h" #include "FreeRTOS.h" #include "task.h" #include "esp8266.h" @@ -118,7 +117,6 @@ void frc2_handler(void) void user_init(void) { - sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); xTaskCreate(timerRegTask, (signed char *)"timerRegTask", 1024, NULL, 2, NULL); TIMER(0).CTRL = VAL2FIELD(TIMER_CTRL_CLKDIV, TIMER_CLKDIV_256) | TIMER_CTRL_RELOAD; diff --git a/examples/experiments/unaligned_load/unaligned_load.c b/examples/experiments/unaligned_load/unaligned_load.c index 1574172..8af7025 100644 --- a/examples/experiments/unaligned_load/unaligned_load.c +++ b/examples/experiments/unaligned_load/unaligned_load.c @@ -3,7 +3,6 @@ #include "esp/rom.h" #include "esp/timer.h" #include "espressif/esp_common.h" -#include "espressif/sdk_private.h" #include "FreeRTOS.h" #include "task.h" #include "queue.h" @@ -214,8 +213,6 @@ void sanity_tests(void); void user_init(void) { - sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); - gpio_enable(2, GPIO_OUTPUT); /* used for LED debug */ gpio_write(2, 1); /* active low */ diff --git a/examples/http_get/http_get.c b/examples/http_get/http_get.c index 408b462..6822194 100644 --- a/examples/http_get/http_get.c +++ b/examples/http_get/http_get.c @@ -114,7 +114,6 @@ void http_get_task(void *pvParameters) void user_init(void) { - sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); printf("SDK version:%s\n", sdk_system_get_sdk_version()); struct sdk_station_config config = { diff --git a/examples/http_get_mbedtls/http_get_mbedtls.c b/examples/http_get_mbedtls/http_get_mbedtls.c index d1fbf0d..f050fdd 100644 --- a/examples/http_get_mbedtls/http_get_mbedtls.c +++ b/examples/http_get_mbedtls/http_get_mbedtls.c @@ -331,7 +331,6 @@ void http_get_task(void *pvParameters) void user_init(void) { - sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); printf("SDK version:%s\n", sdk_system_get_sdk_version()); struct sdk_station_config config = { diff --git a/examples/ota_basic/ota_basic.c b/examples/ota_basic/ota_basic.c index 69751d0..3bffa4e 100644 --- a/examples/ota_basic/ota_basic.c +++ b/examples/ota_basic/ota_basic.c @@ -7,7 +7,6 @@ * NOT SUITABLE TO PUT ON THE INTERNET OR INTO A PRODUCTION ENVIRONMENT!!!! */ #include "espressif/esp_common.h" -#include "espressif/sdk_private.h" #include "FreeRTOS.h" #include "task.h" #include "esp8266.h" @@ -18,8 +17,6 @@ void user_init(void) { - sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); - rboot_config_t conf = rboot_get_config(); printf("\r\n\r\nOTA Basic demo.\r\nCurrently running on flash slot %d / %d.\r\n\r\n", conf.current_rom, conf.count); diff --git a/examples/simple/simple.c b/examples/simple/simple.c index 98e4ada..7044119 100644 --- a/examples/simple/simple.c +++ b/examples/simple/simple.c @@ -1,7 +1,6 @@ /* Very basic example that just demonstrates we can run at all! */ #include "espressif/esp_common.h" -#include "espressif/sdk_private.h" #include "FreeRTOS.h" #include "task.h" #include "queue.h" @@ -36,7 +35,6 @@ static xQueueHandle mainqueue; void user_init(void) { - sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); printf("SDK version:%s\n", sdk_system_get_sdk_version()); mainqueue = xQueueCreate(10, sizeof(uint32_t)); xTaskCreate(task1, (signed char *)"tsk1", 256, &mainqueue, 2, NULL); diff --git a/examples/simple_cplusplus/simple.cpp b/examples/simple_cplusplus/simple.cpp index 1826499..688475d 100644 --- a/examples/simple_cplusplus/simple.cpp +++ b/examples/simple_cplusplus/simple.cpp @@ -3,7 +3,6 @@ This sample code is in the public domain. */ #include "espressif/esp_common.h" -#include "espressif/sdk_private.h" #include "FreeRTOS.h" #include "task.h" #include "queue.h" @@ -58,7 +57,6 @@ void task1(void *pvParameters) extern "C" void user_init(void) { - sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); printf("SDK version:%s\n", sdk_system_get_sdk_version()); xTaskCreate(task1, (signed char *)"tsk1", 256, NULL, 2, NULL); }