Skip to content

Commit 604cda5

Browse files
projectgusdpgeorge
authored andcommitted
esp32: Support building with network and/or bluetooth disabled.
(and a smaller binary size as a result) Signed-off-by: Angus Gratton <[email protected]>
1 parent 521b2f8 commit 604cda5

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

ports/esp32/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,16 @@ int vprintf_null(const char *format, va_list ap) {
9090
return 0;
9191
}
9292

93-
time_t platform_mbedtls_time(time_t *timer) {
93+
#if MICROPY_SSL_MBEDTLS
94+
static time_t platform_mbedtls_time(time_t *timer) {
9495
// mbedtls_time requires time in seconds from EPOCH 1970
9596

9697
struct timeval tv;
9798
gettimeofday(&tv, NULL);
9899

99100
return tv.tv_sec + TIMEUTILS_SECONDS_1970_TO_2000;
100101
}
102+
#endif
101103

102104
void mp_task(void *pvParameter) {
103105
volatile uint32_t sp = (uint32_t)esp_cpu_get_sp();
@@ -114,8 +116,10 @@ void mp_task(void *pvParameter) {
114116
#endif
115117
machine_init();
116118

119+
#if MICROPY_SSL_MBEDTLS
117120
// Configure time function, for mbedtls certificate time validation.
118121
mbedtls_platform_set_time(platform_mbedtls_time);
122+
#endif
119123

120124
esp_err_t err = esp_event_loop_create_default();
121125
if (err != ESP_OK) {

ports/esp32/modsocket.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
#include "lwip/igmp.h"
5656
#include "esp_log.h"
5757

58+
// See note at bottom of file about why this isn't MICROPY_PY_SOCKET
59+
#if MICROPY_PY_NETWORK
60+
5861
#define SOCKET_POLL_US (100000)
5962
#define MDNS_QUERY_TIMEOUT_MS (5000)
6063
#define MDNS_LOCAL_SUFFIX ".local"
@@ -1028,3 +1031,5 @@ const mp_obj_module_t mp_module_socket = {
10281031
// this will not conflict with the common implementation provided by
10291032
// extmod/mod{lwip,socket}.c.
10301033
MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_socket, mp_module_socket);
1034+
1035+
#endif // MICROPY_PY_NETWORK

ports/esp32/mpconfigport.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
#endif
9393
#ifndef MICROPY_PY_BLUETOOTH
9494
#define MICROPY_PY_BLUETOOTH (1)
95+
#endif
96+
97+
#if MICROPY_PY_BLUETOOTH
9598
#define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS (1)
9699
#define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK (1)
97100
// Event stack size is the RTOS stack size minus an allowance for the stack used
@@ -102,7 +105,8 @@
102105
#define MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING (1)
103106
#define MICROPY_BLUETOOTH_NIMBLE (1)
104107
#define MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY (1)
105-
#endif
108+
#endif // MICROPY_PY_BLUETOOTH
109+
106110
#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (esp_random())
107111
#define MICROPY_PY_OS_INCLUDEFILE "ports/esp32/modos.c"
108112
#define MICROPY_PY_OS_DUPTERM (1)
@@ -158,7 +162,9 @@
158162
#define MICROPY_PY_MACHINE_UART_IRQ (1)
159163
#define MICROPY_PY_MACHINE_WDT (1)
160164
#define MICROPY_PY_MACHINE_WDT_INCLUDEFILE "ports/esp32/machine_wdt.c"
165+
#ifndef MICROPY_PY_NETWORK
161166
#define MICROPY_PY_NETWORK (1)
167+
#endif
162168
#ifndef MICROPY_PY_NETWORK_HOSTNAME_DEFAULT
163169
#if CONFIG_IDF_TARGET_ESP32
164170
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32"
@@ -189,10 +195,10 @@
189195
#ifndef MICROPY_HW_ESP_NEW_I2C_DRIVER
190196
#define MICROPY_HW_ESP_NEW_I2C_DRIVER (0)
191197
#endif
192-
#define MICROPY_PY_SSL (1)
193-
#define MICROPY_SSL_MBEDTLS (1)
194-
#define MICROPY_PY_WEBSOCKET (1)
195-
#define MICROPY_PY_WEBREPL (1)
198+
#define MICROPY_PY_SSL (MICROPY_PY_NETWORK)
199+
#define MICROPY_SSL_MBEDTLS (MICROPY_PY_SSL)
200+
#define MICROPY_PY_WEBSOCKET (MICROPY_PY_NETWORK)
201+
#define MICROPY_PY_WEBREPL (MICROPY_PY_NETWORK)
196202
#define MICROPY_PY_ONEWIRE (1)
197203
#define MICROPY_PY_SOCKET_EVENTS (MICROPY_PY_WEBREPL)
198204
#define MICROPY_PY_BLUETOOTH_RANDOM_ADDR (1)

0 commit comments

Comments
 (0)