Skip to content

Commit

Permalink
Disable UART interrupts when writing to flash
Browse files Browse the repository at this point in the history
Fix #9.
  • Loading branch information
igrr committed Nov 18, 2014
1 parent 00eefbd commit 8f6aadf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions target/esp8266/config_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "config_store.h"
#include "user_interface.h"
#include "spi_flash.h"
#include "ets_sys.h"

#define CONFIG_START_SECTOR 0x3C
#define CONFIG_SECTOR (CONFIG_START_SECTOR + 0)
Expand All @@ -27,8 +28,10 @@ void ICACHE_FLASH_ATTR config_read(config_t* config)

void ICACHE_FLASH_ATTR config_write(config_t* config)
{
ETS_UART_INTR_DISABLE();
spi_flash_erase_sector(CONFIG_SECTOR);
spi_flash_write(CONFIG_ADDR, (uint32_t*) config, sizeof(config_t));
ETS_UART_INTR_ENABLE();
}

config_t* ICACHE_FLASH_ATTR config_get()
Expand Down Expand Up @@ -69,6 +72,9 @@ void ICACHE_FLASH_ATTR config_init_default()
config->version = CONFIG_VERSION;
config->baud_rate = 9600;
config_save();

ETS_UART_INTR_DISABLE();
spi_flash_erase_sector(CONFIG_WIFI_SECTOR);
ETS_UART_INTR_ENABLE();
}

9 changes: 9 additions & 0 deletions target/esp8266/wifi_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "wifi_commands.h"
#include "config_store.h"
#include "user_interface.h"
#include "ets_sys.h"

#define CONNECTION_MONITORING_INTERVAL_MS 100
#define ONCE 0
Expand Down Expand Up @@ -41,7 +42,9 @@ dce_result_t SECTION_ATTR wifi_handle_CWMODE(dce_t* dce, void* group_ctx, int ki
dce_emit_basic_result_code(dce, DCE_RC_ERROR);
return DCE_OK;
}
ETS_UART_INTR_DISABLE();
wifi_set_opmode(argv[0].value.number);
ETS_UART_INTR_ENABLE();
dce_emit_basic_result_code(dce, DCE_RC_OK);
}
return DCE_OK;
Expand Down Expand Up @@ -130,8 +133,10 @@ dce_result_t SECTION_ATTR wifi_handle_CWJAP(dce_t* dce, void* group_ctx, int kin

strcpy(conf.ssid, argv[0].value.string);
strcpy(conf.password, argv[1].value.string);
ETS_UART_INTR_DISABLE();
wifi_station_set_config(&conf);
wifi_station_connect();
ETS_UART_INTR_ENABLE();
dce_emit_basic_result_code(dce, DCE_RC_OK);
}
else
Expand Down Expand Up @@ -160,8 +165,10 @@ dce_result_t SECTION_ATTR wifi_handle_CWQAP(dce_t* dce, void* group_ctx, int kin
struct station_config conf;
*conf.ssid = 0;
*conf.password = 0;
ETS_UART_INTR_DISABLE();
wifi_station_set_config(&conf);
wifi_station_disconnect();
ETS_UART_INTR_ENABLE();
dce_emit_basic_result_code(dce, DCE_RC_OK);
return DCE_OK;
}
Expand Down Expand Up @@ -208,7 +215,9 @@ dce_result_t SECTION_ATTR wifi_handle_CWSAP(dce_t* dce, void* group_ctx, int kin
dce_emit_basic_result_code(dce, DCE_RC_ERROR);
return DCE_OK;
}
ETS_UART_INTR_DISABLE();
wifi_softap_set_config(&conf);
ETS_UART_INTR_ENABLE();
dce_emit_basic_result_code(dce, DCE_RC_OK);
}
else
Expand Down

0 comments on commit 8f6aadf

Please sign in to comment.