uart and wifi not working together
Posted: Tue Apr 09, 2019 7:38 am
Hello Everyone,
I am trying to start wifi in sation mode after I receive some data on UART, I am using ESP32. after receiving value on uart I am calling wifi init after wifi initialisation I am getting
Guru Meditation Error: Core 0 panic'ed (LoadStoreError). Exception was unhandle d.
Core 0 register dump:
My code is
Error log
[Codebox]load:0x40078000,len:11308
load:0x40080400,len:6680
entry 0x40080760
I (31) boot: ESP-IDF v4.0-dev-207-g76da10a66-dirty 2nd stage bootloader
I (31) boot: compile time 16:41:15
I (32) boot: Enabling RNG early entropy source...
I (37) boot: SPI Speed : 40MHz
I (42) boot: SPI Mode : DIO
I (46) boot: SPI Flash Size : 4MB
I (50) boot: Partition Table:
I (53) boot: ## Label Usage Type ST Offset Length
I (60) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (68) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (75) boot: 2 factory factory app 00 00 00010000 00100000
I (83) boot: End of partition table
I (87) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x18618 ( 99 864) map
I (131) esp_image: segment 1: paddr=0x00028640 vaddr=0x3ffb0000 size=0x02ff0 ( 1 2272) load
I (136) esp_image: segment 2: paddr=0x0002b638 vaddr=0x40080000 size=0x00400 ( 1024) load
I (138) esp_image: segment 3: paddr=0x0002ba40 vaddr=0x40080400 size=0x045d0 ( 1 7872) load
I (154) esp_image: segment 4: paddr=0x00030018 vaddr=0x400d0018 size=0x67820 (42 3968) map
I (304) esp_image: segment 5: paddr=0x00097840 vaddr=0x400849d0 size=0x0bda0 ( 4 8544) load
I (334) boot: Loaded app from partition at offset 0x10000
I (334) boot: Disabling RNG early entropy source...
I (335) cpu_start: Pro cpu up.
I (338) cpu_start: Application information:
I (343) cpu_start: Project name: wifi_softAP
I (348) cpu_start: App version: v4.0-dev-207-g76da10a66-dirty
I (355) cpu_start: Compile time: Apr 9 2019 16:40:08
I (361) cpu_start: ELF file SHA256: 2af6b75480f86821...
I (367) cpu_start: ESP-IDF: v4.0-dev-207-g76da10a66-dirty
I (374) cpu_start: Starting app cpu, entry point is 0x400810d8
I (366) cpu_start: App cpu up.
I (385) heap_init: Initializing. RAM available for dynamic allocation:
I (392) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (398) heap_init: At 3FFB8DD0 len 00027230 (156 KiB): DRAM
I (404) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (410) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (417) heap_init: At 40090770 len 0000F890 (62 KiB): IRAM
I (423) cpu_start: Pro cpu start user code
I (106) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (170) RX_TASK: rx task
I (170) TX_TASK: Wrote 15 bytes
I (1310) RX_TASK: Received bytes = 10
I (1310) RX_TASK: Enable Wifi
I (1310) wifi: wifi driver task: 3ffc1f5c, prio:23, stack:3584, core=0
I (1310) wifi: wifi firmware version: 8b94b0e
I (1310) wifi: config NVS flash: enabled
I (1320) wifi: config nano formating: disabled
I (1320) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (1330) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (1360) wifi: Init dynamic tx buffer num: 32
I (1370) wifi: Init data frame dynamic rx buffer num: 32
I (1370) wifi: Init management frame dynamic rx buffer num: 32
I (1370) wifi: Init management short buffer num: 32
I (1370) wifi: Init static rx buffer size: 1600
I (1380) wifi: Init static rx buffer num: 10
I (1380) wifi: Init dynamic rx buffer num: 32
I (1520) phy: phy_version: 4100, 6fa5e27, Jan 25 2019, 17:02:06, 0, 0
I (1520) wifi: mode : sta (b4:e6:2d:9e:88:f5)
I (1520) wifi softAP: wifi init finished. SSID:xxxx password:xxxxxxxxxx
Guru Meditation Error: Core 0 panic'ed (LoadStoreError). Exception was unhandle d.
Core 0 register dump:
PC : 0x4000c2ff PS : 0x00060b30 A0 : 0x800d2e31 A1 : 0x3f fbe100
A2 : 0x3f40337c A3 : 0x3f403350 A4 : 0x0000000a A5 : 0x3f 40337c
A6 : 0x69666957 A7 : 0x696e4920 A8 : 0x00000000 A9 : 0x3f fbdf70
A10 : 0x400dc9cc A11 : 0x3ffb3c48 A12 : 0x3f403290 A13 : 0x00 000028
A14 : 0x00000006 A15 : 0x00000005 SAR : 0x00000004 EXCCAUSE: 0x00 000003
EXCVADDR: 0x3f40337c LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xff ffffff
ELF file SHA256: 2af6b75480f86821f4fd555a78910d0078602e9f806e22d530e8f305e2d7dc3 7
Backtrace: 0x4000c2ff:0x3ffbe100 0x400d2e2e:0x3ffbe110 0x4008da35:0x3ffbe130
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:6368
ho 0 tail 12 room 4
load:0x40078000,len:11308
load:0x40080400,len:6680
entry 0x40080760
[/Codebox]
Please help me with this? What I am doing wrong for initialization, I have even tried with uart ISR its giving me same problem.
I am trying to start wifi in sation mode after I receive some data on UART, I am using ESP32. after receiving value on uart I am calling wifi init after wifi initialisation I am getting
Guru Meditation Error: Core 0 panic'ed (LoadStoreError). Exception was unhandle d.
Core 0 register dump:
My code is
Code: Select all
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "driver/uart.h"
#include "soc/uart_struct.h"
#include "lwip/err.h"
#include "lwip/sys.h"
static const int RX_BUF_SIZE = 1024;
#define TXD_PIN (GPIO_NUM_17)
#define RXD_PIN (GPIO_NUM_16)
#define WIFI_SSID "xxxxx"
#define WIFI_PASS "xxxxxxxx"
#define EXAMPLE_MAX_STA_CONN CONFIG_MAX_STA_CONN
static intr_handle_t handle_console;
/* The event group allows multiple bits for each event,
but we only care about one event - are we connected
to the AP with an IP? */
const static int CONNECTED_BIT = BIT0;
#define OPENSSL_EXAMPLE_TARGET_NAME CONFIG_TARGET_DOMAIN
#define OPENSSL_EXAMPLE_TARGET_TCP_PORT CONFIG_TARGET_PORT_NUMBER
// Receive buffer to collect incoming data
uint8_t rxbuf[256], flag = 0;
// Register to collect data length
uint16_t urxlen;
typedef enum {
// Commands from IMX to ESP - Wifi
EnableWifi = 0x30,
GetWifiStatus,
SetWifiConfig,
Number_of_AccessPoints_List,
Number_of_AccessPoints_Record,
Access_Point_Conected_Info,
Set_MAC_Address,
Get_IP_Address,
Get_GatewayAddress,
DisconnectWifi,
Set_Tx_Power,
Get_Auth_Mode,
// Common codes for ESP
ESP_Initialised = 0x50,
Get_ESP32_Status,
Get_ESP32_Mode,
MAC_Address,
Firmware_Version_Number,
SW_Version_Number,
Default_State= 0x7F,
}WifiCommands;
/* FreeRTOS event group to signal when we are connected*/
static EventGroupHandle_t s_wifi_event_group;
static const char *TAG = "wifi softAP";
char *txData = "ESP Initialised";
void wifi_init(void);
void uart_init() {
const uart_config_t uart_config = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
};
uart_param_config(UART_NUM_1, &uart_config);
uart_set_pin(UART_NUM_1, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
// We won't use a buffer for sending data.
uart_driver_install(UART_NUM_1, RX_BUF_SIZE * 2, 0, 0, NULL, 0);
}
int sendData(const char* logName, const char* data)
{
const int len = strlen(txData);
const int txBytes = uart_write_bytes(UART_NUM_1, txData, len);
ESP_LOGI(logName, "Wrote %d bytes", txBytes);
return txBytes;
}
static void tx_task()
{
static const char *TX_TASK_TAG = "TX_TASK";
esp_log_level_set(TX_TASK_TAG, ESP_LOG_INFO);
while(1)
{
if(flag == 0) {
sendData(TX_TASK_TAG, "Hello world");
}
else
{
sendData(TX_TASK_TAG, "Hello world");
}
vTaskDelay(10000/portTICK_PERIOD_MS);
}
}
static void rx_task()
{
static const char *RX_TASK_TAG = "RX_TASK";
esp_log_level_set(RX_TASK_TAG, ESP_LOG_INFO);
uint8_t* data = (uint8_t*) malloc(RX_BUF_SIZE+1);
while (1) {
ESP_LOGI(RX_TASK_TAG,"rx task");
const int rxBytes = uart_read_bytes(UART_NUM_1, data, RX_BUF_SIZE, 1000 / portTICK_RATE_MS);
if (rxBytes > 0) {
ESP_LOGI(RX_TASK_TAG,"Received bytes = %d",rxBytes);
data[rxBytes] = 0;
switch (data[0]){
case EnableWifi:
case ESP_Initialised:
ESP_LOGI(RX_TASK_TAG,"Enable Wifi");
if(flag ==0)
{
strcpy(txData, "Wifi Init");
flag=1;
}
break;
case SetWifiConfig:
break;
case Set_MAC_Address:
break;
case Get_IP_Address:
break;
case DisconnectWifi:
break;
case Set_Tx_Power:
break;
}
}
vTaskDelay(5000/portTICK_PERIOD_MS);
}
free(data);
}
static esp_err_t event_handler(void *ctx, system_event_t *event)
{
switch(event->event_id) {
case SYSTEM_EVENT_STA_START:
ESP_LOGI(TAG, "wifi event connect");
esp_wifi_connect();
break;
case SYSTEM_EVENT_STA_GOT_IP:
ESP_LOGI(TAG, "wifi event got ip");
xEventGroupSetBits(s_wifi_event_group, CONNECTED_BIT);
strcpy(txData, "Connected to Swift Tech");
//openssl_example_client_init();
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
/* This is a workaround as ESP32 WiFi libs don't currently
auto-reassociate. */
esp_wifi_connect();
xEventGroupClearBits(s_wifi_event_group, CONNECTED_BIT);
break;
default:
break;
}
return ESP_OK;
}
void wifi_init()
{
s_wifi_event_group = xEventGroupCreate();
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
wifi_config_t wifi_config = {
.ap = {
.ssid = WIFI_SSID,
.ssid_len = strlen(WIFI_SSID),
.password = WIFI_PASS,
.max_connection = EXAMPLE_MAX_STA_CONN,
.authmode = WIFI_AUTH_WPA_WPA2_PSK
},
};
if (strlen(WIFI_PASS) == 0) {
wifi_config.ap.authmode = WIFI_AUTH_OPEN;
}
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_LOGI(TAG, "wifi init finished. SSID:%s password:%s",
WIFI_SSID, WIFI_PASS);
}
void app_main()
{
//Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
uart_init();
wifi_init();
xTaskCreate(rx_task, "uart_rx_task", 1024*2, NULL, configMAX_PRIORITIES, NULL);
//xTaskCreate(tx_task, "uart_tx_task", 1024*2, NULL, configMAX_PRIORITIES-1, NULL);
while(1)
{
tx_task();
}
}
[Codebox]load:0x40078000,len:11308
load:0x40080400,len:6680
entry 0x40080760
I (31) boot: ESP-IDF v4.0-dev-207-g76da10a66-dirty 2nd stage bootloader
I (31) boot: compile time 16:41:15
I (32) boot: Enabling RNG early entropy source...
I (37) boot: SPI Speed : 40MHz
I (42) boot: SPI Mode : DIO
I (46) boot: SPI Flash Size : 4MB
I (50) boot: Partition Table:
I (53) boot: ## Label Usage Type ST Offset Length
I (60) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (68) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (75) boot: 2 factory factory app 00 00 00010000 00100000
I (83) boot: End of partition table
I (87) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x18618 ( 99 864) map
I (131) esp_image: segment 1: paddr=0x00028640 vaddr=0x3ffb0000 size=0x02ff0 ( 1 2272) load
I (136) esp_image: segment 2: paddr=0x0002b638 vaddr=0x40080000 size=0x00400 ( 1024) load
I (138) esp_image: segment 3: paddr=0x0002ba40 vaddr=0x40080400 size=0x045d0 ( 1 7872) load
I (154) esp_image: segment 4: paddr=0x00030018 vaddr=0x400d0018 size=0x67820 (42 3968) map
I (304) esp_image: segment 5: paddr=0x00097840 vaddr=0x400849d0 size=0x0bda0 ( 4 8544) load
I (334) boot: Loaded app from partition at offset 0x10000
I (334) boot: Disabling RNG early entropy source...
I (335) cpu_start: Pro cpu up.
I (338) cpu_start: Application information:
I (343) cpu_start: Project name: wifi_softAP
I (348) cpu_start: App version: v4.0-dev-207-g76da10a66-dirty
I (355) cpu_start: Compile time: Apr 9 2019 16:40:08
I (361) cpu_start: ELF file SHA256: 2af6b75480f86821...
I (367) cpu_start: ESP-IDF: v4.0-dev-207-g76da10a66-dirty
I (374) cpu_start: Starting app cpu, entry point is 0x400810d8
I (366) cpu_start: App cpu up.
I (385) heap_init: Initializing. RAM available for dynamic allocation:
I (392) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (398) heap_init: At 3FFB8DD0 len 00027230 (156 KiB): DRAM
I (404) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (410) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (417) heap_init: At 40090770 len 0000F890 (62 KiB): IRAM
I (423) cpu_start: Pro cpu start user code
I (106) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (170) RX_TASK: rx task
I (170) TX_TASK: Wrote 15 bytes
I (1310) RX_TASK: Received bytes = 10
I (1310) RX_TASK: Enable Wifi
I (1310) wifi: wifi driver task: 3ffc1f5c, prio:23, stack:3584, core=0
I (1310) wifi: wifi firmware version: 8b94b0e
I (1310) wifi: config NVS flash: enabled
I (1320) wifi: config nano formating: disabled
I (1320) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (1330) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (1360) wifi: Init dynamic tx buffer num: 32
I (1370) wifi: Init data frame dynamic rx buffer num: 32
I (1370) wifi: Init management frame dynamic rx buffer num: 32
I (1370) wifi: Init management short buffer num: 32
I (1370) wifi: Init static rx buffer size: 1600
I (1380) wifi: Init static rx buffer num: 10
I (1380) wifi: Init dynamic rx buffer num: 32
I (1520) phy: phy_version: 4100, 6fa5e27, Jan 25 2019, 17:02:06, 0, 0
I (1520) wifi: mode : sta (b4:e6:2d:9e:88:f5)
I (1520) wifi softAP: wifi init finished. SSID:xxxx password:xxxxxxxxxx
Guru Meditation Error: Core 0 panic'ed (LoadStoreError). Exception was unhandle d.
Core 0 register dump:
PC : 0x4000c2ff PS : 0x00060b30 A0 : 0x800d2e31 A1 : 0x3f fbe100
A2 : 0x3f40337c A3 : 0x3f403350 A4 : 0x0000000a A5 : 0x3f 40337c
A6 : 0x69666957 A7 : 0x696e4920 A8 : 0x00000000 A9 : 0x3f fbdf70
A10 : 0x400dc9cc A11 : 0x3ffb3c48 A12 : 0x3f403290 A13 : 0x00 000028
A14 : 0x00000006 A15 : 0x00000005 SAR : 0x00000004 EXCCAUSE: 0x00 000003
EXCVADDR: 0x3f40337c LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xff ffffff
ELF file SHA256: 2af6b75480f86821f4fd555a78910d0078602e9f806e22d530e8f305e2d7dc3 7
Backtrace: 0x4000c2ff:0x3ffbe100 0x400d2e2e:0x3ffbe110 0x4008da35:0x3ffbe130
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:6368
ho 0 tail 12 room 4
load:0x40078000,len:11308
load:0x40080400,len:6680
entry 0x40080760
[/Codebox]
Please help me with this? What I am doing wrong for initialization, I have even tried with uart ISR its giving me same problem.