blob: a6f103cdef7a58611b818dc55e024a0c14858a6e [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)
IhorNehrutsaa7245452025-02-19 09:23:04 +020065#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL) // Debugging Note: Increase the error reporting level to view
66 // __FUNCTION__, __LINE__, __FILE__ in check_esp_err() exceptions
Damien Georgebc08c882016-12-06 12:20:10 +110067#define MICROPY_WARNINGS (1)
68#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
Damien Georgebc08c882016-12-06 12:20:10 +110069#define MICROPY_STREAMS_POSIX_API (1)
Thorsten von Eicken902da052020-11-11 17:46:18 -080070#define MICROPY_USE_INTERNAL_ERRNO (0) // errno.h from xtensa-esp32-elf/sys-include/sys
Damien Georgebc08c882016-12-06 12:20:10 +110071#define MICROPY_USE_INTERNAL_PRINTF (0) // ESP32 SDK requires its own printf
Damien Georgebc08c882016-12-06 12:20:10 +110072#define MICROPY_SCHEDULER_DEPTH (8)
73#define MICROPY_VFS (1)
Damien Georgebc08c882016-12-06 12:20:10 +110074
75// control over Python builtins
Damien Georgebc08c882016-12-06 12:20:10 +110076#define MICROPY_PY_STR_BYTES_CMP_WARN (1)
Jim Mussaredbfc8e882021-08-04 15:35:00 +100077#define MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS (1)
Damien Georgebc08c882016-12-06 12:20:10 +110078#define MICROPY_PY_BUILTINS_HELP_TEXT esp32_help_text
Damien Georgebc08c882016-12-06 12:20:10 +110079#define MICROPY_PY_IO_BUFFEREDWRITER (1)
Jim Mussaredf5f9edf2022-08-18 15:01:26 +100080#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1)
81#define MICROPY_PY_TIME_TIME_TIME_NS (1)
82#define MICROPY_PY_TIME_INCLUDEFILE "ports/esp32/modtime.c"
Damien Georgebc08c882016-12-06 12:20:10 +110083#define MICROPY_PY_THREAD (1)
84#define MICROPY_PY_THREAD_GIL (1)
85#define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32)
86
Angus Gratton05dcb8b2023-08-02 16:51:07 +100087#define MICROPY_GC_SPLIT_HEAP (1)
88#define MICROPY_GC_SPLIT_HEAP_AUTO (1)
89
Damien Georgebc08c882016-12-06 12:20:10 +110090// extended modules
Glenn Moloney9f835df2023-10-10 13:06:59 +110091#ifndef MICROPY_PY_ESPNOW
92#define MICROPY_PY_ESPNOW (1)
Glenn Moloney7fa322a2020-09-24 15:37:04 +100093#endif
Damien Georgeda2b5fa2021-02-14 01:36:30 +110094#ifndef MICROPY_PY_BLUETOOTH
95#define MICROPY_PY_BLUETOOTH (1)
Damien George5dbb8222021-03-17 12:35:59 +110096#define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS (1)
97#define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK (1)
Angus Gratton6565b3c2024-08-15 16:00:08 +100098// Event stack size is the RTOS stack size minus an allowance for the stack used
99// by the NimBLE functions that call into invoke_irq_handler().
100// MICROPY_STACK_CHECK_MARGIN is further subtracted from this value to set the stack limit.
101#define MICROPY_PY_BLUETOOTH_SYNC_EVENT_STACK_SIZE (CONFIG_BT_NIMBLE_TASK_STACK_SIZE - 1024)
Damien Georgeda2b5fa2021-02-14 01:36:30 +1100102#define MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE (1)
Damien George5dbb8222021-03-17 12:35:59 +1100103#define MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING (1)
Damien Georgeda2b5fa2021-02-14 01:36:30 +1100104#define MICROPY_BLUETOOTH_NIMBLE (1)
105#define MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY (1)
106#endif
IhorNehrutsa55528962023-12-19 16:28:06 +0200107#define MICROPY_PY_HASHLIB_MD5 (1)
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000108#define MICROPY_PY_HASHLIB_SHA1 (1)
109#define MICROPY_PY_HASHLIB_SHA256 (1)
110#define MICROPY_PY_CRYPTOLIB (1)
111#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (esp_random())
Jim Mussared45ac6512022-08-18 16:24:27 +1000112#define MICROPY_PY_OS_INCLUDEFILE "ports/esp32/modos.c"
Damien George98b05e32018-04-27 23:51:00 +1000113#define MICROPY_PY_OS_DUPTERM (1)
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000114#define MICROPY_PY_OS_DUPTERM_NOTIFY (1)
115#define MICROPY_PY_OS_SYNC (1)
116#define MICROPY_PY_OS_UNAME (1)
117#define MICROPY_PY_OS_URANDOM (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100118#define MICROPY_PY_MACHINE (1)
Damien George7d39db22023-11-22 13:00:02 +1100119#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/esp32/modmachine.c"
Damien Georgebfc3dde2024-03-14 11:09:14 +1100120#define MICROPY_PY_MACHINE_RESET (1)
Damien Georgee1ec6af2023-11-24 18:25:30 +1100121#define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1)
Damien Georgef523b862023-11-27 11:43:15 +1100122#define MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ (1)
Damien George95d8b5f2023-10-11 13:48:49 +1100123#define MICROPY_PY_MACHINE_ADC (1)
124#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/esp32/machine_adc.c"
125#define MICROPY_PY_MACHINE_ADC_ATTEN_WIDTH (1)
Damien George95d8b5f2023-10-11 13:48:49 +1100126#define MICROPY_PY_MACHINE_ADC_INIT (1)
purewack5f058e92025-01-02 11:44:00 +0000127#define MICROPY_PY_MACHINE_ADC_DEINIT (1)
Damien George95d8b5f2023-10-11 13:48:49 +1100128#define MICROPY_PY_MACHINE_ADC_READ (1)
129#define MICROPY_PY_MACHINE_ADC_READ_UV (1)
Damien George03eae482023-10-25 19:13:11 +1100130#define MICROPY_PY_MACHINE_ADC_BLOCK (1)
131#define MICROPY_PY_MACHINE_ADC_BLOCK_INCLUDEFILE "ports/esp32/machine_adc_block.c"
Damien Georgebc08c882016-12-06 12:20:10 +1100132#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new
Jim Mussared71f4faa2021-08-11 14:26:23 +1000133#define MICROPY_PY_MACHINE_BITSTREAM (1)
Damien George7d39db22023-11-22 13:00:02 +1100134#define MICROPY_PY_MACHINE_DHT_READINTO (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100135#define MICROPY_PY_MACHINE_PULSE (1)
Damien Georgeaf64c2d2021-06-24 12:37:50 +1000136#define MICROPY_PY_MACHINE_PWM (1)
Damien Georgeaf64c2d2021-06-24 12:37:50 +1000137#define MICROPY_PY_MACHINE_PWM_DUTY (1)
138#define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/esp32/machine_pwm.c"
Damien Georgebc08c882016-12-06 12:20:10 +1100139#define MICROPY_PY_MACHINE_I2C (1)
Damien George6bda80d2022-06-01 11:58:30 +1000140#define MICROPY_PY_MACHINE_I2C_TRANSFER_WRITE1 (1)
Damien George122d9012021-09-02 12:37:00 +1000141#define MICROPY_PY_MACHINE_SOFTI2C (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100142#define MICROPY_PY_MACHINE_SPI (1)
Damien Georgeafe06342021-09-02 12:39:28 +1000143#define MICROPY_PY_MACHINE_SOFTSPI (1)
Damien George1f9243f2021-07-18 12:11:10 +1000144#ifndef MICROPY_PY_MACHINE_DAC
IhorNehrutsa495be712023-11-12 20:46:26 +0200145#define MICROPY_PY_MACHINE_DAC (SOC_DAC_SUPPORTED)
Damien George1f9243f2021-07-18 12:11:10 +1000146#endif
Damien George0fc0cca2021-07-18 12:11:15 +1000147#ifndef MICROPY_PY_MACHINE_I2S
Ihor Nehrutsa3069fee2023-11-13 14:07:59 +0200148#define MICROPY_PY_MACHINE_I2S (SOC_I2S_SUPPORTED)
Damien George0fc0cca2021-07-18 12:11:15 +1000149#endif
Damien Georgef2f3ef12023-10-09 12:12:18 +1100150#define MICROPY_PY_MACHINE_I2S_INCLUDEFILE "ports/esp32/machine_i2s.c"
151#define MICROPY_PY_MACHINE_I2S_FINALISER (1)
MikeTeachman0b145fd2024-02-20 21:37:30 -0800152#define MICROPY_PY_MACHINE_I2S_CONSTANT_RX (I2S_DIR_RX)
153#define MICROPY_PY_MACHINE_I2S_CONSTANT_TX (I2S_DIR_TX)
Damien George5b4a2ba2023-10-10 23:46:07 +1100154#define MICROPY_PY_MACHINE_UART (1)
155#define MICROPY_PY_MACHINE_UART_INCLUDEFILE "ports/esp32/machine_uart.c"
156#define MICROPY_PY_MACHINE_UART_SENDBREAK (1)
robert-hha04a1412024-03-10 15:14:20 +0100157#define MICROPY_PY_MACHINE_UART_IRQ (1)
Damien George60929ec2023-10-10 18:19:03 +1100158#define MICROPY_PY_MACHINE_WDT (1)
159#define MICROPY_PY_MACHINE_WDT_INCLUDEFILE "ports/esp32/machine_wdt.c"
Jim Mussaredeb51ca42023-02-01 14:20:45 +1100160#define MICROPY_PY_NETWORK (1)
161#ifndef MICROPY_PY_NETWORK_HOSTNAME_DEFAULT
162#if CONFIG_IDF_TARGET_ESP32
163#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32"
164#elif CONFIG_IDF_TARGET_ESP32S2
165#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32s2"
166#elif CONFIG_IDF_TARGET_ESP32S3
167#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32s3"
168#elif CONFIG_IDF_TARGET_ESP32C3
169#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32c3"
Andrew Leech6d799372023-06-26 11:53:28 +1000170#elif CONFIG_IDF_TARGET_ESP32C6
171#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32c6"
Jim Mussaredeb51ca42023-02-01 14:20:45 +1100172#endif
173#endif
174#define MICROPY_PY_NETWORK_INCLUDEFILE "ports/esp32/modnetwork.h"
175#define MICROPY_PY_NETWORK_MODULE_GLOBALS_INCLUDEFILE "ports/esp32/modnetwork_globals.h"
Damien Georgeea186de2021-09-22 00:35:46 +1000176#ifndef MICROPY_PY_NETWORK_WLAN
177#define MICROPY_PY_NETWORK_WLAN (1)
178#endif
Damien George66a86a02021-02-18 21:24:34 +1100179#ifndef MICROPY_HW_ENABLE_SDCARD
Nicko van Someren8e3af7d2019-05-04 19:00:35 -0600180#define MICROPY_HW_ENABLE_SDCARD (1)
Damien George66a86a02021-02-18 21:24:34 +1100181#endif
Damien George58ebeca2018-03-09 17:25:58 +1100182#define MICROPY_HW_SOFTSPI_MIN_DELAY (0)
Damien Georgee4650122023-05-09 09:52:54 +1000183#define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (esp_rom_get_cpu_ticks_per_us() * 1000000 / 200) // roughly
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000184#define MICROPY_PY_SSL (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100185#define MICROPY_SSL_MBEDTLS (1)
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000186#define MICROPY_PY_WEBSOCKET (1)
Damien Georgec1d43522018-04-27 23:57:57 +1000187#define MICROPY_PY_WEBREPL (1)
Damien Georged41f6dd2021-09-02 12:39:50 +1000188#define MICROPY_PY_ONEWIRE (1)
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000189#define MICROPY_PY_SOCKET_EVENTS (MICROPY_PY_WEBREPL)
Jim Mussared6a9bd1c2019-10-01 23:47:37 +1000190#define MICROPY_PY_BLUETOOTH_RANDOM_ADDR (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100191
192// fatfs configuration
193#define MICROPY_FATFS_ENABLE_LFN (1)
194#define MICROPY_FATFS_RPATH (2)
195#define MICROPY_FATFS_MAX_SS (4096)
Damien Georgeb5f33ac2019-02-25 23:46:17 +1100196#define MICROPY_FATFS_LFN_CODE_PAGE 437 /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
Damien Georgebc08c882016-12-06 12:20:10 +1100197
dotnfcd7f63f92023-09-12 17:15:27 +0800198// task size
199#ifndef MICROPY_TASK_STACK_SIZE
200#define MICROPY_TASK_STACK_SIZE (16 * 1024)
201#endif
202
Damien Georgebc08c882016-12-06 12:20:10 +1100203#define MP_STATE_PORT MP_STATE_VM
204
Andrew Leech42479212024-05-23 17:23:41 +1000205#ifndef MICROPY_HW_ENABLE_USBDEV
206#define MICROPY_HW_ENABLE_USBDEV (SOC_USB_OTG_SUPPORTED)
207#endif
208
209#if MICROPY_HW_ENABLE_USBDEV
Andrew Leech5ae622e2024-05-23 22:08:12 +1000210#define MICROPY_SCHEDULER_STATIC_NODES (1)
211#define MICROPY_HW_USB_CDC_DTR_RTS_BOOTLOADER (1)
Andrew Leech42479212024-05-23 17:23:41 +1000212
213#ifndef MICROPY_HW_USB_VID
214#define USB_ESPRESSIF_VID 0x303A
215#if CONFIG_TINYUSB_DESC_USE_ESPRESSIF_VID
216#define MICROPY_HW_USB_VID (USB_ESPRESSIF_VID)
217#else
218#define MICROPY_HW_USB_VID (CONFIG_TINYUSB_DESC_CUSTOM_VID)
219#endif
Sebastian Romero5f2d05d2024-12-04 16:30:56 +0100220
221#ifndef MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
222#define MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE (1) // Support machine.USBDevice
223#endif
Andrew Leech42479212024-05-23 17:23:41 +1000224#endif
225
226#ifndef MICROPY_HW_USB_PID
227#if CONFIG_TINYUSB_DESC_USE_DEFAULT_PID
228#define _PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
229// A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
230// Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
231// Auto ProductID layout's Bitmap:
232// [MSB] HID | MSC | CDC [LSB]
233#define USB_TUSB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
234 _PID_MAP(MIDI, 3)) // | _PID_MAP(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
235#define MICROPY_HW_USB_PID (USB_TUSB_PID)
236#else
237#define MICROPY_HW_USB_PID (CONFIG_TINYUSB_DESC_CUSTOM_PID)
238#endif
239#endif
240
241#ifndef MICROPY_HW_USB_MANUFACTURER_STRING
242#ifdef CONFIG_TINYUSB_DESC_MANUFACTURER_STRING
243#define MICROPY_HW_USB_MANUFACTURER_STRING CONFIG_TINYUSB_DESC_MANUFACTURER_STRING
244#else
245#define MICROPY_HW_USB_MANUFACTURER_STRING "MicroPython"
246#endif
247#endif
248
249#ifndef MICROPY_HW_USB_PRODUCT_FS_STRING
250#ifdef CONFIG_TINYUSB_DESC_PRODUCT_STRING
251#define MICROPY_HW_USB_PRODUCT_FS_STRING CONFIG_TINYUSB_DESC_PRODUCT_STRING
252#else
253#define MICROPY_HW_USB_PRODUCT_FS_STRING "Board in FS mode"
254#endif
255#endif
256
257#endif // MICROPY_HW_ENABLE_USBDEV
258
259// Enable stdio over native USB peripheral CDC via TinyUSB
260#ifndef MICROPY_HW_USB_CDC
261#define MICROPY_HW_USB_CDC (MICROPY_HW_ENABLE_USBDEV)
262#endif
263
264// Enable stdio over USB Serial/JTAG peripheral
265#ifndef MICROPY_HW_ESP_USB_SERIAL_JTAG
266#define MICROPY_HW_ESP_USB_SERIAL_JTAG (SOC_USB_SERIAL_JTAG_SUPPORTED && !MICROPY_HW_USB_CDC)
267#endif
268
269#if MICROPY_HW_USB_CDC && MICROPY_HW_ESP_USB_SERIAL_JTAG
270#error "Invalid build config: Can't enable both native USB and USB Serial/JTAG peripheral"
271#endif
272
Damien Georgebc08c882016-12-06 12:20:10 +1100273// type definitions for the specific machine
274
Damien George69661f32020-02-27 15:36:53 +1100275#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p)))
Andrew Leech55dc4822024-10-08 17:19:34 +1100276#if SOC_CPU_IDRAM_SPLIT_USING_PMP && !CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT
277// On targets with this configuration all RAM is executable so no need for a custom commit function.
278#else
Damien George69661f32020-02-27 15:36:53 +1100279void *esp_native_code_commit(void *, size_t, void *);
Damien Georgeb47e1552019-10-06 23:29:40 +1100280#define MP_PLAT_COMMIT_EXEC(buf, len, reloc) esp_native_code_commit(buf, len, reloc)
Andrew Leech55dc4822024-10-08 17:19:34 +1100281#endif
Damien Georgebc08c882016-12-06 12:20:10 +1100282#define MP_SSIZE_MAX (0x7fffffff)
283
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000284#if MICROPY_PY_SOCKET_EVENTS
285#define MICROPY_PY_SOCKET_EVENTS_HANDLER extern void socket_events_handler(void); socket_events_handler();
Damien George999c8b92018-04-27 23:53:45 +1000286#else
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000287#define MICROPY_PY_SOCKET_EVENTS_HANDLER
Damien George999c8b92018-04-27 23:53:45 +1000288#endif
289
Damien Georgebc08c882016-12-06 12:20:10 +1100290#if MICROPY_PY_THREAD
291#define MICROPY_EVENT_POLL_HOOK \
292 do { \
Damien George98a39112020-02-06 01:05:47 +1100293 extern void mp_handle_pending(bool); \
294 mp_handle_pending(true); \
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000295 MICROPY_PY_SOCKET_EVENTS_HANDLER \
Damien Georgebc08c882016-12-06 12:20:10 +1100296 MP_THREAD_GIL_EXIT(); \
Daniƫl van de Giessen665f0e22022-02-23 17:28:32 +0100297 ulTaskNotifyTake(pdFALSE, 1); \
Damien Georgebc08c882016-12-06 12:20:10 +1100298 MP_THREAD_GIL_ENTER(); \
299 } while (0);
300#else
Alessandro Gatti82e382a2024-12-04 12:30:25 +0100301#if CONFIG_IDF_TARGET_ARCH_RISCV
302#define MICROPY_PY_WAIT_FOR_INTERRUPT asm volatile ("wfi\n")
303#else
304#define MICROPY_PY_WAIT_FOR_INTERRUPT asm volatile ("waiti 0\n")
305#endif
Damien Georgebc08c882016-12-06 12:20:10 +1100306#define MICROPY_EVENT_POLL_HOOK \
307 do { \
Damien George98a39112020-02-06 01:05:47 +1100308 extern void mp_handle_pending(bool); \
309 mp_handle_pending(true); \
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000310 MICROPY_PY_SOCKET_EVENTS_HANDLER \
Alessandro Gatti82e382a2024-12-04 12:30:25 +0100311 MICROPY_PY_WAIT_FOR_INTERRUPT; \
Damien Georgebc08c882016-12-06 12:20:10 +1100312 } while (0);
313#endif
314
Damien Georgef4641b22020-02-07 12:11:22 +1100315// Functions that should go in IRAM
Damien Georgeb4b77c12023-12-11 12:01:09 +1100316// For ESP32 with SPIRAM workaround, firmware is larger and uses more static IRAM,
317// so in that configuration don't put too many functions in IRAM.
318#if !(CONFIG_IDF_TARGET_ESP32 && CONFIG_SPIRAM && CONFIG_SPIRAM_CACHE_WORKAROUND)
Damien George549448e2021-09-24 12:50:59 +1000319#define MICROPY_WRAP_MP_BINARY_OP(f) IRAM_ATTR f
Damien Georgeb4b77c12023-12-11 12:01:09 +1100320#endif
Damien George549448e2021-09-24 12:50:59 +1000321#define MICROPY_WRAP_MP_EXECUTE_BYTECODE(f) IRAM_ATTR f
322#define MICROPY_WRAP_MP_LOAD_GLOBAL(f) IRAM_ATTR f
323#define MICROPY_WRAP_MP_LOAD_NAME(f) IRAM_ATTR f
324#define MICROPY_WRAP_MP_MAP_LOOKUP(f) IRAM_ATTR f
325#define MICROPY_WRAP_MP_OBJ_GET_TYPE(f) IRAM_ATTR f
Damien George7cbf8262021-04-28 10:52:19 +1000326#define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) IRAM_ATTR f
Damien Georgee9e9c762021-04-28 10:57:34 +1000327#define MICROPY_WRAP_MP_SCHED_KEYBOARD_INTERRUPT(f) IRAM_ATTR f
Damien Georgef4641b22020-02-07 12:11:22 +1100328
Damien Georgebc08c882016-12-06 12:20:10 +1100329#define UINT_FMT "%u"
330#define INT_FMT "%d"
331
332typedef int32_t mp_int_t; // must be pointer size
333typedef uint32_t mp_uint_t; // must be pointer size
334typedef long mp_off_t;
335// ssize_t, off_t as required by POSIX-signatured functions in stream.h
336#include <sys/types.h>
337
338// board specifics
Damien Georgebc08c882016-12-06 12:20:10 +1100339#define MICROPY_PY_SYS_PLATFORM "esp32"
Damien George2ccf0302019-07-10 15:38:48 +1000340
Seon Rozenblum19048332021-11-12 11:23:49 +1100341// ESP32-S3 extended IO for 47 & 48
342#ifndef MICROPY_HW_ESP32S3_EXTENDED_IO
343#define MICROPY_HW_ESP32S3_EXTENDED_IO (1)
344#endif
345
Damien George2ccf0302019-07-10 15:38:48 +1000346#ifndef MICROPY_HW_ENABLE_MDNS_QUERIES
Carlosgg1f355762023-06-25 22:48:39 +0100347#define MICROPY_HW_ENABLE_MDNS_QUERIES (1)
Damien George2ccf0302019-07-10 15:38:48 +1000348#endif
349
350#ifndef MICROPY_HW_ENABLE_MDNS_RESPONDER
Carlosgg1f355762023-06-25 22:48:39 +0100351#define MICROPY_HW_ENABLE_MDNS_RESPONDER (1)
Damien George2ccf0302019-07-10 15:38:48 +1000352#endif
Damien Georgef046b502021-09-22 00:00:26 +1000353
Trent Piephoaf67be72024-03-02 01:25:10 -0800354#ifndef MICROPY_BOARD_ENTER_BOOTLOADER
355// RTC has a register to trigger bootloader on these targets
356#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3
357#define MICROPY_ESP32_USE_BOOTLOADER_RTC (1)
358#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) machine_bootloader_rtc()
359#endif
360#endif
361
Trent Piepho9fc45062024-03-02 01:10:20 -0800362#ifdef MICROPY_BOARD_ENTER_BOOTLOADER
363#define MICROPY_PY_MACHINE_BOOTLOADER (1)
364#else
365#define MICROPY_PY_MACHINE_BOOTLOADER (0)
Luca Burelli904ccfa2023-07-04 11:54:53 +0200366#endif
367
Angus Gratton6fead312024-07-25 12:11:32 +1000368// Workaround for upstream bug https://github.com/espressif/esp-idf/issues/14273
369// Can be removed if a fix is available in supported ESP-IDF versions.
370#define MICROPY_PY_MATH_GAMMA_FIX_NEGINF (1)
371
Damien Georgef046b502021-09-22 00:00:26 +1000372#ifndef MICROPY_BOARD_STARTUP
373#define MICROPY_BOARD_STARTUP boardctrl_startup
374#endif
375
376void boardctrl_startup(void);
Damien Tournoude982c1d2023-01-12 21:04:07 -0800377
378#ifndef MICROPY_PY_NETWORK_LAN
Damien Georgee4650122023-05-09 09:52:54 +1000379#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 -0800380#define MICROPY_PY_NETWORK_LAN (1)
381#else
382#define MICROPY_PY_NETWORK_LAN (0)
383#endif
384#endif
385
386#if MICROPY_PY_NETWORK_LAN && CONFIG_ETH_USE_SPI_ETHERNET
387#ifndef MICROPY_PY_NETWORK_LAN_SPI_CLOCK_SPEED_MZ
Andrew Leech6d799372023-06-26 11:53:28 +1000388#define MICROPY_PY_NETWORK_LAN_SPI_CLOCK_SPEED_MZ (20)
Damien Tournoude982c1d2023-01-12 21:04:07 -0800389#endif
390#endif
Alessandro Gatti0b75e182024-08-10 16:37:03 +0200391
392// The minimum string length threshold for string printing to stdout operations to be GIL-aware.
393#ifndef MICROPY_PY_STRING_TX_GIL_THRESHOLD
394#define MICROPY_PY_STRING_TX_GIL_THRESHOLD (20)
395#endif
Alessandro Gatti883dc412025-03-25 22:43:23 +0100396
397// Code can override this to provide a custom ESP-IDF entry point.
398#ifndef MICROPY_ESP_IDF_ENTRY
399#define MICROPY_ESP_IDF_ENTRY app_main
400#endif