From b32359b4e666b93d00386c15d7b1b33bb1b97f43 Mon Sep 17 00:00:00 2001 From: KisChang <734615869@qq.com> Date: Fri, 31 Mar 2023 14:46:12 +0800 Subject: [PATCH 01/12] add Define GC heap --- standalone.ld | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/standalone.ld b/standalone.ld index 040f6ad..69bd929 100644 --- a/standalone.ld +++ b/standalone.ld @@ -223,11 +223,18 @@ SECTIONS __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); __StackBottom = __StackTop - SIZEOF(.stack_dummy); + /* Define start and end of GC heap */ + __GcHeapStart = __bss_end__; + __GcHeapEnd = __StackLimit; PROVIDE(__stack = __StackTop); /* Check if data + heap + stack exceeds RAM limit */ ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") + /* Check GC heap is at least 128 KB */ + /* On a RP2040 using all SRAM this should always be the case. */ + ASSERT((__GcHeapEnd - __GcHeapStart) > 128*1024, "GcHeap is too small") + ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") /* todo assert on extra code */ } From b5351a31d9f156e8ba2043e83c41d7ab78f0d2e5 Mon Sep 17 00:00:00 2001 From: KisChang <734615869@qq.com> Date: Sun, 2 Apr 2023 18:05:13 +0800 Subject: [PATCH 02/12] add some file, can use picowota_reboot on MicroPython usermod And don't change source --- picowota_reboot/micropython.cmake | 16 ++++++++++++++++ picowota_reboot/micropython.mk | 9 +++++++++ picowota_reboot/reboot_mp.c | 32 +++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 picowota_reboot/micropython.cmake create mode 100644 picowota_reboot/micropython.mk create mode 100644 picowota_reboot/reboot_mp.c diff --git a/picowota_reboot/micropython.cmake b/picowota_reboot/micropython.cmake new file mode 100644 index 0000000..3b90b26 --- /dev/null +++ b/picowota_reboot/micropython.cmake @@ -0,0 +1,16 @@ +# Create an INTERFACE library for our C module. +add_library(usermod_picowotareboot INTERFACE) + +# Add our source files to the lib +target_sources(usermod_picowotareboot INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/reboot.c + ${CMAKE_CURRENT_LIST_DIR}/reboot_mp.c +) + +# Add the current directory as an include directory. +target_include_directories(usermod_picowotareboot INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/include +) + +# Link our INTERFACE library to the usermod target. +target_link_libraries(usermod INTERFACE usermod_picowotareboot) \ No newline at end of file diff --git a/picowota_reboot/micropython.mk b/picowota_reboot/micropython.mk new file mode 100644 index 0000000..94617bd --- /dev/null +++ b/picowota_reboot/micropython.mk @@ -0,0 +1,9 @@ +EXAMPLE_MOD_DIR := $(USERMOD_DIR) + +# Add all C files to SRC_USERMOD. +SRC_USERMOD += $(EXAMPLE_MOD_DIR)/reboot.c + +# We can add our module folder to include paths if needed +# This is not actually needed in this example. +CFLAGS_USERMOD += -I$(EXAMPLE_MOD_DIR) +CEXAMPLE_MOD_DIR := $(USERMOD_DIR) diff --git a/picowota_reboot/reboot_mp.c b/picowota_reboot/reboot_mp.c new file mode 100644 index 0000000..41ec198 --- /dev/null +++ b/picowota_reboot/reboot_mp.c @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2023 KisChang + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#include "py/runtime.h" +#include "py/obj.h" + +#include "picowota/reboot.h" + +STATIC mp_obj_t mp_picowota_reboot(mp_obj_t arg_obj) { + bool arg = mp_obj_is_true(arg_obj); + picowota_reboot(arg); + return mp_obj_new_int(1); +} + +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_picowota_reboot_obj, mp_picowota_reboot); + +STATIC const mp_rom_map_elem_t example_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_picowota_reboot) }, + { MP_ROM_QSTR(MP_QSTR_reboot), MP_ROM_PTR(&mp_picowota_reboot_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(example_module_globals, example_module_globals_table); + +// Define module object. +const mp_obj_module_t user_cmodule = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&example_module_globals, +}; + +// Register the module to make it available in Python. +MP_REGISTER_MODULE(MP_QSTR_picowota_reboot, user_cmodule); From 73317cb8f2708ad206bfcf29a14f1c127e559c8d Mon Sep 17 00:00:00 2001 From: KisChang <734615869@qq.com> Date: Sun, 2 Apr 2023 18:58:46 +0800 Subject: [PATCH 03/12] Update micropython.mk fix .mk issue --- picowota_reboot/micropython.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/picowota_reboot/micropython.mk b/picowota_reboot/micropython.mk index 94617bd..d4ad880 100644 --- a/picowota_reboot/micropython.mk +++ b/picowota_reboot/micropython.mk @@ -2,6 +2,7 @@ EXAMPLE_MOD_DIR := $(USERMOD_DIR) # Add all C files to SRC_USERMOD. SRC_USERMOD += $(EXAMPLE_MOD_DIR)/reboot.c +SRC_USERMOD += $(EXAMPLE_MOD_DIR)/reboot_mp.c # We can add our module folder to include paths if needed # This is not actually needed in this example. From dce2af2d2fecc94da11faf577213c4881cc43d3d Mon Sep 17 00:00:00 2001 From: KisChang <734615869@qq.com> Date: Fri, 31 Mar 2023 15:01:28 +0800 Subject: [PATCH 04/12] add CMake variables BOOTLOADER_ENTRY_PIN --- CMakeLists.txt | 5 +++++ README.md | 1 + main.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8af9907..89e107b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,11 @@ if (PICOWOTA_WIFI_AP) message("Building in WiFi AP mode.") endif() +if (BOOTLOADER_ENTRY_PIN) + target_compile_definitions(picowota PUBLIC BOOTLOADER_ENTRY_PIN=${BOOTLOADER_ENTRY_PIN}) + message("Building with BOOTLOADER_ENTRY_PIN.") +endif() + # Provide a helper to build a standalone target function(picowota_build_standalone NAME) get_target_property(PICOWOTA_SRC_DIR picowota SOURCE_DIR) diff --git a/README.md b/README.md index f8e51ba..167b1de 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ as CMake variables: PICOWOTA_WIFI_SSID # The WiFi network SSID PICOWOTA_WIFI_PASS # The WiFi network password PICOWOTA_WIFI_AP # Optional; 0 = connect to the network, 1 = create it +BOOTLOADER_ENTRY_PIN # Optional; default use pin 15, you can change it ``` Then, you can either build just your standalone app binary (suitable for diff --git a/main.c b/main.c index 8223c63..06b139a 100644 --- a/main.c +++ b/main.c @@ -83,7 +83,10 @@ struct event { }; }; +#ifndef BOOTLOADER_ENTRY_PIN +#warning "BOOTLOADER_ENTRY_PIN not defined" #define BOOTLOADER_ENTRY_PIN 15 +#endif #define TCP_PORT 4242 From 3bb86e089be4ecea9105761d0741372c5afbaf6c Mon Sep 17 00:00:00 2001 From: KisChang <734615869@qq.com> Date: Mon, 3 Apr 2023 10:33:43 +0800 Subject: [PATCH 05/12] change BOOTLOADER_ENTRY_PIN to PICOWOTA_ENTRY_PIN --- CMakeLists.txt | 7 ++++--- README.md | 2 +- main.c | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89e107b..3076673 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,7 @@ endfunction() picowota_retrieve_variable(PICOWOTA_WIFI_SSID false) picowota_retrieve_variable(PICOWOTA_WIFI_PASS true) picowota_retrieve_variable(PICOWOTA_WIFI_AP false) +picowota_retrieve_variable(PICOWOTA_ENTRY_PIN false) if ((NOT PICOWOTA_WIFI_SSID) OR (NOT PICOWOTA_WIFI_PASS)) message(FATAL_ERROR @@ -107,9 +108,9 @@ if (PICOWOTA_WIFI_AP) message("Building in WiFi AP mode.") endif() -if (BOOTLOADER_ENTRY_PIN) - target_compile_definitions(picowota PUBLIC BOOTLOADER_ENTRY_PIN=${BOOTLOADER_ENTRY_PIN}) - message("Building with BOOTLOADER_ENTRY_PIN.") +if (PICOWOTA_ENTRY_PIN) + target_compile_definitions(picowota PUBLIC PICOWOTA_ENTRY_PIN=${PICOWOTA_ENTRY_PIN}) + message("Building with custom PICOWOTA_ENTRY_PIN.") endif() # Provide a helper to build a standalone target diff --git a/README.md b/README.md index 167b1de..6533060 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ as CMake variables: PICOWOTA_WIFI_SSID # The WiFi network SSID PICOWOTA_WIFI_PASS # The WiFi network password PICOWOTA_WIFI_AP # Optional; 0 = connect to the network, 1 = create it -BOOTLOADER_ENTRY_PIN # Optional; default use pin 15, you can change it +PICOWOTA_ENTRY_PIN # Optional; default use pin 15, you can change it ``` Then, you can either build just your standalone app binary (suitable for diff --git a/main.c b/main.c index 06b139a..60373a5 100644 --- a/main.c +++ b/main.c @@ -83,9 +83,10 @@ struct event { }; }; -#ifndef BOOTLOADER_ENTRY_PIN -#warning "BOOTLOADER_ENTRY_PIN not defined" +#ifndef PICOWOTA_ENTRY_PIN #define BOOTLOADER_ENTRY_PIN 15 +#else +#define BOOTLOADER_ENTRY_PIN PICOWOTA_ENTRY_PIN #endif #define TCP_PORT 4242 From 616342e7ec918d87d858ad823bc3dd2254333649 Mon Sep 17 00:00:00 2001 From: KisChang <734615869@qq.com> Date: Sat, 10 Jun 2023 10:19:34 +0800 Subject: [PATCH 06/12] Update main.c not in bootloader add return 0 --- main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/main.c b/main.c index 60373a5..97a98af 100644 --- a/main.c +++ b/main.c @@ -591,6 +591,7 @@ int main() disable_interrupts(); reset_peripherals(); jump_to_vtor(vtor); + return 0; } DBG_PRINTF_INIT(); From a57bfee704785e92af4e8a500020c92ba1a7569a Mon Sep 17 00:00:00 2001 From: KisChang <734615869@qq.com> Date: Sat, 17 Jun 2023 13:57:08 +0800 Subject: [PATCH 07/12] test auto reset --- CMakeLists.txt | 1 + main.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3076673..bde939d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,7 @@ target_link_libraries(picowota hardware_structs pico_cyw43_arch_lwip_poll pico_stdlib + pico_multicore pico_sync pico_util picowota_reboot diff --git a/main.c b/main.c index 97a98af..abd26e2 100644 --- a/main.c +++ b/main.c @@ -25,6 +25,7 @@ #include "pico/stdlib.h" #include "pico/cyw43_arch.h" +#include "pico/multicore.h" #include "tcp_comm.h" @@ -576,6 +577,14 @@ static void network_deinit() cyw43_arch_deinit(); } +void core1_entry() +{ + // timout 10 minutes + sleep_ms(1000 * 60 * 1); + //auto reset + watchdog_reboot(0, SRAM_END, 0); +} + int main() { err_t err; @@ -626,7 +635,9 @@ int main() } #endif - critical_section_init(&critical_section); + multicore_launch_core1(core1_entry); + + critical_section_init(&critical_section); const struct comm_command *cmds[] = { &sync_cmd, From 102102446cdf8b49f357befd3df4ff9573ceaa8e Mon Sep 17 00:00:00 2001 From: KisChang <734615869@qq.com> Date: Sat, 17 Jun 2023 14:14:25 +0800 Subject: [PATCH 08/12] add PICOWOTA_ENTRY_AUTORE --- CMakeLists.txt | 7 +++++++ main.c | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bde939d..2dddcec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,7 @@ picowota_retrieve_variable(PICOWOTA_WIFI_SSID false) picowota_retrieve_variable(PICOWOTA_WIFI_PASS true) picowota_retrieve_variable(PICOWOTA_WIFI_AP false) picowota_retrieve_variable(PICOWOTA_ENTRY_PIN false) +picowota_retrieve_variable(PICOWOTA_ENTRY_AUTORE false) if ((NOT PICOWOTA_WIFI_SSID) OR (NOT PICOWOTA_WIFI_PASS)) message(FATAL_ERROR @@ -109,6 +110,12 @@ if (PICOWOTA_WIFI_AP) message("Building in WiFi AP mode.") endif() +# Use the WiFi AP mode upon request +if (PICOWOTA_ENTRY_AUTORE) + target_compile_definitions(picowota PUBLIC PICOWOTA_ENTRY_AUTORE=1) + message("Building with ota mode timeout auto reset.") +endif() + if (PICOWOTA_ENTRY_PIN) target_compile_definitions(picowota PUBLIC PICOWOTA_ENTRY_PIN=${PICOWOTA_ENTRY_PIN}) message("Building with custom PICOWOTA_ENTRY_PIN.") diff --git a/main.c b/main.c index abd26e2..2c525ef 100644 --- a/main.c +++ b/main.c @@ -25,7 +25,9 @@ #include "pico/stdlib.h" #include "pico/cyw43_arch.h" +#if PICOWOTA_ENTRY_AUTORE == 1 #include "pico/multicore.h" +#endif #include "tcp_comm.h" @@ -577,13 +579,15 @@ static void network_deinit() cyw43_arch_deinit(); } +#if PICOWOTA_ENTRY_AUTORE == 1 void core1_entry() { - // timout 10 minutes - sleep_ms(1000 * 60 * 1); + // timout 5 minutes + sleep_ms(1000 * 60 * 5); //auto reset watchdog_reboot(0, SRAM_END, 0); } +#endif int main() { @@ -635,7 +639,9 @@ int main() } #endif +#if PICOWOTA_ENTRY_AUTORE == 1 multicore_launch_core1(core1_entry); +#endif critical_section_init(&critical_section); From b1c375d6f1b0502361a4baaec7ce3585f99bc4d7 Mon Sep 17 00:00:00 2001 From: KisChang <734615869@qq.com> Date: Sat, 17 Jun 2023 14:19:02 +0800 Subject: [PATCH 09/12] reset to reboot --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 2c525ef..405946a 100644 --- a/main.c +++ b/main.c @@ -584,8 +584,8 @@ void core1_entry() { // timout 5 minutes sleep_ms(1000 * 60 * 5); - //auto reset - watchdog_reboot(0, SRAM_END, 0); + //auto reset(to bootloader) + picowota_reboot(true); } #endif From 3c9f80122eca8465f3dd0b18f1dc12ac87eea186 Mon Sep 17 00:00:00 2001 From: KisChang <734615869@qq.com> Date: Tue, 29 Jul 2025 11:47:40 +0800 Subject: [PATCH 10/12] test build --- CMakeLists.txt | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dddcec..0b493db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,16 +174,16 @@ function(picowota_build_combined NAME) COMMAND ${CMAKE_OBJCOPY} -Obinary ${COMBINED}.elf ${COMBINED}.bin ) - if (NOT ELF2UF2_FOUND) - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PICO_SDK_PATH}/tools) - find_package(ELF2UF2) - endif() - if (ELF2UF2_FOUND) - add_custom_command(TARGET ${COMBINED} POST_BUILD - COMMAND ELF2UF2 ${COMBINED}.elf ${COMBINED}.uf2 - ) - list(APPEND clean_files ${COMBINED}.uf2) - endif() +# if (NOT ELF2UF2_FOUND) +# set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PICO_SDK_PATH}/tools) +# find_package(ELF2UF2) +# endif() +# if (ELF2UF2_FOUND) +# add_custom_command(TARGET ${COMBINED} POST_BUILD +# COMMAND ELF2UF2 ${COMBINED}.elf ${COMBINED}.uf2 +# ) +# list(APPEND clean_files ${COMBINED}.uf2) +# endif() set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${clean_files}") endfunction() From cc48a40f74c6764d2021b6302a41b7b4f403076b Mon Sep 17 00:00:00 2001 From: KisChang <734615869@qq.com> Date: Tue, 29 Jul 2025 16:36:08 +0800 Subject: [PATCH 11/12] fix static --- picowota_reboot/reboot_mp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/picowota_reboot/reboot_mp.c b/picowota_reboot/reboot_mp.c index 41ec198..75cf811 100644 --- a/picowota_reboot/reboot_mp.c +++ b/picowota_reboot/reboot_mp.c @@ -8,19 +8,19 @@ #include "picowota/reboot.h" -STATIC mp_obj_t mp_picowota_reboot(mp_obj_t arg_obj) { +static mp_obj_t mp_picowota_reboot(mp_obj_t arg_obj) { bool arg = mp_obj_is_true(arg_obj); picowota_reboot(arg); return mp_obj_new_int(1); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_picowota_reboot_obj, mp_picowota_reboot); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_picowota_reboot_obj, mp_picowota_reboot); -STATIC const mp_rom_map_elem_t example_module_globals_table[] = { +static const mp_rom_map_elem_t example_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_picowota_reboot) }, { MP_ROM_QSTR(MP_QSTR_reboot), MP_ROM_PTR(&mp_picowota_reboot_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(example_module_globals, example_module_globals_table); +static MP_DEFINE_CONST_DICT(example_module_globals, example_module_globals_table); // Define module object. const mp_obj_module_t user_cmodule = { From 2acc5ec72f1c2efc9d0991bfa870c3b6e2918d73 Mon Sep 17 00:00:00 2001 From: KisChang <734615869@qq.com> Date: Tue, 29 Jul 2025 19:24:22 +0800 Subject: [PATCH 12/12] test update disable_interrupts --- main.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 405946a..aed1584 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,7 @@ #include "hardware/resets.h" #include "hardware/uart.h" #include "hardware/watchdog.h" +#include "hardware/sync.h" #include "pico/stdlib.h" #include "pico/cyw43_arch.h" @@ -448,13 +449,13 @@ struct comm_command seal_cmd = { .handle = &handle_seal, }; -static void disable_interrupts(void) -{ - SysTick->CTRL &= ~1; - - NVIC->ICER[0] = 0xFFFFFFFF; - NVIC->ICPR[0] = 0xFFFFFFFF; -} +//static void disable_interrupts(void) +//{ +// SysTick->CTRL &= ~1; +// +// NVIC->ICER[0] = 0xFFFFFFFF; +// NVIC->ICPR[0] = 0xFFFFFFFF; +//} static void reset_peripherals(void) {