diff --git a/firmware/fiatlux.c b/firmware/fiatlux.c index a0fb5ea..1368d86 100644 --- a/firmware/fiatlux.c +++ b/firmware/fiatlux.c @@ -2,6 +2,7 @@ #include #include +#include "system.h" #include "wifi.h" #include "web.h" #include "mqtt.h" @@ -15,5 +16,5 @@ void user_init(void) sdk_wifi_set_sleep_type(WIFI_SLEEP_MODEM); - while(1); + system_init_config(); } diff --git a/firmware/system.c b/firmware/system.c index f4a9e2e..350f86e 100644 --- a/firmware/system.c +++ b/firmware/system.c @@ -20,4 +20,18 @@ void system_clear_config(){ spiflash_erase_sector(start + i * sdk_flashchip.sector_size); } sdk_system_restart(); +} + +void system_init_config(){ + uint32_t base_addr; + uint32_t num_sectors; + if(sysparam_get_info(&base_addr, &num_sectors) != SYSPARAM_OK) { + printf("Warning: WiFi config, sysparam not initialized\n"); + num_sectors = DEFAULT_SYSPARAM_SECTORS; + base_addr = sdk_flashchip.chip_size - (5 + num_sectors) * sdk_flashchip.sector_size; + if(sysparam_create_area(base_addr, num_sectors, true) == SYSPARAM_OK) { + sysparam_init(base_addr, 0); + } + sdk_system_restart(); + } } \ No newline at end of file diff --git a/firmware/system.h b/firmware/system.h index 1046f49..14f5188 100644 --- a/firmware/system.h +++ b/firmware/system.h @@ -10,6 +10,7 @@ extern "C" { #endif void system_clear_config(); +void system_init_config(); #ifdef __cplusplus }