From 658a1f7b3e5069cd74e84e4cecea7aa9271666f1 Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Sat, 15 Feb 2025 16:06:10 +0100 Subject: [PATCH 01/10] Fix STM32WL TCXO setting; enable logs and modules (#6063) Co-authored-by: Ben Meadors --- arch/stm32/stm32.ini | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/stm32/stm32.ini b/arch/stm32/stm32.ini index 5066b5c0c..e8042bc53 100644 --- a/arch/stm32/stm32.ini +++ b/arch/stm32/stm32.ini @@ -9,7 +9,7 @@ build_type = release ;board_build.flash_offset = 0x08000000 -build_flags = +build_flags = ${arduino_base.build_flags} -Wl,--undefined=vTaskSwitchContext -flto @@ -23,14 +23,12 @@ build_flags = -DMESHTASTIC_EXCLUDE_BLUETOOTH -DMESHTASTIC_EXCLUDE_PKI -DMESHTASTIC_EXCLUDE_GPS -; -DVECT_TAB_OFFSET=0x08000000 -DconfigUSE_CMSIS_RTOS_V2=1 -; -DSPI_MODE_0=SPI_MODE0 -fmerge-all-constants -ffunction-sections -fdata-sections - -build_src_filter = + +build_src_filter = ${arduino_base.build_src_filter} - - - - - - - - - - - - - - board_upload.offset_address = 0x08000000 From 2f6f786f7317f12af22b65c4386b5972c2bdb6ce Mon Sep 17 00:00:00 2001 From: Daniel Peter Chokola Date: Thu, 6 Feb 2025 03:27:38 -0500 Subject: [PATCH 02/10] guard against including I2C inputs when MESHTASTIC_EXCLUDE_I2C is set --- src/modules/Modules.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/Modules.cpp b/src/modules/Modules.cpp index f386147d0..e2a4a970c 100644 --- a/src/modules/Modules.cpp +++ b/src/modules/Modules.cpp @@ -7,7 +7,9 @@ #include "input/SerialKeyboardImpl.h" #include "input/TrackballInterruptImpl1.h" #include "input/UpDownInterruptImpl1.h" +#if !MESHTASTIC_EXCLUDE_I2C #include "input/cardKbI2cImpl.h" +#endif #include "input/kbMatrixImpl.h" #endif #if !MESHTASTIC_EXCLUDE_ADMIN From f60ccc545d0fe42c679c6947f87758a7ca35f1eb Mon Sep 17 00:00:00 2001 From: Daniel Peter Chokola Date: Thu, 6 Feb 2025 03:30:58 -0500 Subject: [PATCH 03/10] correctly translate memory address/block from LFS to STM32 HAL Reading and writing FLASH works! --- src/platform/stm32wl/LittleFS.cpp | 183 +++++++++++++------------- src/platform/stm32wl/STM32_LittleFS.h | 2 +- 2 files changed, 89 insertions(+), 96 deletions(-) diff --git a/src/platform/stm32wl/LittleFS.cpp b/src/platform/stm32wl/LittleFS.cpp index e23470799..1f2bcc8f2 100644 --- a/src/platform/stm32wl/LittleFS.cpp +++ b/src/platform/stm32wl/LittleFS.cpp @@ -23,41 +23,46 @@ */ #include "LittleFS.h" +#include "stm32wlxx_hal_flash.h" /********************************************************************************************************************** * Macro definitions **********************************************************************************************************************/ /** This macro is used to suppress compiler messages about a parameter not being used in a function. */ -#define PARAMETER_NOT_USED(p) (void)((p)) +#define LFS_UNUSED(p) (void)((p)) -#define STM32WL_SECTOR_SIZE 0x800 /* 2K */ -#define STM32WL_SECTOR_COUNT 14 +#define STM32WL_PAGE_SIZE (FLASH_PAGE_SIZE) +#define STM32WL_PAGE_COUNT (FLASH_PAGE_NB) +#define STM32WL_FLASH_BASE (FLASH_BASE) -#define LFS_FLASH_TOTAL_SIZE (STM32WL_SECTOR_COUNT * STM32WL_SECTOR_SIZE) -#define LFS_BLOCK_SIZE 128 +/* FLASH_SIZE from stm32wle5xx.h will read the actual FLASH size from the chip */ +/* use the last 1/4 of the FLASH */ +#define LFS_FLASH_TOTAL_SIZE (FLASH_SIZE / 4) +#define LFS_BLOCK_SIZE (128) +#define LFS_FLASH_ADDR_END (FLASH_END_ADDR) +#define LFS_FLASH_ADDR_BASE (LFS_FLASH_ADDR_END - (FLASH_SIZE / 4) + 1) -#define LFS_FLASH_ADDR (262144 - LFS_FLASH_TOTAL_SIZE) +#if !CFG_DEBUG +#define _LFS_DBG(fmt, ...) +#else +#define _LFS_DBG(fmt, ...) printf("%s:%d (%s): " fmt "\n", __FILE__, __LINE__, __func__, __VA_ARGS__) +#endif //--------------------------------------------------------------------+ // LFS Disk IO //--------------------------------------------------------------------+ -static inline uint32_t lba2addr(uint32_t block) -{ - return ((uint32_t)LFS_FLASH_ADDR) + block * LFS_BLOCK_SIZE; -} - static int _internal_flash_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) { - PARAMETER_NOT_USED(c); + LFS_UNUSED(c); + if (!buffer || !size) { - printf("%s Invalid parameter!\r\n", __func__); + _LFS_DBG("%s Invalid parameter!\r\n", __func__); return LFS_ERR_INVAL; } - lfs_block_t address = LFS_FLASH_ADDR + (block * STM32WL_SECTOR_SIZE + off); - // printf("+%s(Addr 0x%06lX, Len 0x%04lX)\r\n",__func__,address,size); - // hexdump((void *)address,size); + lfs_block_t address = LFS_FLASH_ADDR_BASE + (block * STM32WL_PAGE_SIZE + off); + memcpy(buffer, (void *)address, size); return LFS_ERR_OK; @@ -68,38 +73,38 @@ static int _internal_flash_read(const struct lfs_config *c, lfs_block_t block, l // May return LFS_ERR_CORRUPT if the block should be considered bad. static int _internal_flash_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) { - // (void) c; - - // uint32_t addr = lba2addr(block) + off; - // VERIFY( flash_nrf5x_write(addr, buffer, size), -1) - - // return 0; - PARAMETER_NOT_USED(c); - lfs_block_t address = LFS_FLASH_ADDR + (block * STM32WL_SECTOR_SIZE + off); + lfs_block_t address = LFS_FLASH_ADDR_BASE + (block * STM32WL_PAGE_SIZE + off); HAL_StatusTypeDef hal_rc = HAL_OK; uint32_t block_count = size / 8; + uint64_t *bufp = (uint64_t *) buffer; - // printf("+%s(Addr 0x%06lX, Len 0x%04lX)\r\n",__func__,address,size); - // hexdump((void *)address,size); - /* Program the user Flash area word by word - (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/ - - uint64_t data_source; + LFS_UNUSED(c); + if(HAL_FLASH_Unlock() != HAL_OK) + { + return LFS_ERR_IO; + } for (uint32_t i = 0; i < block_count; i++) { - memcpy(&data_source, buffer, 8); // load the 64-bit source from the buffer - hal_rc = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, data_source); - if (hal_rc == HAL_OK) { - address += 8; - buffer = (uint8_t *)buffer + 8; - } else { + if((address < LFS_FLASH_ADDR_BASE) || (address > LFS_FLASH_ADDR_END)) + { + _LFS_DBG("Wanted to program out of bound of FLASH: 0x%08x.\n", address); + HAL_FLASH_Lock(); + return LFS_ERR_INVAL; + } + hal_rc = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, *bufp); + if (hal_rc != HAL_OK) { /* Error occurred while writing data in Flash memory. - User can add here some code to deal with this error */ - printf("Program Error, 0x%X\n", hal_rc); - - } // else - } // for - // printf("-%s\n",__func__); + * User can add here some code to deal with this error. + */ + _LFS_DBG("Program error at (0x%08x), 0x%X, error: 0x%08x\n", address, hal_rc, HAL_FLASH_GetError()); + } + address += 8; + bufp += 8; + } + if(HAL_FLASH_Lock() != HAL_OK) + { + return LFS_ERR_IO; + } return hal_rc == HAL_OK ? LFS_ERR_OK : LFS_ERR_IO; // If HAL_OK, return LFS_ERR_OK, else return LFS_ERR_IO } @@ -110,38 +115,28 @@ static int _internal_flash_prog(const struct lfs_config *c, lfs_block_t block, l // May return LFS_ERR_CORRUPT if the block should be considered bad. static int _internal_flash_erase(const struct lfs_config *c, lfs_block_t block) { - // (void) c; - - // uint32_t addr = lba2addr(block); - - // // implement as write 0xff to whole block address - // for(int i=0; i LFS_FLASH_ADDR_END)) + { + _LFS_DBG("Wanted to erase out of bound of FLASH: 0x%08x.\n", address); + return LFS_ERR_INVAL; + } + /* calculate the absolute page, i.e. what the ST wants */ + EraseInitStruct.Page = (address - STM32WL_FLASH_BASE) / STM32WL_PAGE_SIZE; + _LFS_DBG("Erasing block %d at 0x%08x... ", block, address); + HAL_FLASH_Unlock(); + hal_rc = HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError); + HAL_FLASH_Lock(); return hal_rc == HAL_OK ? LFS_ERR_OK : LFS_ERR_IO; // If HAL_OK, return LFS_ERR_OK, else return LFS_ERR_IO } @@ -150,33 +145,31 @@ static int _internal_flash_erase(const struct lfs_config *c, lfs_block_t block) // are propogated to the user. static int _internal_flash_sync(const struct lfs_config *c) { - // (void) c; - // flash_nrf5x_flush(); - // return 0; - PARAMETER_NOT_USED(c); + LFS_UNUSED(c); // write function performs no caching. No need for sync. - // printf("+%s()\r\n",__func__); + return LFS_ERR_OK; - // return LFS_ERR_IO; } -static struct lfs_config _InternalFSConfig = {.context = NULL, +static struct lfs_config _InternalFSConfig = { + .context = NULL, - .read = _internal_flash_read, - .prog = _internal_flash_prog, - .erase = _internal_flash_erase, - .sync = _internal_flash_sync, + .read = _internal_flash_read, + .prog = _internal_flash_prog, + .erase = _internal_flash_erase, + .sync = _internal_flash_sync, - .read_size = LFS_BLOCK_SIZE, - .prog_size = LFS_BLOCK_SIZE, - .block_size = LFS_BLOCK_SIZE, - .block_count = LFS_FLASH_TOTAL_SIZE / LFS_BLOCK_SIZE, - .lookahead = 128, + .read_size = LFS_BLOCK_SIZE, + .prog_size = LFS_BLOCK_SIZE, + .block_size = LFS_BLOCK_SIZE, + .block_count = LFS_FLASH_TOTAL_SIZE / LFS_BLOCK_SIZE, + .lookahead = 128, - .read_buffer = NULL, - .prog_buffer = NULL, - .lookahead_buffer = NULL, - .file_buffer = NULL}; + .read_buffer = NULL, + .prog_buffer = NULL, + .lookahead_buffer = NULL, + .file_buffer = NULL +}; LittleFS InternalFS; @@ -188,11 +181,11 @@ LittleFS::LittleFS(void) : STM32_LittleFS(&_InternalFSConfig) {} bool LittleFS::begin(void) { - // failed to mount, erase all sector then format and mount again + // failed to mount, erase all pages then format and mount again if (!STM32_LittleFS::begin()) { - // Erase all sectors of internal flash region for Filesystem. - for (uint32_t addr = LFS_FLASH_ADDR; addr < LFS_FLASH_ADDR + LFS_FLASH_TOTAL_SIZE; addr += STM32WL_SECTOR_SIZE) { - _internal_flash_erase(&_InternalFSConfig, (addr - LFS_FLASH_ADDR) / STM32WL_SECTOR_SIZE); + // Erase all pages of internal flash region for Filesystem. + for (uint32_t addr = LFS_FLASH_ADDR_BASE; addr < (LFS_FLASH_ADDR_END + 1); addr += STM32WL_PAGE_SIZE) { + _internal_flash_erase(&_InternalFSConfig, (addr - LFS_FLASH_ADDR_BASE) / STM32WL_PAGE_SIZE); } // lfs format diff --git a/src/platform/stm32wl/STM32_LittleFS.h b/src/platform/stm32wl/STM32_LittleFS.h index a6d897930..8aec8e7a5 100644 --- a/src/platform/stm32wl/STM32_LittleFS.h +++ b/src/platform/stm32wl/STM32_LittleFS.h @@ -97,7 +97,7 @@ class STM32_LittleFS #define PRINT_LFS_ERR(_err) \ do { \ if (_err) { \ - VERIFY_MESS((long int)_err, dbg_strerr_lfs); \ + printf("%s:%d, LFS error: %d\n", __FILE__, __LINE__, _err); \ } \ } while (0) // LFS_ERR are of type int, VERIFY_MESS expects long_int From 28bd8ec8809a3c5e943c238b822b8085fe16e0c9 Mon Sep 17 00:00:00 2001 From: Daniel Peter Chokola Date: Thu, 6 Feb 2025 03:34:02 -0500 Subject: [PATCH 04/10] STM32 build fits in available FLASH; re-enable hardware and modules on STM32 previously disabled --- arch/stm32/stm32.ini | 2 -- variants/wio-e5/platformio.ini | 35 +++++++++++----------------------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/arch/stm32/stm32.ini b/arch/stm32/stm32.ini index e8042bc53..14fe8ea93 100644 --- a/arch/stm32/stm32.ini +++ b/arch/stm32/stm32.ini @@ -7,8 +7,6 @@ extra_scripts = post:extra_scripts/extra_stm32.py build_type = release -;board_build.flash_offset = 0x08000000 - build_flags = ${arduino_base.build_flags} -Wl,--undefined=vTaskSwitchContext diff --git a/variants/wio-e5/platformio.ini b/variants/wio-e5/platformio.ini index d89f187dc..b91eb060d 100644 --- a/variants/wio-e5/platformio.ini +++ b/variants/wio-e5/platformio.ini @@ -1,7 +1,7 @@ [env:wio-e5] extends = stm32_base board = lora_e5_dev_board -board_upload.maximum_size = 233472 ; reserve the last 28KB for filesystem +board_upload.maximum_size = 233472 ; reserve the last 128KB for filesystem build_flags = ${stm32_base.build_flags} -Ivariants/wio-e5 @@ -9,31 +9,18 @@ build_flags = -DPIN_SERIAL_RX=PB7 -DPIN_SERIAL_TX=PB6 -DHAL_DAC_MODULE_ONLY - -DHAL_ADC_MODULE_DISABLED - -DHAL_COMP_MODULE_DISABLED - -DHAL_CRC_MODULE_DISABLED - -DHAL_CRYP_MODULE_DISABLED - -DHAL_GTZC_MODULE_DISABLED - -DHAL_HSEM_MODULE_DISABLED - -DHAL_I2C_MODULE_DISABLED - -DHAL_I2S_MODULE_DISABLED - -DHAL_IPCC_MODULE_DISABLED - -DHAL_IRDA_MODULE_DISABLED - -DHAL_IWDG_MODULE_DISABLED - -DHAL_LPTIM_MODULE_DISABLED - -DHAL_PKA_MODULE_DISABLED - -DHAL_RNG_MODULE_DISABLED - -DHAL_RTC_MODULE_DISABLED - -DHAL_SMARTCARD_MODULE_DISABLED - -DHAL_SMBUS_MODULE_DISABLED - -DHAL_TIM_MODULE_DISABLED - -DHAL_WWDG_MODULE_DISABLED - -DHAL_EXTI_MODULE_DISABLED - -DHAL_SAI_MODULE_DISABLED - -DHAL_ICACHE_MODULE_DISABLED + -DHAL_RNG_MODULE_ENABLED -DRADIOLIB_EXCLUDE_SX128X=1 -DRADIOLIB_EXCLUDE_SX127X=1 -DRADIOLIB_EXCLUDE_LR11X0=1 -; -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF + -DMESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR=1 + -DMESHTASTIC_EXCLUDE_I2C=1 + -DMESHTASTIC_EXCLUDE_WIFI=1 + -DMESHTASTIC_EXCLUDE_BLUETOOTH=1 + -DMESHTASTIC_EXCLUDE_GPS=1 + -DMESHTASTIC_EXCLUDE_SCREEN=1 + -DMESHTASTIC_EXCLUDE_MQTT=1 + -DMESHTASTIC_EXCLUDE_POWERMON=1 + -DPIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF upload_port = stlink \ No newline at end of file From f02628ad0aa3941d4961194c75122a28ccd475b5 Mon Sep 17 00:00:00 2001 From: Daniel Peter Chokola Date: Sun, 16 Feb 2025 15:49:30 -0500 Subject: [PATCH 05/10] correctly compute flash block sizes --- src/platform/stm32wl/LittleFS.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/platform/stm32wl/LittleFS.cpp b/src/platform/stm32wl/LittleFS.cpp index 1f2bcc8f2..f9e34ef20 100644 --- a/src/platform/stm32wl/LittleFS.cpp +++ b/src/platform/stm32wl/LittleFS.cpp @@ -37,10 +37,10 @@ /* FLASH_SIZE from stm32wle5xx.h will read the actual FLASH size from the chip */ /* use the last 1/4 of the FLASH */ -#define LFS_FLASH_TOTAL_SIZE (FLASH_SIZE / 4) -#define LFS_BLOCK_SIZE (128) +#define LFS_FLASH_TOTAL_SIZE (FLASH_SIZE / 8) +#define LFS_BLOCK_SIZE (2048) #define LFS_FLASH_ADDR_END (FLASH_END_ADDR) -#define LFS_FLASH_ADDR_BASE (LFS_FLASH_ADDR_END - (FLASH_SIZE / 4) + 1) +#define LFS_FLASH_ADDR_BASE (LFS_FLASH_ADDR_END - (FLASH_SIZE / 8) + 1) #if !CFG_DEBUG #define _LFS_DBG(fmt, ...) @@ -75,16 +75,17 @@ static int _internal_flash_prog(const struct lfs_config *c, lfs_block_t block, l { lfs_block_t address = LFS_FLASH_ADDR_BASE + (block * STM32WL_PAGE_SIZE + off); HAL_StatusTypeDef hal_rc = HAL_OK; - uint32_t block_count = size / 8; + uint32_t dw_count = size / 8; uint64_t *bufp = (uint64_t *) buffer; LFS_UNUSED(c); - if(HAL_FLASH_Unlock() != HAL_OK) + _LFS_DBG("Programming %d bytes/%d doublewords at address 0x%08x/block %d, offset %d.", size, dw_count, address, block, off); + if (HAL_FLASH_Unlock() != HAL_OK) { return LFS_ERR_IO; } - for (uint32_t i = 0; i < block_count; i++) { + for (uint32_t i = 0; i < dw_count; i++) { if((address < LFS_FLASH_ADDR_BASE) || (address > LFS_FLASH_ADDR_END)) { _LFS_DBG("Wanted to program out of bound of FLASH: 0x%08x.\n", address); @@ -99,7 +100,7 @@ static int _internal_flash_prog(const struct lfs_config *c, lfs_block_t block, l _LFS_DBG("Program error at (0x%08x), 0x%X, error: 0x%08x\n", address, hal_rc, HAL_FLASH_GetError()); } address += 8; - bufp += 8; + bufp += 1; } if(HAL_FLASH_Lock() != HAL_OK) { From 8455defa7a1014d99d2c0fa06e30bf54bbda0978 Mon Sep 17 00:00:00 2001 From: Daniel Peter Chokola Date: Sun, 16 Feb 2025 15:54:16 -0500 Subject: [PATCH 06/10] properly define Wio-E5 LED pin --- variants/wio-e5/variant.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/variants/wio-e5/variant.h b/variants/wio-e5/variant.h index ac92915bb..7795b0701 100644 --- a/variants/wio-e5/variant.h +++ b/variants/wio-e5/variant.h @@ -18,4 +18,9 @@ Do not expect a working Meshtastic device with this target. #define LED_PIN PB5 #define LED_STATE_ON 1 +#if (defined(LED_BUILTIN) && LED_BUILTIN == PNUM_NOT_DEFINED) +#undef LED_BUILTIN +#define LED_BUILTIN (LED_PIN) +#endif + #endif From 694f012dd0228d7567cfd30b2a0a3a742747e221 Mon Sep 17 00:00:00 2001 From: Daniel Peter Chokola Date: Sun, 16 Feb 2025 15:54:53 -0500 Subject: [PATCH 07/10] remove FreeRTOS dependency from STM32 build; disable debugging to preserve FLASH space LittleFS mutex routines are stubs and malloc()/free() are the stdlib versions --- arch/stm32/stm32.ini | 5 ++--- src/freertosinc.h | 2 +- src/platform/stm32wl/STM32_LittleFS.cpp | 1 - src/platform/stm32wl/STM32_LittleFS.h | 8 ++------ src/platform/stm32wl/littlefs/lfs_util.h | 6 ++---- variants/wio-e5/platformio.ini | 4 +++- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/arch/stm32/stm32.ini b/arch/stm32/stm32.ini index 14fe8ea93..d66abe3b7 100644 --- a/arch/stm32/stm32.ini +++ b/arch/stm32/stm32.ini @@ -9,7 +9,6 @@ build_type = release build_flags = ${arduino_base.build_flags} - -Wl,--undefined=vTaskSwitchContext -flto -Isrc/platform/stm32wl -g -DMESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR @@ -21,7 +20,7 @@ build_flags = -DMESHTASTIC_EXCLUDE_BLUETOOTH -DMESHTASTIC_EXCLUDE_PKI -DMESHTASTIC_EXCLUDE_GPS - -DconfigUSE_CMSIS_RTOS_V2=1 + -DDEBUG_MUTE -fmerge-all-constants -ffunction-sections -fdata-sections @@ -31,11 +30,11 @@ build_src_filter = board_upload.offset_address = 0x08000000 upload_protocol = stlink +debug_tool = stlink lib_deps = ${env.lib_deps} ${radiolib_base.lib_deps} - stm32duino/STM32duino FreeRTOS@^10.3.2 https://github.com/caveman99/Crypto.git#eae9c768054118a9399690f8af202853d1ae8516 lib_ignore = diff --git a/src/freertosinc.h b/src/freertosinc.h index aed6dd8f4..e9e6cd53a 100644 --- a/src/freertosinc.h +++ b/src/freertosinc.h @@ -12,7 +12,7 @@ #include #endif -#if defined(ARDUINO_NRF52_ADAFRUIT) || defined(ARDUINO_ARCH_RP2040) || defined(STM32WLE5xx) +#if defined(ARDUINO_NRF52_ADAFRUIT) || defined(ARDUINO_ARCH_RP2040) #define HAS_FREE_RTOS #include diff --git a/src/platform/stm32wl/STM32_LittleFS.cpp b/src/platform/stm32wl/STM32_LittleFS.cpp index a7f744129..97e79e61e 100644 --- a/src/platform/stm32wl/STM32_LittleFS.cpp +++ b/src/platform/stm32wl/STM32_LittleFS.cpp @@ -42,7 +42,6 @@ STM32_LittleFS::STM32_LittleFS(struct lfs_config *cfg) varclr(&_lfs); _lfs_cfg = cfg; _mounted = false; - _mutex = xSemaphoreCreateMutexStatic(&this->_MutexStorageSpace); } STM32_LittleFS::~STM32_LittleFS() {} diff --git a/src/platform/stm32wl/STM32_LittleFS.h b/src/platform/stm32wl/STM32_LittleFS.h index 8aec8e7a5..d05c0dcbc 100644 --- a/src/platform/stm32wl/STM32_LittleFS.h +++ b/src/platform/stm32wl/STM32_LittleFS.h @@ -76,17 +76,13 @@ class STM32_LittleFS * code. User should not call these directly *------------------------------------------------------------------*/ lfs_t *_getFS(void) { return &_lfs; } - void _lockFS(void) { xSemaphoreTake(_mutex, portMAX_DELAY); } - void _unlockFS(void) { xSemaphoreGive(_mutex); } + void _lockFS(void) { /* no-op */ } + void _unlockFS(void) { /* no-op */ } protected: bool _mounted; struct lfs_config *_lfs_cfg; lfs_t _lfs; - SemaphoreHandle_t _mutex; - - private: - StaticSemaphore_t _MutexStorageSpace; }; #if !CFG_DEBUG diff --git a/src/platform/stm32wl/littlefs/lfs_util.h b/src/platform/stm32wl/littlefs/lfs_util.h index ba84d6b5e..5c8469f88 100644 --- a/src/platform/stm32wl/littlefs/lfs_util.h +++ b/src/platform/stm32wl/littlefs/lfs_util.h @@ -174,8 +174,7 @@ void lfs_crc(uint32_t *crc, const void *buffer, size_t size); static inline void *lfs_malloc(size_t size) { #ifndef LFS_NO_MALLOC - extern void *pvPortMalloc(size_t xWantedSize); - return pvPortMalloc(size); + return malloc(size); #else (void)size; return NULL; @@ -186,8 +185,7 @@ static inline void *lfs_malloc(size_t size) static inline void lfs_free(void *p) { #ifndef LFS_NO_MALLOC - extern void vPortFree(void *pv); - vPortFree(p); + free(p); #else (void)p; #endif diff --git a/variants/wio-e5/platformio.ini b/variants/wio-e5/platformio.ini index b91eb060d..8f800a687 100644 --- a/variants/wio-e5/platformio.ini +++ b/variants/wio-e5/platformio.ini @@ -21,6 +21,8 @@ build_flags = -DMESHTASTIC_EXCLUDE_SCREEN=1 -DMESHTASTIC_EXCLUDE_MQTT=1 -DMESHTASTIC_EXCLUDE_POWERMON=1 - -DPIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF + -DMESHTASTIC_EXCLUDE_PKI + ;-DPIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF + ;-DCFG_DEBUG upload_port = stlink \ No newline at end of file From ef527fc22f52ab62d816b655e715f7ef4fe6271e Mon Sep 17 00:00:00 2001 From: Daniel Peter Chokola Date: Sun, 16 Feb 2025 16:08:27 -0500 Subject: [PATCH 08/10] enable encryption on STM32 platform --- arch/stm32/stm32.ini | 1 - variants/wio-e5/platformio.ini | 1 - 2 files changed, 2 deletions(-) diff --git a/arch/stm32/stm32.ini b/arch/stm32/stm32.ini index d66abe3b7..8f6354f5c 100644 --- a/arch/stm32/stm32.ini +++ b/arch/stm32/stm32.ini @@ -18,7 +18,6 @@ build_flags = -DMESHTASTIC_EXCLUDE_SCREEN -DMESHTASTIC_EXCLUDE_MQTT -DMESHTASTIC_EXCLUDE_BLUETOOTH - -DMESHTASTIC_EXCLUDE_PKI -DMESHTASTIC_EXCLUDE_GPS -DDEBUG_MUTE -fmerge-all-constants diff --git a/variants/wio-e5/platformio.ini b/variants/wio-e5/platformio.ini index 8f800a687..a00c804ce 100644 --- a/variants/wio-e5/platformio.ini +++ b/variants/wio-e5/platformio.ini @@ -21,7 +21,6 @@ build_flags = -DMESHTASTIC_EXCLUDE_SCREEN=1 -DMESHTASTIC_EXCLUDE_MQTT=1 -DMESHTASTIC_EXCLUDE_POWERMON=1 - -DMESHTASTIC_EXCLUDE_PKI ;-DPIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF ;-DCFG_DEBUG From 85989a13f9625f1c2bbc502c00980178f6841151 Mon Sep 17 00:00:00 2001 From: Daniel Peter Chokola Date: Sat, 22 Feb 2025 13:24:51 -0500 Subject: [PATCH 09/10] limit LittleFS on STM32 to 28 KiB add a runtime check for available space (probably overkill) --- src/platform/stm32wl/LittleFS.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/platform/stm32wl/LittleFS.cpp b/src/platform/stm32wl/LittleFS.cpp index f9e34ef20..f09f626f6 100644 --- a/src/platform/stm32wl/LittleFS.cpp +++ b/src/platform/stm32wl/LittleFS.cpp @@ -35,12 +35,15 @@ #define STM32WL_PAGE_COUNT (FLASH_PAGE_NB) #define STM32WL_FLASH_BASE (FLASH_BASE) -/* FLASH_SIZE from stm32wle5xx.h will read the actual FLASH size from the chip */ -/* use the last 1/4 of the FLASH */ -#define LFS_FLASH_TOTAL_SIZE (FLASH_SIZE / 8) +/* + * FLASH_SIZE from stm32wle5xx.h will read the actual FLASH size from the chip. + * FLASH_END_ADDR is calculated from FLASH_SIZE. + * Use the last 28 KiB of the FLASH + */ +#define LFS_FLASH_TOTAL_SIZE (14 * 2048) /* needs to be a multiple of LFS_BLOCK_SIZE */ #define LFS_BLOCK_SIZE (2048) #define LFS_FLASH_ADDR_END (FLASH_END_ADDR) -#define LFS_FLASH_ADDR_BASE (LFS_FLASH_ADDR_END - (FLASH_SIZE / 8) + 1) +#define LFS_FLASH_ADDR_BASE (LFS_FLASH_ADDR_END - LFS_FLASH_TOTAL_SIZE + 1) #if !CFG_DEBUG #define _LFS_DBG(fmt, ...) @@ -182,6 +185,11 @@ LittleFS::LittleFS(void) : STM32_LittleFS(&_InternalFSConfig) {} bool LittleFS::begin(void) { + if(FLASH_BASE >= LFS_FLASH_ADDR_BASE) + { + /* There is not enough space on this device for a filesystem. */ + return false; + } // failed to mount, erase all pages then format and mount again if (!STM32_LittleFS::begin()) { // Erase all pages of internal flash region for Filesystem. From 72d2191212410532320f36fd94390961394fcfe1 Mon Sep 17 00:00:00 2001 From: Daniel Peter Chokola Date: Tue, 25 Feb 2025 22:30:50 -0500 Subject: [PATCH 10/10] Implement reboot for STM32WL --- src/shutdown.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/shutdown.h b/src/shutdown.h index 9e30e772c..7229e7821 100644 --- a/src/shutdown.h +++ b/src/shutdown.h @@ -30,6 +30,8 @@ void powerCommandsCheck() delete screen; LOG_DEBUG("final reboot!"); reboot(); +#elif defined(ARCH_STM32WL) + HAL_NVIC_SystemReset(); #else rebootAtMsec = -1; LOG_WARN("FIXME implement reboot for this platform. Note that some settings require a restart to be applied");