diff --git a/examples/stm32/nucleo-h563zi-make-baremetal-builtin/mongoose_custom.h b/examples/stm32/nucleo-h563zi-make-baremetal-builtin/mongoose_custom.h index 0a2df18d..09860117 100644 --- a/examples/stm32/nucleo-h563zi-make-baremetal-builtin/mongoose_custom.h +++ b/examples/stm32/nucleo-h563zi-make-baremetal-builtin/mongoose_custom.h @@ -2,11 +2,11 @@ #define MG_ARCH MG_ARCH_NEWLIB #define MG_OTA MG_OTA_FLASH +#define MG_SYS MG_SYS_STM32H5 #define MG_ENABLE_TCPIP 1 #define MG_ENABLE_CUSTOM_MILLIS 1 #define MG_ENABLE_CUSTOM_RANDOM 1 #define MG_ENABLE_PACKED_FS 1 #define MG_ENABLE_DRIVER_STM32H 1 -#define MG_ENABLE_STM32H5 1 #define MG_ENABLE_LINES 1 diff --git a/examples/stm32/nucleo-h743zi-make-baremetal-builtin/mongoose_custom.h b/examples/stm32/nucleo-h743zi-make-baremetal-builtin/mongoose_custom.h index 1316e8b1..c965bdca 100644 --- a/examples/stm32/nucleo-h743zi-make-baremetal-builtin/mongoose_custom.h +++ b/examples/stm32/nucleo-h743zi-make-baremetal-builtin/mongoose_custom.h @@ -2,11 +2,11 @@ #define MG_ARCH MG_ARCH_NEWLIB #define MG_OTA MG_OTA_FLASH +#define MG_SYS MG_SYS_STM32H7 #define MG_ENABLE_TCPIP 1 #define MG_ENABLE_CUSTOM_MILLIS 1 #define MG_ENABLE_CUSTOM_RANDOM 1 #define MG_ENABLE_PACKED_FS 1 #define MG_ENABLE_DRIVER_STM32H 1 -#define MG_ENABLE_STM32H7 1 #define MG_ENABLE_LINES 1 diff --git a/mongoose.c b/mongoose.c index 7b42365a..b1e451c6 100644 --- a/mongoose.c +++ b/mongoose.c @@ -4979,8 +4979,6 @@ size_t mg_ota_size(int fw) { (void) fw; return 0; } -void mg_sys_reset(void) { -} #endif #ifdef MG_ENABLE_LINES @@ -6844,6 +6842,42 @@ bool mg_path_is_sane(const char *path) { return true; } +#ifdef MG_ENABLE_LINES +#line 1 "src/sys_dummy.c" +#endif + + +#if MG_SYS == MG_SYS_NONE +void *mg_flash_start(void) { + return NULL; +} +size_t mg_flash_size(void) { + return 0; +} +size_t mg_flash_sector_size(void) { + return 0; +} +size_t mg_flash_write_align(void) { + return 0; +} +int mg_flash_bank(void) { + return 0; +} +bool mg_flash_erase(void *location) { + (void) location; + return false; +} +bool mg_flash_swap_bank(void) { + return true; +} +bool mg_flash_write(void *addr, const void *buf, size_t len) { + (void) addr, (void) buf, (void) len; + return false; +} +void mg_sys_reset(void) { +} +#endif + #ifdef MG_ENABLE_LINES #line 1 "src/sys_stm32h5.c" #endif @@ -6851,7 +6885,7 @@ bool mg_path_is_sane(const char *path) { -#if MG_ENABLE_STM32H5 +#if MG_SYS == MG_SYS_STM32H5 #define FLASH_BASE 0x40022000 // Base address of the flash controller #define FLASH_KEYR (FLASH_BASE + 0x4) // See RM0481 7.11 @@ -6998,7 +7032,7 @@ void mg_sys_reset(void) { -#if MG_ENABLE_STM32H7 +#if MG_SYS == MG_SYS_STM32H7 #define FLASH_BASE1 0x52002000 // Base address for bank1 #define FLASH_BASE2 0x52002100 // Base address for bank2 diff --git a/mongoose.h b/mongoose.h index 354d8d02..31aed55c 100644 --- a/mongoose.h +++ b/mongoose.h @@ -815,14 +815,6 @@ struct timeval { #define MG_EPOLL_MOD(c, wr) #endif -#ifndef MG_ENABLE_STM32H5 -#define MG_ENABLE_STM32H5 0 -#endif - -#ifndef MG_ENABLE_STM32H7 -#define MG_ENABLE_STM32H7 0 -#endif - @@ -1702,13 +1694,20 @@ size_t mg_ota_size(int firmware); // Firmware size bool mg_ota_commit(void); // Commit current firmware bool mg_ota_rollback(void); // Rollback to the previous firmware - -void mg_sys_reset(void); // Reboot device immediately // Copyright (c) 2023 Cesanta Software Limited // All rights reserved +#define MG_SYS_NONE 0 // Dummy system +#define MG_SYS_STM32H5 1 // STM32 H5 +#define MG_SYS_STM32H7 2 // STM32 H7 +#define MG_SYS_CUSTOM 100 // Custom implementation + +#ifndef MG_SYS +#define MG_SYS MG_SYS_NONE +#endif + // Flash information void *mg_flash_start(void); // Return flash start address size_t mg_flash_size(void); // Return flash size @@ -1726,6 +1725,8 @@ bool mg_flash_swap_bank(void); bool mg_flash_load(void *sector, uint32_t key, void *buf, size_t len); bool mg_flash_save(void *sector, uint32_t key, const void *buf, size_t len); +void mg_sys_reset(void); // Reboot device immediately + diff --git a/src/config.h b/src/config.h index 7314105f..f69da657 100644 --- a/src/config.h +++ b/src/config.h @@ -149,11 +149,3 @@ #define MG_EPOLL_ADD(c) #define MG_EPOLL_MOD(c, wr) #endif - -#ifndef MG_ENABLE_STM32H5 -#define MG_ENABLE_STM32H5 0 -#endif - -#ifndef MG_ENABLE_STM32H7 -#define MG_ENABLE_STM32H7 0 -#endif diff --git a/src/ota.h b/src/ota.h index 3a979e12..a39c79bf 100644 --- a/src/ota.h +++ b/src/ota.h @@ -33,5 +33,3 @@ size_t mg_ota_size(int firmware); // Firmware size bool mg_ota_commit(void); // Commit current firmware bool mg_ota_rollback(void); // Rollback to the previous firmware - -void mg_sys_reset(void); // Reboot device immediately diff --git a/src/ota_dummy.c b/src/ota_dummy.c index 25b81831..6aa106a3 100644 --- a/src/ota_dummy.c +++ b/src/ota_dummy.c @@ -35,6 +35,4 @@ size_t mg_ota_size(int fw) { (void) fw; return 0; } -void mg_sys_reset(void) { -} #endif diff --git a/src/sys.h b/src/sys.h index 94897220..457fccff 100644 --- a/src/sys.h +++ b/src/sys.h @@ -3,6 +3,15 @@ #pragma once +#define MG_SYS_NONE 0 // Dummy system +#define MG_SYS_STM32H5 1 // STM32 H5 +#define MG_SYS_STM32H7 2 // STM32 H7 +#define MG_SYS_CUSTOM 100 // Custom implementation + +#ifndef MG_SYS +#define MG_SYS MG_SYS_NONE +#endif + // Flash information void *mg_flash_start(void); // Return flash start address size_t mg_flash_size(void); // Return flash size @@ -19,3 +28,5 @@ bool mg_flash_swap_bank(void); // If `sector` is NULL, then the last sector of flash is used bool mg_flash_load(void *sector, uint32_t key, void *buf, size_t len); bool mg_flash_save(void *sector, uint32_t key, const void *buf, size_t len); + +void mg_sys_reset(void); // Reboot device immediately diff --git a/src/sys_dummy.c b/src/sys_dummy.c new file mode 100644 index 00000000..80834e6e --- /dev/null +++ b/src/sys_dummy.c @@ -0,0 +1,32 @@ +#include "sys.h" + +#if MG_SYS == MG_SYS_NONE +void *mg_flash_start(void) { + return NULL; +} +size_t mg_flash_size(void) { + return 0; +} +size_t mg_flash_sector_size(void) { + return 0; +} +size_t mg_flash_write_align(void) { + return 0; +} +int mg_flash_bank(void) { + return 0; +} +bool mg_flash_erase(void *location) { + (void) location; + return false; +} +bool mg_flash_swap_bank(void) { + return true; +} +bool mg_flash_write(void *addr, const void *buf, size_t len) { + (void) addr, (void) buf, (void) len; + return false; +} +void mg_sys_reset(void) { +} +#endif diff --git a/src/sys_stm32h5.c b/src/sys_stm32h5.c index 63185338..f9f9ee7b 100644 --- a/src/sys_stm32h5.c +++ b/src/sys_stm32h5.c @@ -2,7 +2,7 @@ #include "log.h" #include "ota.h" -#if MG_ENABLE_STM32H5 +#if MG_SYS == MG_SYS_STM32H5 #define FLASH_BASE 0x40022000 // Base address of the flash controller #define FLASH_KEYR (FLASH_BASE + 0x4) // See RM0481 7.11 diff --git a/src/sys_stm32h7.c b/src/sys_stm32h7.c index 1bdc585a..3566dcb4 100644 --- a/src/sys_stm32h7.c +++ b/src/sys_stm32h7.c @@ -2,7 +2,7 @@ #include "log.h" #include "ota.h" -#if MG_ENABLE_STM32H7 +#if MG_SYS == MG_SYS_STM32H7 #define FLASH_BASE1 0x52002000 // Base address for bank1 #define FLASH_BASE2 0x52002100 // Base address for bank2