From 585c4b80bb359d1f1848a04b1ef4a3e44145e1a2 Mon Sep 17 00:00:00 2001 From: Manuel Bleichenbacher Date: Mon, 23 Jul 2018 16:59:38 +0200 Subject: [PATCH] Configuration of UART --- .vscode/c_cpp_properties.json | 2 ++ .vscode/settings.json | 3 ++- Kconfig | 42 +++++++++++++++++------------------ src/provisioning.c | 25 ++++++++++++++++----- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 934642c..199c206 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -16,7 +16,9 @@ "${IDF_PATH}/components/soc/include", "${IDF_PATH}/components/soc/esp32/include", "${IDF_PATH}/components/tcpip_adapter/include", + "${workspaceRoot}/examples/provisioning/build/include", "${workspaceRoot}/examples/hello_world/build/include", + "${workspaceRoot}/examples/send_recv/build/include", "${workspaceRoot}/include", "${workspaceRoot}/src" ], diff --git a/.vscode/settings.json b/.vscode/settings.json index 248ebc7..28b96ed 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "provisioning.h": "c", "config.h": "c", "sdkconfig.h": "c", - "oslmic.h": "c" + "oslmic.h": "c", + "hal_esp32.h": "c" } } \ No newline at end of file diff --git a/Kconfig b/Kconfig index f1ef14c..8e02846 100644 --- a/Kconfig +++ b/Kconfig @@ -88,21 +88,6 @@ config TTN_PROVISION_UART_NONE bool "None" endchoice -choice TTN_PROVISION_UART_INIT - prompt "Initialize UART" - default TTN_PROVISION_UART_INIT_NO - depends on !TTN_PROVISION_UART_NONE - help - Select whether to initialize the UART, i.e. set the baud rate, the RX and TX - pins. If the UART is shared with other features (e.g. the console), it - should not be initialized. - -config TTN_PROVISION_UART_INIT_NO - bool "No" -config TTN_PROVISION_UART_INIT_YES - bool "Yes" -endchoice - choice TTN_PROVISION_UART_NUM prompt "UART peripheral for provisioning (0-1)" depends on TTN_PROVISION_UART_CUSTOM @@ -114,6 +99,21 @@ config TTN_PROVISION_UART_CUSTOM_NUM_1 bool "UART1" endchoice +choice TTN_PROVISION_UART_CONFIG + prompt "Configure UART settings" + default TTN_PROVISION_UART_CONFIG_NO + depends on TTN_PROVISION_UART_CUSTOM + help + Select whether to configure the UART, i.e. set the baud rate, the RX and TX + pins. If the UART is shared with other features (e.g. the console), it + should not be configured. + +config TTN_PROVISION_UART_CONFIG_NO + bool "No" +config TTN_PROVISION_UART_CONFIG_YES + bool "Yes" +endchoice + config TTN_PROVISION_UART_NUM int default 0 if TTN_PROVISION_UART_DEFAULT || TTN_PROVISION_UART_NONE @@ -122,21 +122,21 @@ config TTN_PROVISION_UART_NUM config TTN_PROVISION_UART_TX_GPIO int "Provisioning UART TX on GPIO#" - depends on TTN_PROVISION_UART_CUSTOM && TTN_PROVISION_UART_INIT_YES + depends on TTN_PROVISION_UART_CONFIG_YES range 0 33 - default 19 + default 1 config TTN_PROVISION_UART_RX_GPIO int "Provisioning UART RX on GPIO#" - depends on TTN_PROVISION_UART_CUSTOM && TTN_PROVISION_UART_INIT_YES + depends on TTN_PROVISION_UART_CONFIG_YES range 0 39 - default 21 + default 3 config TTN_PROVISION_UART_BAUDRATE int "Provisioning UART baud rate" - depends on TTN_PROVISION_UART_CUSTOM && TTN_PROVISION_UART_INIT_YES - default 115200 + depends on TTN_PROVISION_UART_CONFIG_YES range 1200 4000000 + default 115200 endmenu diff --git a/src/provisioning.c b/src/provisioning.c index a6b5e82..c417151 100644 --- a/src/provisioning.c +++ b/src/provisioning.c @@ -53,8 +53,8 @@ static bool have_keys = false; static bool quit_task = false; -#if defined(CONFIG_TTN_PROVISION_UART_INIT_YES) -static void provisioning_init_uart(); +#if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES) +static void provisioning_config_uart(); #endif @@ -88,8 +88,8 @@ void os_getDevKey (u1_t* buf) void provisioning_start_task() { -#if defined(CONFIG_TTN_PROVISION_UART_INIT_YES) - provisioning_init_uart(); +#if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES) + provisioning_config_uart(); #endif esp_err_t err = uart_driver_install(UART_NUM, 2048, 2048, 20, &uart_queue, 0); @@ -244,11 +244,24 @@ void provisioning_process_line() uart_write_bytes(UART_NUM, is_ok ? "OK\r\n" : "ERROR\r\n", is_ok ? 4 : 7); } -#if defined(CONFIG_TTN_PROVISION_UART_INIT_YES) +#if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES) -void provisioning_init_uart() +void provisioning_config_uart() { + esp_err_t err; + uart_config_t uart_config = { + .baud_rate = CONFIG_TTN_PROVISION_UART_BAUDRATE, + .data_bits = UART_DATA_8_BITS, + .parity = UART_PARITY_DISABLE, + .stop_bits = UART_STOP_BITS_1, + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE + }; + err = uart_param_config(UART_NUM, &uart_config); + ESP_ERROR_CHECK(err); + + err = uart_set_pin(UART_NUM, CONFIG_TTN_PROVISION_UART_TX_GPIO, CONFIG_TTN_PROVISION_UART_RX_GPIO, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + ESP_ERROR_CHECK(err); } #endif