Skip to content

Commit

Permalink
samd/mbdetls: Adapt for version 3.5.1.
Browse files Browse the repository at this point in the history
Due to flash size restrictions, do not support SSL when BLE is enabled
and the flash size is 512k.

Signed-off-by: robert-hh <robert@hammelrath.com>
  • Loading branch information
robert-hh committed Sep 4, 2024
1 parent 8eb7b6a commit cdd2c4b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <time.h>
extern time_t samd_rtctime_seconds(time_t *timer);
#define MBEDTLS_PLATFORM_TIME_MACRO samd_rtctime_seconds
#define MBEDTLS_PLATFORM_MS_TIME_ALT mbedtls_ms_time

// Set MicroPython-specific options.
#define MICROPY_MBEDTLS_CONFIG_BARE_METAL (1)
#define MBEDTLS_ECP_NIST_OPTIM
Expand Down
10 changes: 9 additions & 1 deletion ports/samd/mbedtls/mbedtls_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@

#ifdef MICROPY_SSL_MBEDTLS

#include "mbedtls_config.h"
#include "mbedtls_config_port.h"
#include <stdint.h>
uint32_t trng_random_u32(void);
#if defined(MBEDTLS_HAVE_TIME) || defined(MBEDTLS_HAVE_TIME_DATE)
#include <stdbool.h>
#include "py/runtime.h"
#include "shared/timeutils/timeutils.h"
#include "mbedtls/platform_time.h"
extern void rtc_gettime(timeutils_struct_time_t *tm);
#endif

Expand All @@ -59,6 +60,13 @@ time_t samd_rtctime_seconds(time_t *timer) {
rtc_gettime(&tm);
return timeutils_seconds_since_epoch(tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
}

mbedtls_ms_time_t mbedtls_ms_time(void) {
time_t *tv = NULL;
mbedtls_ms_time_t current_ms;
current_ms = samd_rtctime_seconds(tv) * 1000;
return current_ms;
}
#endif

#if defined(MBEDTLS_HAVE_TIME_DATE)
Expand Down
11 changes: 8 additions & 3 deletions ports/samd/mcu/samd51/mpconfigmcu.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ ifneq ($(BOARD_VARIANT),)
MICROPY_PY_NETWORK = 1
CFLAGS += -DMICROPY_PY_NETWORK=1
MICROPY_PY_NETWORK_ESP_HOSTED = 1

MICROPY_PY_LWIP = 1
MICROPY_PY_SSL = 1
MICROPY_SSL_MBEDTLS = 1

ifeq ($(MICROPY_HW_CODESIZE), 1008K)
MICROPY_PY_SSL = 1
MICROPY_SSL_MBEDTLS = 1
else ifeq ($(BOARD_VARIANT), WLAN)
MICROPY_PY_SSL = 1
MICROPY_SSL_MBEDTLS = 1
endif

ifeq ($(BOARD_VARIANT), WLAN_BLE)
MICROPY_PY_BLUETOOTH = 1
Expand Down

0 comments on commit cdd2c4b

Please sign in to comment.