From 2df4e596e2c16393569d4920cc402e269276f64f Mon Sep 17 00:00:00 2001 From: Peter Antypas Date: Mon, 16 Jan 2023 21:04:58 -0800 Subject: [PATCH] Factory reset --- latest/Firmware/WiFiAdapter/.gitignore | 6 +--- latest/Firmware/WiFiAdapter/CMakeLists.txt | 2 +- .../hooks/CMakeLists.txt | 6 ++++ .../hooks/bootloader_hooks.c | 35 +++++++++++++++++++ latest/Firmware/WiFiAdapter/bsp/bsp_1_0.c | 13 +++++++ .../WiFiAdapter/main/MaianaWiFiAdapter.c | 2 +- latest/Firmware/WiFiAdapter/partitions.csv | 2 +- latest/Firmware/WiFiAdapter/sdkconfig | 12 +++---- 8 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 latest/Firmware/WiFiAdapter/bootloader_components/hooks/CMakeLists.txt create mode 100644 latest/Firmware/WiFiAdapter/bootloader_components/hooks/bootloader_hooks.c diff --git a/latest/Firmware/WiFiAdapter/.gitignore b/latest/Firmware/WiFiAdapter/.gitignore index d111a9b..1048640 100644 --- a/latest/Firmware/WiFiAdapter/.gitignore +++ b/latest/Firmware/WiFiAdapter/.gitignore @@ -1,10 +1,6 @@ # Build directory build -build_dev/ -build_prod/ -build_factory/ -build_sample/ -sdkconfig + *.lock diff --git a/latest/Firmware/WiFiAdapter/CMakeLists.txt b/latest/Firmware/WiFiAdapter/CMakeLists.txt index 1777def..5e586d4 100755 --- a/latest/Firmware/WiFiAdapter/CMakeLists.txt +++ b/latest/Firmware/WiFiAdapter/CMakeLists.txt @@ -5,6 +5,6 @@ cmake_minimum_required(VERSION 3.5) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -set(EXTRA_COMPONENT_DIRS bsp core html) +set(EXTRA_COMPONENT_DIRS bsp core html bootloader_components) list (APPEND EXTRA_COMPONENT_DIRS components) project(MaianaWiFiAdapter) diff --git a/latest/Firmware/WiFiAdapter/bootloader_components/hooks/CMakeLists.txt b/latest/Firmware/WiFiAdapter/bootloader_components/hooks/CMakeLists.txt new file mode 100644 index 0000000..94ef1ff --- /dev/null +++ b/latest/Firmware/WiFiAdapter/bootloader_components/hooks/CMakeLists.txt @@ -0,0 +1,6 @@ + +idf_component_register(SRCS + "bootloader_hooks.c" + PRIV_REQUIRES hal + ) + \ No newline at end of file diff --git a/latest/Firmware/WiFiAdapter/bootloader_components/hooks/bootloader_hooks.c b/latest/Firmware/WiFiAdapter/bootloader_components/hooks/bootloader_hooks.c new file mode 100644 index 0000000..bbd645e --- /dev/null +++ b/latest/Firmware/WiFiAdapter/bootloader_components/hooks/bootloader_hooks.c @@ -0,0 +1,35 @@ +#include +#include +#include + +#define GPIO_RED_LED GPIO_NUM_5 +#define GPIO_GREEN_LED GPIO_NUM_4 + + +void bootloader_hooks_include(void) +{ +} + +void bootloader_before_init(void) +{ + ESP_LOGI("hook", "Custom hook (before init)"); +} + +void bootloader_after_init(void) +{ + + /** + * @brief Turn on both LEDs immediately. This way, if firmware is hosed and can't run, + * at least there's an indication that the system is on. + * + */ + + ESP_LOGI("hook", "Custom hook (after init)"); + gpio_ll_output_enable(&GPIO, GPIO_GREEN_LED); + gpio_ll_output_enable(&GPIO, GPIO_RED_LED); + + gpio_ll_set_level(&GPIO, GPIO_GREEN_LED, 1); + gpio_ll_set_level(&GPIO, GPIO_RED_LED, 1); + + //sleep(1); +} diff --git a/latest/Firmware/WiFiAdapter/bsp/bsp_1_0.c b/latest/Firmware/WiFiAdapter/bsp/bsp_1_0.c index f7db401..5161ca1 100644 --- a/latest/Firmware/WiFiAdapter/bsp/bsp_1_0.c +++ b/latest/Firmware/WiFiAdapter/bsp/bsp_1_0.c @@ -20,6 +20,8 @@ uint8_t dtmp[RD_BUF_SIZE]; #define GPIO_UART1_RX GPIO_NUM_25 #define GPIO_UART1_TX GPIO_NUM_26 #define GPIO_TX_BUTTON GPIO_NUM_34 +#define GPIO_RED_LED GPIO_NUM_5 +#define GPIO_GREEN_LED GPIO_NUM_4 void uart_rx_task(void *params) { @@ -111,6 +113,17 @@ void bsp_hw_init() gpio_set_direction(GPIO_TX_BUTTON, GPIO_MODE_INPUT); gpio_set_intr_type(GPIO_TX_BUTTON, GPIO_INTR_NEGEDGE); + config_gpio(GPIO_RED_LED, GPIO_MODE_OUTPUT, false, false); + config_gpio(GPIO_GREEN_LED, GPIO_MODE_OUTPUT, false, false); + +#if 0 + gpio_set_direction(GPIO_RED_LED, GPIO_MODE_OUTPUT); + gpio_set_direction(GPIO_GREEN_LED, GPIO_MODE_OUTPUT); + + gpio_set_level(GPIO_RED_LED, 1); + gpio_set_level(GPIO_GREEN_LED, 1); +#endif + gpio_install_isr_service(0); gpio_isr_handler_add(GPIO_TX_BUTTON, btn_isr, NULL); bsp_timer_init(); diff --git a/latest/Firmware/WiFiAdapter/main/MaianaWiFiAdapter.c b/latest/Firmware/WiFiAdapter/main/MaianaWiFiAdapter.c index 70cd073..eca0d4e 100755 --- a/latest/Firmware/WiFiAdapter/main/MaianaWiFiAdapter.c +++ b/latest/Firmware/WiFiAdapter/main/MaianaWiFiAdapter.c @@ -29,7 +29,7 @@ void app_main(void) esp_event_loop_create_default(); esp_event_handler_register(MAIANA_EVENT, REBOOT_EVENT, reboot_handler, NULL); - + //sleep(5); config_init(); //config_reset_all(); diff --git a/latest/Firmware/WiFiAdapter/partitions.csv b/latest/Firmware/WiFiAdapter/partitions.csv index b14a7af..511ade6 100644 --- a/latest/Firmware/WiFiAdapter/partitions.csv +++ b/latest/Firmware/WiFiAdapter/partitions.csv @@ -3,6 +3,6 @@ nvs, data, nvs, 0x9000, 16K otadata, data, ota, , 8K phy_init, data, phy, , 4K +factory, app, factory, , 1536K ota_0, app, ota_0, , 1536K -ota_1, app, ota_1, , 1536K storage, data, fat, , 900K diff --git a/latest/Firmware/WiFiAdapter/sdkconfig b/latest/Firmware/WiFiAdapter/sdkconfig index 9b69df3..07c91d5 100644 --- a/latest/Firmware/WiFiAdapter/sdkconfig +++ b/latest/Firmware/WiFiAdapter/sdkconfig @@ -43,13 +43,13 @@ CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y # CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG is not set # CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF is not set # CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_NONE is not set -CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y +# CONFIG_BOOTLOADER_LOG_LEVEL_NONE is not set # CONFIG_BOOTLOADER_LOG_LEVEL_ERROR is not set # CONFIG_BOOTLOADER_LOG_LEVEL_WARN is not set -# CONFIG_BOOTLOADER_LOG_LEVEL_INFO is not set +CONFIG_BOOTLOADER_LOG_LEVEL_INFO=y # CONFIG_BOOTLOADER_LOG_LEVEL_DEBUG is not set # CONFIG_BOOTLOADER_LOG_LEVEL_VERBOSE is not set -CONFIG_BOOTLOADER_LOG_LEVEL=0 +CONFIG_BOOTLOADER_LOG_LEVEL=3 # CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V is not set CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y CONFIG_BOOTLOADER_FACTORY_RESET=y @@ -1225,13 +1225,13 @@ CONFIG_WPA_MBEDTLS_CRYPTO=y # Deprecated options for backward compatibility CONFIG_TOOLPREFIX="xtensa-esp32-elf-" -CONFIG_LOG_BOOTLOADER_LEVEL_NONE=y +# CONFIG_LOG_BOOTLOADER_LEVEL_NONE is not set # CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set # CONFIG_LOG_BOOTLOADER_LEVEL_WARN is not set -# CONFIG_LOG_BOOTLOADER_LEVEL_INFO is not set +CONFIG_LOG_BOOTLOADER_LEVEL_INFO=y # CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set # CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set -CONFIG_LOG_BOOTLOADER_LEVEL=0 +CONFIG_LOG_BOOTLOADER_LEVEL=3 # CONFIG_APP_ROLLBACK_ENABLE is not set # CONFIG_FLASH_ENCRYPTION_ENABLED is not set # CONFIG_FLASHMODE_QIO is not set