blob: 7c260095789289281da7b62adf415c3548c2c4dc [file] [log] [blame]
Damien Georgebc08c882016-12-06 12:20:10 +11001// Options to control how MicroPython is built for this port,
2// overriding defaults in py/mpconfig.h.
3
Jim Mussared8db517f2019-08-09 18:07:50 +10004// Board-specific definitions
5#include "mpconfigboard.h"
6
Damien Georgebc08c882016-12-06 12:20:10 +11007#include <stdint.h>
8#include <alloca.h>
Damien Georgee4650122023-05-09 09:52:54 +10009#include "esp_random.h"
robertb4062892020-08-22 20:56:26 +020010#include "esp_system.h"
MikeTeachman6d5296e2021-11-09 20:41:34 -080011#include "freertos/FreeRTOS.h"
MikeTeachman0b145fd2024-02-20 21:37:30 -080012#include "driver/i2s_std.h"
Damien Georgee4650122023-05-09 09:52:54 +100013#include "esp_wifi_types.h"
Jim Mussared96008ff2019-09-13 23:04:13 +100014
Damien Georgec8cd5a92022-02-18 15:50:01 +110015#ifndef MICROPY_CONFIG_ROM_LEVEL
16#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES)
17#endif
18
Damien Georgebc08c882016-12-06 12:20:10 +110019// object representation and NLR handling
20#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_A)
Andrew Leech6d799372023-06-26 11:53:28 +100021#if CONFIG_IDF_TARGET_ARCH_XTENSA
Damien Georgebc08c882016-12-06 12:20:10 +110022#define MICROPY_NLR_SETJMP (1)
Damien George68235142021-07-18 12:11:21 +100023#endif
Damien Georgebc08c882016-12-06 12:20:10 +110024
25// memory allocation policies
26#define MICROPY_ALLOC_PATH_MAX (128)
27
Damien Georgef6d63082023-12-18 13:38:16 +110028// Initial Python heap size. This starts small but adds new heap areas on demand due to
29// the settings MICROPY_GC_SPLIT_HEAP and MICROPY_GC_SPLIT_HEAP_AUTO. The value is
30// different for different MCUs and is chosen so they can grow the heap once (double it)
31// and still have enough internal RAM to start WiFi and make a HTTPS request.
32#ifndef MICROPY_GC_INITIAL_HEAP_SIZE
33#if CONFIG_IDF_TARGET_ESP32
34#define MICROPY_GC_INITIAL_HEAP_SIZE (56 * 1024)
35#elif CONFIG_IDF_TARGET_ESP32S2 && !CONFIG_SPIRAM
36#define MICROPY_GC_INITIAL_HEAP_SIZE (36 * 1024)
37#else
38#define MICROPY_GC_INITIAL_HEAP_SIZE (64 * 1024)
39#endif
40#endif
41
Damien Georgebc08c882016-12-06 12:20:10 +110042// emitters
43#define MICROPY_PERSISTENT_CODE_LOAD (1)
Andrew Leech6d799372023-06-26 11:53:28 +100044#if CONFIG_IDF_TARGET_ARCH_RISCV
Andrew Leech55dc4822024-10-08 17:19:34 +110045#if CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT
46#define MICROPY_EMIT_RV32 (0)
47#else
Alessandro Gatti6007f3e2024-07-02 22:49:47 +020048#define MICROPY_EMIT_RV32 (1)
Andrew Leech55dc4822024-10-08 17:19:34 +110049#endif
Andrew Leech6d799372023-06-26 11:53:28 +100050#else
51#define MICROPY_EMIT_XTENSAWIN (1)
Damien George68235142021-07-18 12:11:21 +100052#endif
Damien Georgebc08c882016-12-06 12:20:10 +110053
Damien Georgebc08c882016-12-06 12:20:10 +110054// optimisations
Damien Georged0758d82023-12-11 12:01:40 +110055#ifndef MICROPY_OPT_COMPUTED_GOTO
Damien Georgebc08c882016-12-06 12:20:10 +110056#define MICROPY_OPT_COMPUTED_GOTO (1)
Damien Georged0758d82023-12-11 12:01:40 +110057#endif
Damien Georgebc08c882016-12-06 12:20:10 +110058
59// Python internal features
60#define MICROPY_READER_VFS (1)
61#define MICROPY_ENABLE_GC (1)
Angus Grattone3955f42024-08-06 16:13:33 +100062#define MICROPY_STACK_CHECK_MARGIN (1024)
Damien Georgebc08c882016-12-06 12:20:10 +110063#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
Damien Georgebc08c882016-12-06 12:20:10 +110064#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
Damien Georgebc08c882016-12-06 12:20:10 +110065#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
66#define MICROPY_WARNINGS (1)
67#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
Damien Georgebc08c882016-12-06 12:20:10 +110068#define MICROPY_STREAMS_POSIX_API (1)
Thorsten von Eicken902da052020-11-11 17:46:18 -080069#define MICROPY_USE_INTERNAL_ERRNO (0) // errno.h from xtensa-esp32-elf/sys-include/sys
Damien Georgebc08c882016-12-06 12:20:10 +110070#define MICROPY_USE_INTERNAL_PRINTF (0) // ESP32 SDK requires its own printf
Damien Georgebc08c882016-12-06 12:20:10 +110071#define MICROPY_SCHEDULER_DEPTH (8)
72#define MICROPY_VFS (1)
Damien Georgebc08c882016-12-06 12:20:10 +110073
74// control over Python builtins
Damien Georgebc08c882016-12-06 12:20:10 +110075#define MICROPY_PY_STR_BYTES_CMP_WARN (1)
Jim Mussaredbfc8e882021-08-04 15:35:00 +100076#define MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS (1)
Damien Georgebc08c882016-12-06 12:20:10 +110077#define MICROPY_PY_BUILTINS_HELP_TEXT esp32_help_text
Damien Georgebc08c882016-12-06 12:20:10 +110078#define MICROPY_PY_IO_BUFFEREDWRITER (1)
Jim Mussaredf5f9edf2022-08-18 15:01:26 +100079#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1)
80#define MICROPY_PY_TIME_TIME_TIME_NS (1)
81#define MICROPY_PY_TIME_INCLUDEFILE "ports/esp32/modtime.c"
Damien Georgebc08c882016-12-06 12:20:10 +110082#define MICROPY_PY_THREAD (1)
83#define MICROPY_PY_THREAD_GIL (1)
84#define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32)
85
Angus Gratton05dcb8b2023-08-02 16:51:07 +100086#define MICROPY_GC_SPLIT_HEAP (1)
87#define MICROPY_GC_SPLIT_HEAP_AUTO (1)
88
Damien Georgebc08c882016-12-06 12:20:10 +110089// extended modules
Glenn Moloney9f835df2023-10-10 13:06:59 +110090#ifndef MICROPY_PY_ESPNOW
91#define MICROPY_PY_ESPNOW (1)
Glenn Moloney7fa322a2020-09-24 15:37:04 +100092#endif
Damien Georgeda2b5fa2021-02-14 01:36:30 +110093#ifndef MICROPY_PY_BLUETOOTH
94#define MICROPY_PY_BLUETOOTH (1)
Damien George5dbb8222021-03-17 12:35:59 +110095#define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS (1)
96#define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK (1)
Angus Gratton6565b3c2024-08-15 16:00:08 +100097// Event stack size is the RTOS stack size minus an allowance for the stack used
98// by the NimBLE functions that call into invoke_irq_handler().
99// MICROPY_STACK_CHECK_MARGIN is further subtracted from this value to set the stack limit.
100#define MICROPY_PY_BLUETOOTH_SYNC_EVENT_STACK_SIZE (CONFIG_BT_NIMBLE_TASK_STACK_SIZE - 1024)
Damien Georgeda2b5fa2021-02-14 01:36:30 +1100101#define MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE (1)
Damien George5dbb8222021-03-17 12:35:59 +1100102#define MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING (1)
Damien Georgeda2b5fa2021-02-14 01:36:30 +1100103#define MICROPY_BLUETOOTH_NIMBLE (1)
104#define MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY (1)
105#endif
IhorNehrutsa55528962023-12-19 16:28:06 +0200106#define MICROPY_PY_HASHLIB_MD5 (1)
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000107#define MICROPY_PY_HASHLIB_SHA1 (1)
108#define MICROPY_PY_HASHLIB_SHA256 (1)
109#define MICROPY_PY_CRYPTOLIB (1)
110#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (esp_random())
Jim Mussared45ac6512022-08-18 16:24:27 +1000111#define MICROPY_PY_OS_INCLUDEFILE "ports/esp32/modos.c"
Damien George98b05e32018-04-27 23:51:00 +1000112#define MICROPY_PY_OS_DUPTERM (1)
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000113#define MICROPY_PY_OS_DUPTERM_NOTIFY (1)
114#define MICROPY_PY_OS_SYNC (1)
115#define MICROPY_PY_OS_UNAME (1)
116#define MICROPY_PY_OS_URANDOM (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100117#define MICROPY_PY_MACHINE (1)
Damien George7d39db22023-11-22 13:00:02 +1100118#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/esp32/modmachine.c"
Damien Georgebfc3dde2024-03-14 11:09:14 +1100119#define MICROPY_PY_MACHINE_RESET (1)
Damien Georgee1ec6af2023-11-24 18:25:30 +1100120#define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1)
Damien Georgef523b862023-11-27 11:43:15 +1100121#define MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ (1)
Damien George95d8b5f2023-10-11 13:48:49 +1100122#define MICROPY_PY_MACHINE_ADC (1)
123#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/esp32/machine_adc.c"
124#define MICROPY_PY_MACHINE_ADC_ATTEN_WIDTH (1)
Damien George95d8b5f2023-10-11 13:48:49 +1100125#define MICROPY_PY_MACHINE_ADC_INIT (1)
126#define MICROPY_PY_MACHINE_ADC_READ (1)
127#define MICROPY_PY_MACHINE_ADC_READ_UV (1)
Damien George03eae482023-10-25 19:13:11 +1100128#define MICROPY_PY_MACHINE_ADC_BLOCK (1)
129#define MICROPY_PY_MACHINE_ADC_BLOCK_INCLUDEFILE "ports/esp32/machine_adc_block.c"
Damien Georgebc08c882016-12-06 12:20:10 +1100130#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new
Jim Mussared71f4faa2021-08-11 14:26:23 +1000131#define MICROPY_PY_MACHINE_BITSTREAM (1)
Damien George7d39db22023-11-22 13:00:02 +1100132#define MICROPY_PY_MACHINE_DHT_READINTO (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100133#define MICROPY_PY_MACHINE_PULSE (1)
Damien Georgeaf64c2d2021-06-24 12:37:50 +1000134#define MICROPY_PY_MACHINE_PWM (1)
Damien Georgeaf64c2d2021-06-24 12:37:50 +1000135#define MICROPY_PY_MACHINE_PWM_DUTY (1)
136#define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/esp32/machine_pwm.c"
Damien Georgebc08c882016-12-06 12:20:10 +1100137#define MICROPY_PY_MACHINE_I2C (1)
Damien George6bda80d2022-06-01 11:58:30 +1000138#define MICROPY_PY_MACHINE_I2C_TRANSFER_WRITE1 (1)
Damien George122d9012021-09-02 12:37:00 +1000139#define MICROPY_PY_MACHINE_SOFTI2C (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100140#define MICROPY_PY_MACHINE_SPI (1)
Damien Georgeafe06342021-09-02 12:39:28 +1000141#define MICROPY_PY_MACHINE_SOFTSPI (1)
Damien George1f9243f2021-07-18 12:11:10 +1000142#ifndef MICROPY_PY_MACHINE_DAC
IhorNehrutsa495be712023-11-12 20:46:26 +0200143#define MICROPY_PY_MACHINE_DAC (SOC_DAC_SUPPORTED)
Damien George1f9243f2021-07-18 12:11:10 +1000144#endif
Damien George0fc0cca2021-07-18 12:11:15 +1000145#ifndef MICROPY_PY_MACHINE_I2S
Ihor Nehrutsa3069fee2023-11-13 14:07:59 +0200146#define MICROPY_PY_MACHINE_I2S (SOC_I2S_SUPPORTED)
Damien George0fc0cca2021-07-18 12:11:15 +1000147#endif
Damien Georgef2f3ef12023-10-09 12:12:18 +1100148#define MICROPY_PY_MACHINE_I2S_INCLUDEFILE "ports/esp32/machine_i2s.c"
149#define MICROPY_PY_MACHINE_I2S_FINALISER (1)
MikeTeachman0b145fd2024-02-20 21:37:30 -0800150#define MICROPY_PY_MACHINE_I2S_CONSTANT_RX (I2S_DIR_RX)
151#define MICROPY_PY_MACHINE_I2S_CONSTANT_TX (I2S_DIR_TX)
Damien George5b4a2ba2023-10-10 23:46:07 +1100152#define MICROPY_PY_MACHINE_UART (1)
153#define MICROPY_PY_MACHINE_UART_INCLUDEFILE "ports/esp32/machine_uart.c"
154#define MICROPY_PY_MACHINE_UART_SENDBREAK (1)
robert-hha04a1412024-03-10 15:14:20 +0100155#define MICROPY_PY_MACHINE_UART_IRQ (1)
Damien George60929ec2023-10-10 18:19:03 +1100156#define MICROPY_PY_MACHINE_WDT (1)
157#define MICROPY_PY_MACHINE_WDT_INCLUDEFILE "ports/esp32/machine_wdt.c"
Jim Mussaredeb51ca42023-02-01 14:20:45 +1100158#define MICROPY_PY_NETWORK (1)
159#ifndef MICROPY_PY_NETWORK_HOSTNAME_DEFAULT
160#if CONFIG_IDF_TARGET_ESP32
161#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32"
162#elif CONFIG_IDF_TARGET_ESP32S2
163#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32s2"
164#elif CONFIG_IDF_TARGET_ESP32S3
165#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32s3"
166#elif CONFIG_IDF_TARGET_ESP32C3
167#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32c3"
Andrew Leech6d799372023-06-26 11:53:28 +1000168#elif CONFIG_IDF_TARGET_ESP32C6
169#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32c6"
Jim Mussaredeb51ca42023-02-01 14:20:45 +1100170#endif
171#endif
172#define MICROPY_PY_NETWORK_INCLUDEFILE "ports/esp32/modnetwork.h"
173#define MICROPY_PY_NETWORK_MODULE_GLOBALS_INCLUDEFILE "ports/esp32/modnetwork_globals.h"
Damien Georgeea186de2021-09-22 00:35:46 +1000174#ifndef MICROPY_PY_NETWORK_WLAN
175#define MICROPY_PY_NETWORK_WLAN (1)
176#endif
Damien George66a86a02021-02-18 21:24:34 +1100177#ifndef MICROPY_HW_ENABLE_SDCARD
Nicko van Someren8e3af7d2019-05-04 19:00:35 -0600178#define MICROPY_HW_ENABLE_SDCARD (1)
Damien George66a86a02021-02-18 21:24:34 +1100179#endif
Damien George58ebeca2018-03-09 17:25:58 +1100180#define MICROPY_HW_SOFTSPI_MIN_DELAY (0)
Damien Georgee4650122023-05-09 09:52:54 +1000181#define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (esp_rom_get_cpu_ticks_per_us() * 1000000 / 200) // roughly
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000182#define MICROPY_PY_SSL (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100183#define MICROPY_SSL_MBEDTLS (1)
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000184#define MICROPY_PY_WEBSOCKET (1)
Damien Georgec1d43522018-04-27 23:57:57 +1000185#define MICROPY_PY_WEBREPL (1)
Damien Georged41f6dd2021-09-02 12:39:50 +1000186#define MICROPY_PY_ONEWIRE (1)
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000187#define MICROPY_PY_SOCKET_EVENTS (MICROPY_PY_WEBREPL)
Jim Mussared6a9bd1c2019-10-01 23:47:37 +1000188#define MICROPY_PY_BLUETOOTH_RANDOM_ADDR (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100189
190// fatfs configuration
191#define MICROPY_FATFS_ENABLE_LFN (1)
192#define MICROPY_FATFS_RPATH (2)
193#define MICROPY_FATFS_MAX_SS (4096)
Damien Georgeb5f33ac2019-02-25 23:46:17 +1100194#define MICROPY_FATFS_LFN_CODE_PAGE 437 /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
Damien Georgebc08c882016-12-06 12:20:10 +1100195
dotnfcd7f63f92023-09-12 17:15:27 +0800196// task size
197#ifndef MICROPY_TASK_STACK_SIZE
198#define MICROPY_TASK_STACK_SIZE (16 * 1024)
199#endif
200
Damien Georgebc08c882016-12-06 12:20:10 +1100201#define MP_STATE_PORT MP_STATE_VM
202
Andrew Leech42479212024-05-23 17:23:41 +1000203#ifndef MICROPY_HW_ENABLE_USBDEV
204#define MICROPY_HW_ENABLE_USBDEV (SOC_USB_OTG_SUPPORTED)
205#endif
206
207#if MICROPY_HW_ENABLE_USBDEV
Andrew Leech5ae622e2024-05-23 22:08:12 +1000208#define MICROPY_SCHEDULER_STATIC_NODES (1)
209#define MICROPY_HW_USB_CDC_DTR_RTS_BOOTLOADER (1)
Andrew Leech42479212024-05-23 17:23:41 +1000210
211#ifndef MICROPY_HW_USB_VID
212#define USB_ESPRESSIF_VID 0x303A
213#if CONFIG_TINYUSB_DESC_USE_ESPRESSIF_VID
214#define MICROPY_HW_USB_VID (USB_ESPRESSIF_VID)
215#else
216#define MICROPY_HW_USB_VID (CONFIG_TINYUSB_DESC_CUSTOM_VID)
217#endif
Sebastian Romero5f2d05d2024-12-04 16:30:56 +0100218
219#ifndef MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
220#define MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE (1) // Support machine.USBDevice
221#endif
Andrew Leech42479212024-05-23 17:23:41 +1000222#endif
223
224#ifndef MICROPY_HW_USB_PID
225#if CONFIG_TINYUSB_DESC_USE_DEFAULT_PID
226#define _PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
227// A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
228// Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
229// Auto ProductID layout's Bitmap:
230// [MSB] HID | MSC | CDC [LSB]
231#define USB_TUSB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
232 _PID_MAP(MIDI, 3)) // | _PID_MAP(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
233#define MICROPY_HW_USB_PID (USB_TUSB_PID)
234#else
235#define MICROPY_HW_USB_PID (CONFIG_TINYUSB_DESC_CUSTOM_PID)
236#endif
237#endif
238
239#ifndef MICROPY_HW_USB_MANUFACTURER_STRING
240#ifdef CONFIG_TINYUSB_DESC_MANUFACTURER_STRING
241#define MICROPY_HW_USB_MANUFACTURER_STRING CONFIG_TINYUSB_DESC_MANUFACTURER_STRING
242#else
243#define MICROPY_HW_USB_MANUFACTURER_STRING "MicroPython"
244#endif
245#endif
246
247#ifndef MICROPY_HW_USB_PRODUCT_FS_STRING
248#ifdef CONFIG_TINYUSB_DESC_PRODUCT_STRING
249#define MICROPY_HW_USB_PRODUCT_FS_STRING CONFIG_TINYUSB_DESC_PRODUCT_STRING
250#else
251#define MICROPY_HW_USB_PRODUCT_FS_STRING "Board in FS mode"
252#endif
253#endif
254
255#endif // MICROPY_HW_ENABLE_USBDEV
256
257// Enable stdio over native USB peripheral CDC via TinyUSB
258#ifndef MICROPY_HW_USB_CDC
259#define MICROPY_HW_USB_CDC (MICROPY_HW_ENABLE_USBDEV)
260#endif
261
262// Enable stdio over USB Serial/JTAG peripheral
263#ifndef MICROPY_HW_ESP_USB_SERIAL_JTAG
264#define MICROPY_HW_ESP_USB_SERIAL_JTAG (SOC_USB_SERIAL_JTAG_SUPPORTED && !MICROPY_HW_USB_CDC)
265#endif
266
267#if MICROPY_HW_USB_CDC && MICROPY_HW_ESP_USB_SERIAL_JTAG
268#error "Invalid build config: Can't enable both native USB and USB Serial/JTAG peripheral"
269#endif
270
Damien Georgebc08c882016-12-06 12:20:10 +1100271// type definitions for the specific machine
272
Damien George69661f32020-02-27 15:36:53 +1100273#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p)))
Andrew Leech55dc4822024-10-08 17:19:34 +1100274#if SOC_CPU_IDRAM_SPLIT_USING_PMP && !CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT
275// On targets with this configuration all RAM is executable so no need for a custom commit function.
276#else
Damien George69661f32020-02-27 15:36:53 +1100277void *esp_native_code_commit(void *, size_t, void *);
Damien Georgeb47e1552019-10-06 23:29:40 +1100278#define MP_PLAT_COMMIT_EXEC(buf, len, reloc) esp_native_code_commit(buf, len, reloc)
Andrew Leech55dc4822024-10-08 17:19:34 +1100279#endif
Damien Georgebc08c882016-12-06 12:20:10 +1100280#define MP_SSIZE_MAX (0x7fffffff)
281
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000282#if MICROPY_PY_SOCKET_EVENTS
283#define MICROPY_PY_SOCKET_EVENTS_HANDLER extern void socket_events_handler(void); socket_events_handler();
Damien George999c8b92018-04-27 23:53:45 +1000284#else
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000285#define MICROPY_PY_SOCKET_EVENTS_HANDLER
Damien George999c8b92018-04-27 23:53:45 +1000286#endif
287
Damien Georgebc08c882016-12-06 12:20:10 +1100288#if MICROPY_PY_THREAD
289#define MICROPY_EVENT_POLL_HOOK \
290 do { \
Damien George98a39112020-02-06 01:05:47 +1100291 extern void mp_handle_pending(bool); \
292 mp_handle_pending(true); \
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000293 MICROPY_PY_SOCKET_EVENTS_HANDLER \
Damien Georgebc08c882016-12-06 12:20:10 +1100294 MP_THREAD_GIL_EXIT(); \
Daniƫl van de Giessen665f0e22022-02-23 17:28:32 +0100295 ulTaskNotifyTake(pdFALSE, 1); \
Damien Georgebc08c882016-12-06 12:20:10 +1100296 MP_THREAD_GIL_ENTER(); \
297 } while (0);
298#else
Alessandro Gatti82e382a2024-12-04 12:30:25 +0100299#if CONFIG_IDF_TARGET_ARCH_RISCV
300#define MICROPY_PY_WAIT_FOR_INTERRUPT asm volatile ("wfi\n")
301#else
302#define MICROPY_PY_WAIT_FOR_INTERRUPT asm volatile ("waiti 0\n")
303#endif
Damien Georgebc08c882016-12-06 12:20:10 +1100304#define MICROPY_EVENT_POLL_HOOK \
305 do { \
Damien George98a39112020-02-06 01:05:47 +1100306 extern void mp_handle_pending(bool); \
307 mp_handle_pending(true); \
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000308 MICROPY_PY_SOCKET_EVENTS_HANDLER \
Alessandro Gatti82e382a2024-12-04 12:30:25 +0100309 MICROPY_PY_WAIT_FOR_INTERRUPT; \
Damien Georgebc08c882016-12-06 12:20:10 +1100310 } while (0);
311#endif
312
Damien Georgef4641b22020-02-07 12:11:22 +1100313// Functions that should go in IRAM
Damien Georgeb4b77c12023-12-11 12:01:09 +1100314// For ESP32 with SPIRAM workaround, firmware is larger and uses more static IRAM,
315// so in that configuration don't put too many functions in IRAM.
316#if !(CONFIG_IDF_TARGET_ESP32 && CONFIG_SPIRAM && CONFIG_SPIRAM_CACHE_WORKAROUND)
Damien George549448e2021-09-24 12:50:59 +1000317#define MICROPY_WRAP_MP_BINARY_OP(f) IRAM_ATTR f
Damien Georgeb4b77c12023-12-11 12:01:09 +1100318#endif
Damien George549448e2021-09-24 12:50:59 +1000319#define MICROPY_WRAP_MP_EXECUTE_BYTECODE(f) IRAM_ATTR f
320#define MICROPY_WRAP_MP_LOAD_GLOBAL(f) IRAM_ATTR f
321#define MICROPY_WRAP_MP_LOAD_NAME(f) IRAM_ATTR f
322#define MICROPY_WRAP_MP_MAP_LOOKUP(f) IRAM_ATTR f
323#define MICROPY_WRAP_MP_OBJ_GET_TYPE(f) IRAM_ATTR f
Damien George7cbf8262021-04-28 10:52:19 +1000324#define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) IRAM_ATTR f
Damien Georgee9e9c762021-04-28 10:57:34 +1000325#define MICROPY_WRAP_MP_SCHED_KEYBOARD_INTERRUPT(f) IRAM_ATTR f
Damien Georgef4641b22020-02-07 12:11:22 +1100326
Damien Georgebc08c882016-12-06 12:20:10 +1100327#define UINT_FMT "%u"
328#define INT_FMT "%d"
329
330typedef int32_t mp_int_t; // must be pointer size
331typedef uint32_t mp_uint_t; // must be pointer size
332typedef long mp_off_t;
333// ssize_t, off_t as required by POSIX-signatured functions in stream.h
334#include <sys/types.h>
335
336// board specifics
Damien Georgebc08c882016-12-06 12:20:10 +1100337#define MICROPY_PY_SYS_PLATFORM "esp32"
Damien George2ccf0302019-07-10 15:38:48 +1000338
Seon Rozenblum19048332021-11-12 11:23:49 +1100339// ESP32-S3 extended IO for 47 & 48
340#ifndef MICROPY_HW_ESP32S3_EXTENDED_IO
341#define MICROPY_HW_ESP32S3_EXTENDED_IO (1)
342#endif
343
Damien George2ccf0302019-07-10 15:38:48 +1000344#ifndef MICROPY_HW_ENABLE_MDNS_QUERIES
Carlosgg1f355762023-06-25 22:48:39 +0100345#define MICROPY_HW_ENABLE_MDNS_QUERIES (1)
Damien George2ccf0302019-07-10 15:38:48 +1000346#endif
347
348#ifndef MICROPY_HW_ENABLE_MDNS_RESPONDER
Carlosgg1f355762023-06-25 22:48:39 +0100349#define MICROPY_HW_ENABLE_MDNS_RESPONDER (1)
Damien George2ccf0302019-07-10 15:38:48 +1000350#endif
Damien Georgef046b502021-09-22 00:00:26 +1000351
Trent Piephoaf67be72024-03-02 01:25:10 -0800352#ifndef MICROPY_BOARD_ENTER_BOOTLOADER
353// RTC has a register to trigger bootloader on these targets
354#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3
355#define MICROPY_ESP32_USE_BOOTLOADER_RTC (1)
356#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) machine_bootloader_rtc()
357#endif
358#endif
359
Trent Piepho9fc45062024-03-02 01:10:20 -0800360#ifdef MICROPY_BOARD_ENTER_BOOTLOADER
361#define MICROPY_PY_MACHINE_BOOTLOADER (1)
362#else
363#define MICROPY_PY_MACHINE_BOOTLOADER (0)
Luca Burelli904ccfa2023-07-04 11:54:53 +0200364#endif
365
Angus Gratton6fead312024-07-25 12:11:32 +1000366// Workaround for upstream bug https://github.com/espressif/esp-idf/issues/14273
367// Can be removed if a fix is available in supported ESP-IDF versions.
368#define MICROPY_PY_MATH_GAMMA_FIX_NEGINF (1)
369
Damien Georgef046b502021-09-22 00:00:26 +1000370#ifndef MICROPY_BOARD_STARTUP
371#define MICROPY_BOARD_STARTUP boardctrl_startup
372#endif
373
374void boardctrl_startup(void);
Damien Tournoude982c1d2023-01-12 21:04:07 -0800375
376#ifndef MICROPY_PY_NETWORK_LAN
Damien Georgee4650122023-05-09 09:52:54 +1000377#if CONFIG_IDF_TARGET_ESP32 || (CONFIG_ETH_USE_SPI_ETHERNET && (CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL || CONFIG_ETH_SPI_ETHERNET_DM9051 || CONFIG_ETH_SPI_ETHERNET_W5500))
Damien Tournoude982c1d2023-01-12 21:04:07 -0800378#define MICROPY_PY_NETWORK_LAN (1)
379#else
380#define MICROPY_PY_NETWORK_LAN (0)
381#endif
382#endif
383
384#if MICROPY_PY_NETWORK_LAN && CONFIG_ETH_USE_SPI_ETHERNET
385#ifndef MICROPY_PY_NETWORK_LAN_SPI_CLOCK_SPEED_MZ
Andrew Leech6d799372023-06-26 11:53:28 +1000386#define MICROPY_PY_NETWORK_LAN_SPI_CLOCK_SPEED_MZ (20)
Damien Tournoude982c1d2023-01-12 21:04:07 -0800387#endif
388#endif
Alessandro Gatti0b75e182024-08-10 16:37:03 +0200389
390// The minimum string length threshold for string printing to stdout operations to be GIL-aware.
391#ifndef MICROPY_PY_STRING_TX_GIL_THRESHOLD
392#define MICROPY_PY_STRING_TX_GIL_THRESHOLD (20)
393#endif
Alessandro Gatti883dc412025-03-25 22:43:23 +0100394
395// Code can override this to provide a custom ESP-IDF entry point.
396#ifndef MICROPY_ESP_IDF_ENTRY
397#define MICROPY_ESP_IDF_ENTRY app_main
398#endif