Configuration of UART

This commit is contained in:
Manuel Bleichenbacher 2018-07-23 16:59:38 +02:00
parent 53d4be5de4
commit 585c4b80bb
4 changed files with 44 additions and 28 deletions

View File

@ -16,7 +16,9 @@
"${IDF_PATH}/components/soc/include", "${IDF_PATH}/components/soc/include",
"${IDF_PATH}/components/soc/esp32/include", "${IDF_PATH}/components/soc/esp32/include",
"${IDF_PATH}/components/tcpip_adapter/include", "${IDF_PATH}/components/tcpip_adapter/include",
"${workspaceRoot}/examples/provisioning/build/include",
"${workspaceRoot}/examples/hello_world/build/include", "${workspaceRoot}/examples/hello_world/build/include",
"${workspaceRoot}/examples/send_recv/build/include",
"${workspaceRoot}/include", "${workspaceRoot}/include",
"${workspaceRoot}/src" "${workspaceRoot}/src"
], ],

View File

@ -3,6 +3,7 @@
"provisioning.h": "c", "provisioning.h": "c",
"config.h": "c", "config.h": "c",
"sdkconfig.h": "c", "sdkconfig.h": "c",
"oslmic.h": "c" "oslmic.h": "c",
"hal_esp32.h": "c"
} }
} }

42
Kconfig
View File

@ -88,21 +88,6 @@ config TTN_PROVISION_UART_NONE
bool "None" bool "None"
endchoice 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 choice TTN_PROVISION_UART_NUM
prompt "UART peripheral for provisioning (0-1)" prompt "UART peripheral for provisioning (0-1)"
depends on TTN_PROVISION_UART_CUSTOM depends on TTN_PROVISION_UART_CUSTOM
@ -114,6 +99,21 @@ config TTN_PROVISION_UART_CUSTOM_NUM_1
bool "UART1" bool "UART1"
endchoice 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 config TTN_PROVISION_UART_NUM
int int
default 0 if TTN_PROVISION_UART_DEFAULT || TTN_PROVISION_UART_NONE 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 config TTN_PROVISION_UART_TX_GPIO
int "Provisioning UART TX on 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 range 0 33
default 19 default 1
config TTN_PROVISION_UART_RX_GPIO config TTN_PROVISION_UART_RX_GPIO
int "Provisioning UART RX on 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 range 0 39
default 21 default 3
config TTN_PROVISION_UART_BAUDRATE config TTN_PROVISION_UART_BAUDRATE
int "Provisioning UART baud rate" int "Provisioning UART baud rate"
depends on TTN_PROVISION_UART_CUSTOM && TTN_PROVISION_UART_INIT_YES depends on TTN_PROVISION_UART_CONFIG_YES
default 115200
range 1200 4000000 range 1200 4000000
default 115200
endmenu endmenu

View File

@ -53,8 +53,8 @@ static bool have_keys = false;
static bool quit_task = false; static bool quit_task = false;
#if defined(CONFIG_TTN_PROVISION_UART_INIT_YES) #if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES)
static void provisioning_init_uart(); static void provisioning_config_uart();
#endif #endif
@ -88,8 +88,8 @@ void os_getDevKey (u1_t* buf)
void provisioning_start_task() void provisioning_start_task()
{ {
#if defined(CONFIG_TTN_PROVISION_UART_INIT_YES) #if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES)
provisioning_init_uart(); provisioning_config_uart();
#endif #endif
esp_err_t err = uart_driver_install(UART_NUM, 2048, 2048, 20, &uart_queue, 0); 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); 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 #endif