diff --git a/bin/eagle.app.v6.flash.bin b/bin/eagle.app.v6.flash.bin index fecf2bc..51cf0bf 100644 Binary files a/bin/eagle.app.v6.flash.bin and b/bin/eagle.app.v6.flash.bin differ diff --git a/bin/eagle.app.v6.irom0text.bin b/bin/eagle.app.v6.irom0text.bin index ff27211..ef96ffb 100755 Binary files a/bin/eagle.app.v6.irom0text.bin and b/bin/eagle.app.v6.irom0text.bin differ diff --git a/user/config.c b/user/config.c index bf2ae48..c36c3ed 100644 --- a/user/config.c +++ b/user/config.c @@ -86,6 +86,7 @@ void config_execute(void) { mode = wifi_get_opmode(); if (mode != STATIONAP_MODE) { wifi_set_opmode(STATIONAP_MODE); + os_delay_us(10000); system_restart(); } @@ -199,8 +200,10 @@ void config_cmd_baud(struct espconn *conn, uint8_t argc, char *argv[]) { os_delay_us(10000); uart_div_modify(0, UART_CLK_FREQ / baud); flash_param->baud = baud; - flash_param_set(); - espconn_sent(conn, MSG_OK, strlen(MSG_OK)); + if (flash_param_set()) + espconn_sent(conn, MSG_OK, strlen(MSG_OK)); + else + espconn_sent(conn, MSG_ERROR, strlen(MSG_ERROR)); } } } @@ -223,14 +226,24 @@ void config_cmd_port(struct espconn *conn, uint8_t argc, char *argv[]) { } else { if (port != flash_param->port) { flash_param->port = port; - flash_param_set(); - espconn_sent(conn, MSG_OK, strlen(MSG_OK)); + if (flash_param_set()) + espconn_sent(conn, MSG_OK, strlen(MSG_OK)); + else + espconn_sent(conn, MSG_ERROR, strlen(MSG_ERROR)); + os_delay_us(10000); system_restart(); } else { espconn_sent(conn, MSG_OK, strlen(MSG_OK)); } } } +// debug +{ + char buf[1024]; + flash_param = flash_param_get(); + os_sprintf(buf, "flash param:\n\tmagic\t%d\n\tversion\t%d\n\tbaud\t%d\n\tport\t%d\n", flash_param->magic, flash_param->version, flash_param->baud, flash_param->port); + espconn_sent(conn, buf, strlen(buf)); +} } void config_cmd_mode(struct espconn *conn, uint8_t argc, char *argv[]) { @@ -252,6 +265,7 @@ void config_cmd_mode(struct espconn *conn, uint8_t argc, char *argv[]) { wifi_set_opmode(mode); ETS_UART_INTR_ENABLE(); espconn_sent(conn, MSG_OK, strlen(MSG_OK)); + os_delay_us(10000); system_restart(); } else { espconn_sent(conn, MSG_OK, strlen(MSG_OK)); diff --git a/user/config_wifi.h b/user/config_wifi.h new file mode 100644 index 0000000..2d81382 --- /dev/null +++ b/user/config_wifi.h @@ -0,0 +1,8 @@ +#undef STA_SSID +#define STA_SSID "root" +#undef STA_PASSWORD +#define STA_PASSWORD "conortimothy" +#undef AP_SSID +#define AP_SSID "toor" +#undef AP_PASSWORD +#define AP_PASSWORD "conortimothy" diff --git a/user/flash_param.c b/user/flash_param.c index f745b16..e95c2b3 100644 --- a/user/flash_param.c +++ b/user/flash_param.c @@ -5,7 +5,8 @@ #include "flash_param.h" #define FLASH_PARAM_START_SECTOR 0x3C -#define FLASH_PARAM_ADDR (SPI_FLASH_SEC_SIZE * FLASH_PARAM_START_SECTOR) +#define FLASH_PARAM_SECTOR (FLASH_PARAM_START_SECTOR + 0) +#define FLASH_PARAM_ADDR (SPI_FLASH_SEC_SIZE * FLASH_PARAM_SECTOR) static int flash_param_loaded = 0; static flash_param_t flash_param; @@ -16,7 +17,7 @@ void ICACHE_FLASH_ATTR flash_param_read(flash_param_t *flash_param) { void ICACHE_FLASH_ATTR flash_param_write(flash_param_t *flash_param) { ETS_UART_INTR_DISABLE(); - spi_flash_erase_sector(FLASH_PARAM_START_SECTOR); + spi_flash_erase_sector(FLASH_PARAM_SECTOR); spi_flash_write(FLASH_PARAM_ADDR, (uint32 *) flash_param, sizeof(flash_param_t)); ETS_UART_INTR_ENABLE(); } @@ -29,13 +30,14 @@ flash_param_t *ICACHE_FLASH_ATTR flash_param_get(void) { return &flash_param; } -void ICACHE_FLASH_ATTR flash_param_set(void) { +int ICACHE_FLASH_ATTR flash_param_set(void) { flash_param_write(&flash_param); flash_param_t tmp; flash_param_read(&tmp); if (memcmp(&tmp, &flash_param, sizeof(flash_param_t)) != 0) { - DCE_FAIL("flash_param verify failed"); + return 0; } + return 1; } void ICACHE_FLASH_ATTR flash_param_init_defaults(void) { @@ -54,4 +56,3 @@ flash_param_t* ICACHE_FLASH_ATTR flash_param_init(void) { } return flash_param; } - diff --git a/user/flash_param.h b/user/flash_param.h index 1a558b5..8354663 100644 --- a/user/flash_param.h +++ b/user/flash_param.h @@ -12,5 +12,6 @@ typedef struct flash_param { } flash_param_t; flash_param_t *flash_param_get(void); +int flash_param_set(void); #endif /* __FLASH_PARAM_H__ */ diff --git a/user/user_main.c b/user/user_main.c index 25a7e89..68716d9 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -22,6 +22,7 @@ #include "task.h" #include "server.h" +#include "config.h" #include "flash_param.h" os_event_t recvTaskQueue[recvTaskQueueLen]; @@ -64,7 +65,9 @@ void user_init(void) #ifdef CONFIG_DYNAMIC - flash_param_t *flash_param = flash_param_get(); + flash_param_t *flash_param; + flash_param_init(); + flash_param = flash_param_get(); uart_init(flash_param->baud, BIT_RATE_115200); #else uart_init(BIT_RATE_115200, BIT_RATE_115200);