diff --git a/mongoose.c b/mongoose.c index 97049830..61afa2f7 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3487,7 +3487,7 @@ struct mg_fs mg_fs_posix = {p_stat, p_list, p_open, p_close, p_read, struct mg_health mg_health_record MG_HEALTH_RAM; // STM32 H723 support. Needs the _estack symbol from the linker script -#if MG_ENABLE_HEALTH && defined(STM32H723xx_H) +#if MG_ENABLE_HEALTH && (defined(STM32H7_DEV_ID) || defined(STM32H5)) // Fault handler body. Runs in exception context: no printf, no malloc, no // blocking calls. Copies the unwind registers and raw stack into the health // record, then resets. @@ -26581,11 +26581,12 @@ bool mg_random(void *buf, size_t len) { success = true; #elif MG_ARCH == MG_ARCH_CUBE && defined(HAL_RNG_MODULE_ENABLED) extern RNG_HandleTypeDef hrng; + success = true; for (size_t n = 0; n < len; n += sizeof(uint32_t)) { - uint32_t r = HAL_RNG_ReadLastRandomNumber(&hrng); + uint32_t r = 0; + if (HAL_RNG_GenerateRandomNumber(&hrng, &r) != HAL_OK) success = false; memcpy((char *) buf + n, &r, n + sizeof(r) > len ? len - n : sizeof(r)); } - success = true; #elif MG_ARCH == MG_ARCH_PICOSDK while (len--) *p++ = (unsigned char) (get_rand_32() & 255); success = true; diff --git a/mongoose.h b/mongoose.h index f98f5f52..8a784269 100644 --- a/mongoose.h +++ b/mongoose.h @@ -4927,6 +4927,10 @@ void mg_ota_poll(struct mg_mgr *); #define MG_HEALTH_MAGIC {'M', 'G', 'H', '3'} // '3' is the layout version #endif +#if !defined(MG_HEALTH_RAM) && (defined(STM32H7_DEV_ID) || defined(STM32H5)) +#define MG_HEALTH_RAM __attribute__((section(".mg_health"))) +#endif + // Places the record in RAM that survives a reset. Define in mongoose_config.h // to match the linker script, e.g. __attribute__((section(".mg_health"))) #ifndef MG_HEALTH_RAM @@ -4948,7 +4952,7 @@ enum mg_health_reason { }; #ifndef MG_HEALTH_DATA_SIZE -#define MG_HEALTH_DATA_SIZE 20 +#define MG_HEALTH_DATA_SIZE 250 #endif struct mg_health { diff --git a/src/health.c b/src/health.c index b4a2eebc..1c167976 100644 --- a/src/health.c +++ b/src/health.c @@ -6,7 +6,7 @@ struct mg_health mg_health_record MG_HEALTH_RAM; // STM32 H723 support. Needs the _estack symbol from the linker script -#if MG_ENABLE_HEALTH && defined(STM32H723xx_H) +#if MG_ENABLE_HEALTH && (defined(STM32H7_DEV_ID) || defined(STM32H5)) // Fault handler body. Runs in exception context: no printf, no malloc, no // blocking calls. Copies the unwind registers and raw stack into the health // record, then resets. diff --git a/src/health.h b/src/health.h index be662bdc..d438b0b2 100644 --- a/src/health.h +++ b/src/health.h @@ -9,6 +9,10 @@ #define MG_HEALTH_MAGIC {'M', 'G', 'H', '3'} // '3' is the layout version #endif +#if !defined(MG_HEALTH_RAM) && (defined(STM32H7_DEV_ID) || defined(STM32H5)) +#define MG_HEALTH_RAM __attribute__((section(".mg_health"))) +#endif + // Places the record in RAM that survives a reset. Define in mongoose_config.h // to match the linker script, e.g. __attribute__((section(".mg_health"))) #ifndef MG_HEALTH_RAM @@ -30,7 +34,7 @@ enum mg_health_reason { }; #ifndef MG_HEALTH_DATA_SIZE -#define MG_HEALTH_DATA_SIZE 20 +#define MG_HEALTH_DATA_SIZE 250 #endif struct mg_health { diff --git a/src/util.c b/src/util.c index 7539f09f..24619fd2 100644 --- a/src/util.c +++ b/src/util.c @@ -43,11 +43,12 @@ bool mg_random(void *buf, size_t len) { success = true; #elif MG_ARCH == MG_ARCH_CUBE && defined(HAL_RNG_MODULE_ENABLED) extern RNG_HandleTypeDef hrng; + success = true; for (size_t n = 0; n < len; n += sizeof(uint32_t)) { - uint32_t r = HAL_RNG_ReadLastRandomNumber(&hrng); + uint32_t r = 0; + if (HAL_RNG_GenerateRandomNumber(&hrng, &r) != HAL_OK) success = false; memcpy((char *) buf + n, &r, n + sizeof(r) > len ? len - n : sizeof(r)); } - success = true; #elif MG_ARCH == MG_ARCH_PICOSDK while (len--) *p++ = (unsigned char) (get_rand_32() & 255); success = true; diff --git a/tutorials/stm32/nucleo-h723zg/minimal/mongoose_config.h b/tutorials/stm32/nucleo-h723zg/minimal/mongoose_config.h index 23b639c5..5f1f6a15 100644 --- a/tutorials/stm32/nucleo-h723zg/minimal/mongoose_config.h +++ b/tutorials/stm32/nucleo-h723zg/minimal/mongoose_config.h @@ -28,10 +28,8 @@ // Crash report support. Health record lives in the .mg_health region, see link.ld #define MG_ENABLE_HEALTH 1 -#define MG_HEALTH_RAM __attribute__((section(".mg_health"))) -#define MG_HEALTH_DATA_SIZE 1000 // mdash.net device management service support #define MG_ENABLE_MDASH 0 #define MG_MDASH_KEY "..." // Set this - mDash device token -#define MG_FIRMWARE_VERSION "1.0.0" +#define MG_FIRMWARE_VERSION "h723.1.0.0"