Introduce MG_ARCH_CUBE, autodetect everything

This commit is contained in:
Sergey Lyubka committed 2025-07-17 17:29:48 +01:00
1 parent e07a8283ec
commit 75c11436ff
9 files changed
+186 -56

No files matched your search

+9 -4
View File
@@ -17,6 +17,13 @@ bool mg_random(void *buf, size_t len) {
#if MG_ARCH == MG_ARCH_ESP32
while (len--) *p++ = (unsigned char) (esp_random() & 255);
success = true;
#elif MG_ARCH == MG_ARCH_CUBE && defined(HAL_RNG_MODULE_ENABLED)
extern RNG_HandleTypeDef hrng;
for (size_t n = 0; n < len; n += sizeof(uint32_t)) {
uint32_t r = HAL_RNG_ReadLastRandomNumber(&hrng);
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;
@@ -147,6 +154,8 @@ uint64_t mg_millis(void) {
#elif MG_ARCH == MG_ARCH_ESP8266 || MG_ARCH == MG_ARCH_ESP32 || \
MG_ARCH == MG_ARCH_FREERTOS
return xTaskGetTickCount() * portTICK_PERIOD_MS;
#elif MG_ARCH == MG_ARCH_CUBE
return (uint64_t) HAL_GetTick();
#elif MG_ARCH == MG_ARCH_THREADX
return tx_time_get() * (1000 /* MS per SEC */ / TX_TIMER_TICKS_PER_SECOND);
#elif MG_ARCH == MG_ARCH_TIRTOS
@@ -180,10 +189,6 @@ uint64_t mg_millis(void) {
return ((uint64_t) ts.tv_sec * 1000 + (uint64_t) ts.tv_nsec / 1000000);
#elif defined(ARDUINO)
return (uint64_t) millis();
#elif defined(__STM32H5xx_HAL_H) || defined(__STM32H7xx_HAL_H) || \
defined(__STM32F7xx_HAL_H) || defined(__STM32F4xx_HAL_H) || \
defined(__STM32F2xx_HAL_H) || defined(__STM32F1xx_HAL_H)
return (uint64_t) HAL_GetTick(); // Using STM32 HAL
#else
return (uint64_t) (time(NULL) * 1000);
#endif