blob: 35c8ff1831dbfccb1d5bc66820375341c8d4182e [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)
127#define MICROPY_PY_MACHINE_ADC_READ (1)
128#define MICROPY_PY_MACHINE_ADC_READ_UV (1)
Damien George03eae482023-10-25 19:13:11 +1100129#define MICROPY_PY_MACHINE_ADC_BLOCK (1)
130#define MICROPY_PY_MACHINE_ADC_BLOCK_INCLUDEFILE "ports/esp32/machine_adc_block.c"
Damien Georgebc08c882016-12-06 12:20:10 +1100131#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new
Jim Mussared71f4faa2021-08-11 14:26:23 +1000132#define MICROPY_PY_MACHINE_BITSTREAM (1)
Damien George7d39db22023-11-22 13:00:02 +1100133#define MICROPY_PY_MACHINE_DHT_READINTO (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100134#define MICROPY_PY_MACHINE_PULSE (1)
Damien Georgeaf64c2d2021-06-24 12:37:50 +1000135#define MICROPY_PY_MACHINE_PWM (1)
Damien Georgeaf64c2d2021-06-24 12:37:50 +1000136#define MICROPY_PY_MACHINE_PWM_DUTY (1)
137#define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/esp32/machine_pwm.c"
Damien Georgebc08c882016-12-06 12:20:10 +1100138#define MICROPY_PY_MACHINE_I2C (1)
Damien George6bda80d2022-06-01 11:58:30 +1000139#define MICROPY_PY_MACHINE_I2C_TRANSFER_WRITE1 (1)
Damien George122d9012021-09-02 12:37:00 +1000140#define MICROPY_PY_MACHINE_SOFTI2C (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100141#define MICROPY_PY_MACHINE_SPI (1)
Damien Georgeafe06342021-09-02 12:39:28 +1000142#define MICROPY_PY_MACHINE_SOFTSPI (1)
Damien George1f9243f2021-07-18 12:11:10 +1000143#ifndef MICROPY_PY_MACHINE_DAC
IhorNehrutsa495be712023-11-12 20:46:26 +0200144#define MICROPY_PY_MACHINE_DAC (SOC_DAC_SUPPORTED)
Damien George1f9243f2021-07-18 12:11:10 +1000145#endif
Damien George0fc0cca2021-07-18 12:11:15 +1000146#ifndef MICROPY_PY_MACHINE_I2S
Ihor Nehrutsa3069fee2023-11-13 14:07:59 +0200147#define MICROPY_PY_MACHINE_I2S (SOC_I2S_SUPPORTED)
Damien George0fc0cca2021-07-18 12:11:15 +1000148#endif
Damien Georgef2f3ef12023-10-09 12:12:18 +1100149#define MICROPY_PY_MACHINE_I2S_INCLUDEFILE "ports/esp32/machine_i2s.c"
150#define MICROPY_PY_MACHINE_I2S_FINALISER (1)
MikeTeachman0b145fd2024-02-20 21:37:30 -0800151#define MICROPY_PY_MACHINE_I2S_CONSTANT_RX (I2S_DIR_RX)
152#define MICROPY_PY_MACHINE_I2S_CONSTANT_TX (I2S_DIR_TX)
Damien George5b4a2ba2023-10-10 23:46:07 +1100153#define MICROPY_PY_MACHINE_UART (1)
154#define MICROPY_PY_MACHINE_UART_INCLUDEFILE "ports/esp32/machine_uart.c"
155#define MICROPY_PY_MACHINE_UART_SENDBREAK (1)
robert-hha04a1412024-03-10 15:14:20 +0100156#define MICROPY_PY_MACHINE_UART_IRQ (1)
Damien George60929ec2023-10-10 18:19:03 +1100157#define MICROPY_PY_MACHINE_WDT (1)
158#define MICROPY_PY_MACHINE_WDT_INCLUDEFILE "ports/esp32/machine_wdt.c"
Jim Mussaredeb51ca42023-02-01 14:20:45 +1100159#define MICROPY_PY_NETWORK (1)
160#ifndef MICROPY_PY_NETWORK_HOSTNAME_DEFAULT
161#if CONFIG_IDF_TARGET_ESP32
162#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32"
163#elif CONFIG_IDF_TARGET_ESP32S2
164#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32s2"
165#elif CONFIG_IDF_TARGET_ESP32S3
166#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32s3"
167#elif CONFIG_IDF_TARGET_ESP32C3
168#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32c3"
Andrew Leech6d799372023-06-26 11:53:28 +1000169#elif CONFIG_IDF_TARGET_ESP32C6
170#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32c6"
Jim Mussaredeb51ca42023-02-01 14:20:45 +1100171#endif
172#endif
173#define MICROPY_PY_NETWORK_INCLUDEFILE "ports/esp32/modnetwork.h"
174#define MICROPY_PY_NETWORK_MODULE_GLOBALS_INCLUDEFILE "ports/esp32/modnetwork_globals.h"
Damien Georgeea186de2021-09-22 00:35:46 +1000175#ifndef MICROPY_PY_NETWORK_WLAN
176#define MICROPY_PY_NETWORK_WLAN (1)
177#endif
Damien George66a86a02021-02-18 21:24:34 +1100178#ifndef MICROPY_HW_ENABLE_SDCARD
Nicko van Someren8e3af7d2019-05-04 19:00:35 -0600179#define MICROPY_HW_ENABLE_SDCARD (1)
Damien George66a86a02021-02-18 21:24:34 +1100180#endif
Damien George58ebeca2018-03-09 17:25:58 +1100181#define MICROPY_HW_SOFTSPI_MIN_DELAY (0)
Damien Georgee4650122023-05-09 09:52:54 +1000182#define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (esp_rom_get_cpu_ticks_per_us() * 1000000 / 200) // roughly
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000183#define MICROPY_PY_SSL (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100184#define MICROPY_SSL_MBEDTLS (1)
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000185#define MICROPY_PY_WEBSOCKET (1)
Damien Georgec1d43522018-04-27 23:57:57 +1000186#define MICROPY_PY_WEBREPL (1)
Damien Georged41f6dd2021-09-02 12:39:50 +1000187#define MICROPY_PY_ONEWIRE (1)
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000188#define MICROPY_PY_SOCKET_EVENTS (MICROPY_PY_WEBREPL)
Jim Mussared6a9bd1c2019-10-01 23:47:37 +1000189#define MICROPY_PY_BLUETOOTH_RANDOM_ADDR (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100190
191// fatfs configuration
192#define MICROPY_FATFS_ENABLE_LFN (1)
193#define MICROPY_FATFS_RPATH (2)
194#define MICROPY_FATFS_MAX_SS (4096)
Damien Georgeb5f33ac2019-02-25 23:46:17 +1100195#define MICROPY_FATFS_LFN_CODE_PAGE 437 /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
Damien Georgebc08c882016-12-06 12:20:10 +1100196
dotnfcd7f63f92023-09-12 17:15:27 +0800197// task size
198#ifndef MICROPY_TASK_STACK_SIZE
199#define MICROPY_TASK_STACK_SIZE (16 * 1024)
200#endif
201
Damien Georgebc08c882016-12-06 12:20:10 +1100202#define MP_STATE_PORT MP_STATE_VM
203
Andrew Leech42479212024-05-23 17:23:41 +1000204#ifndef MICROPY_HW_ENABLE_USBDEV
205#define MICROPY_HW_ENABLE_USBDEV (SOC_USB_OTG_SUPPORTED)
206#endif
207
208#if MICROPY_HW_ENABLE_USBDEV
Andrew Leech5ae622e2024-05-23 22:08:12 +1000209#define MICROPY_SCHEDULER_STATIC_NODES (1)
210#define MICROPY_HW_USB_CDC_DTR_RTS_BOOTLOADER (1)
Andrew Leech42479212024-05-23 17:23:41 +1000211
212#ifndef MICROPY_HW_USB_VID
213#define USB_ESPRESSIF_VID 0x303A
214#if CONFIG_TINYUSB_DESC_USE_ESPRESSIF_VID
215#define MICROPY_HW_USB_VID (USB_ESPRESSIF_VID)
216#else
217#define MICROPY_HW_USB_VID (CONFIG_TINYUSB_DESC_CUSTOM_VID)
218#endif
Sebastian Romero5f2d05d2024-12-04 16:30:56 +0100219
220#ifndef MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
221#define MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE (1) // Support machine.USBDevice
222#endif
Andrew Leech42479212024-05-23 17:23:41 +1000223#endif
224
225#ifndef MICROPY_HW_USB_PID
226#if CONFIG_TINYUSB_DESC_USE_DEFAULT_PID
227#define _PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
228// A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
229// Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
230// Auto ProductID layout's Bitmap:
231// [MSB] HID | MSC | CDC [LSB]
232#define USB_TUSB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
233 _PID_MAP(MIDI, 3)) // | _PID_MAP(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
234#define MICROPY_HW_USB_PID (USB_TUSB_PID)
235#else
236#define MICROPY_HW_USB_PID (CONFIG_TINYUSB_DESC_CUSTOM_PID)
237#endif
238#endif
239
240#ifndef MICROPY_HW_USB_MANUFACTURER_STRING
241#ifdef CONFIG_TINYUSB_DESC_MANUFACTURER_STRING
242#define MICROPY_HW_USB_MANUFACTURER_STRING CONFIG_TINYUSB_DESC_MANUFACTURER_STRING
243#else
244#define MICROPY_HW_USB_MANUFACTURER_STRING "MicroPython"
245#endif
246#endif
247
248#ifndef MICROPY_HW_USB_PRODUCT_FS_STRING
249#ifdef CONFIG_TINYUSB_DESC_PRODUCT_STRING
250#define MICROPY_HW_USB_PRODUCT_FS_STRING CONFIG_TINYUSB_DESC_PRODUCT_STRING
251#else
252#define MICROPY_HW_USB_PRODUCT_FS_STRING "Board in FS mode"
253#endif
254#endif
255
256#endif // MICROPY_HW_ENABLE_USBDEV
257
258// Enable stdio over native USB peripheral CDC via TinyUSB
259#ifndef MICROPY_HW_USB_CDC
260#define MICROPY_HW_USB_CDC (MICROPY_HW_ENABLE_USBDEV)
261#endif
262
263// Enable stdio over USB Serial/JTAG peripheral
264#ifndef MICROPY_HW_ESP_USB_SERIAL_JTAG
265#define MICROPY_HW_ESP_USB_SERIAL_JTAG (SOC_USB_SERIAL_JTAG_SUPPORTED && !MICROPY_HW_USB_CDC)
266#endif
267
268#if MICROPY_HW_USB_CDC && MICROPY_HW_ESP_USB_SERIAL_JTAG
269#error "Invalid build config: Can't enable both native USB and USB Serial/JTAG peripheral"
270#endif
271
Damien Georgebc08c882016-12-06 12:20:10 +1100272// type definitions for the specific machine
273
Damien George69661f32020-02-27 15:36:53 +1100274#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p)))
Andrew Leech55dc4822024-10-08 17:19:34 +1100275#if SOC_CPU_IDRAM_SPLIT_USING_PMP && !CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT
276// On targets with this configuration all RAM is executable so no need for a custom commit function.
277#else
Damien George69661f32020-02-27 15:36:53 +1100278void *esp_native_code_commit(void *, size_t, void *);
Damien Georgeb47e1552019-10-06 23:29:40 +1100279#define MP_PLAT_COMMIT_EXEC(buf, len, reloc) esp_native_code_commit(buf, len, reloc)
Andrew Leech55dc4822024-10-08 17:19:34 +1100280#endif
Damien Georgebc08c882016-12-06 12:20:10 +1100281#define MP_SSIZE_MAX (0x7fffffff)
282
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000283#if MICROPY_PY_SOCKET_EVENTS
284#define MICROPY_PY_SOCKET_EVENTS_HANDLER extern void socket_events_handler(void); socket_events_handler();
Damien George999c8b92018-04-27 23:53:45 +1000285#else
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000286#define MICROPY_PY_SOCKET_EVENTS_HANDLER
Damien George999c8b92018-04-27 23:53:45 +1000287#endif
288
Damien Georgebc08c882016-12-06 12:20:10 +1100289#if MICROPY_PY_THREAD
290#define MICROPY_EVENT_POLL_HOOK \
291 do { \
Damien George98a39112020-02-06 01:05:47 +1100292 extern void mp_handle_pending(bool); \
293 mp_handle_pending(true); \
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000294 MICROPY_PY_SOCKET_EVENTS_HANDLER \
Damien Georgebc08c882016-12-06 12:20:10 +1100295 MP_THREAD_GIL_EXIT(); \
Daniƫl van de Giessen665f0e22022-02-23 17:28:32 +0100296 ulTaskNotifyTake(pdFALSE, 1); \
Damien Georgebc08c882016-12-06 12:20:10 +1100297 MP_THREAD_GIL_ENTER(); \
298 } while (0);
299#else
Alessandro Gatti82e382a2024-12-04 12:30:25 +0100300#if CONFIG_IDF_TARGET_ARCH_RISCV
301#define MICROPY_PY_WAIT_FOR_INTERRUPT asm volatile ("wfi\n")
302#else
303#define MICROPY_PY_WAIT_FOR_INTERRUPT asm volatile ("waiti 0\n")
304#endif
Damien Georgebc08c882016-12-06 12:20:10 +1100305#define MICROPY_EVENT_POLL_HOOK \
306 do { \
Damien George98a39112020-02-06 01:05:47 +1100307 extern void mp_handle_pending(bool); \
308 mp_handle_pending(true); \
Jim Mussaredf5f9edf2022-08-18 15:01:26 +1000309 MICROPY_PY_SOCKET_EVENTS_HANDLER \
Alessandro Gatti82e382a2024-12-04 12:30:25 +0100310 MICROPY_PY_WAIT_FOR_INTERRUPT; \
Damien Georgebc08c882016-12-06 12:20:10 +1100311 } while (0);
312#endif
313
Damien Georgef4641b22020-02-07 12:11:22 +1100314// Functions that should go in IRAM
Damien Georgeb4b77c12023-12-11 12:01:09 +1100315// For ESP32 with SPIRAM workaround, firmware is larger and uses more static IRAM,
316// so in that configuration don't put too many functions in IRAM.
317#if !(CONFIG_IDF_TARGET_ESP32 && CONFIG_SPIRAM && CONFIG_SPIRAM_CACHE_WORKAROUND)
Damien George549448e2021-09-24 12:50:59 +1000318#define MICROPY_WRAP_MP_BINARY_OP(f) IRAM_ATTR f
Damien Georgeb4b77c12023-12-11 12:01:09 +1100319#endif
Damien George549448e2021-09-24 12:50:59 +1000320#define MICROPY_WRAP_MP_EXECUTE_BYTECODE(f) IRAM_ATTR f
321#define MICROPY_WRAP_MP_LOAD_GLOBAL(f) IRAM_ATTR f
322#define MICROPY_WRAP_MP_LOAD_NAME(f) IRAM_ATTR f
323#define MICROPY_WRAP_MP_MAP_LOOKUP(f) IRAM_ATTR f
324#define MICROPY_WRAP_MP_OBJ_GET_TYPE(f) IRAM_ATTR f
Damien George7cbf8262021-04-28 10:52:19 +1000325#define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) IRAM_ATTR f
Damien Georgee9e9c762021-04-28 10:57:34 +1000326#define MICROPY_WRAP_MP_SCHED_KEYBOARD_INTERRUPT(f) IRAM_ATTR f
Damien Georgef4641b22020-02-07 12:11:22 +1100327
Damien Georgebc08c882016-12-06 12:20:10 +1100328#define UINT_FMT "%u"
329#define INT_FMT "%d"
330
331typedef int32_t mp_int_t; // must be pointer size
332typedef uint32_t mp_uint_t; // must be pointer size
333typedef long mp_off_t;
334// ssize_t, off_t as required by POSIX-signatured functions in stream.h
335#include <sys/types.h>
336
337// board specifics
Damien Georgebc08c882016-12-06 12:20:10 +1100338#define MICROPY_PY_SYS_PLATFORM "esp32"
Damien George2ccf0302019-07-10 15:38:48 +1000339
Seon Rozenblum19048332021-11-12 11:23:49 +1100340// ESP32-S3 extended IO for 47 & 48
341#ifndef MICROPY_HW_ESP32S3_EXTENDED_IO
342#define MICROPY_HW_ESP32S3_EXTENDED_IO (1)
343#endif
344
Damien George2ccf0302019-07-10 15:38:48 +1000345#ifndef MICROPY_HW_ENABLE_MDNS_QUERIES
Carlosgg1f355762023-06-25 22:48:39 +0100346#define MICROPY_HW_ENABLE_MDNS_QUERIES (1)
Damien George2ccf0302019-07-10 15:38:48 +1000347#endif
348
349#ifndef MICROPY_HW_ENABLE_MDNS_RESPONDER
Carlosgg1f355762023-06-25 22:48:39 +0100350#define MICROPY_HW_ENABLE_MDNS_RESPONDER (1)
Damien George2ccf0302019-07-10 15:38:48 +1000351#endif
Damien Georgef046b502021-09-22 00:00:26 +1000352
Trent Piephoaf67be72024-03-02 01:25:10 -0800353#ifndef MICROPY_BOARD_ENTER_BOOTLOADER
354// RTC has a register to trigger bootloader on these targets
355#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3
356#define MICROPY_ESP32_USE_BOOTLOADER_RTC (1)
357#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) machine_bootloader_rtc()
358#endif
359#endif
360
Trent Piepho9fc45062024-03-02 01:10:20 -0800361#ifdef MICROPY_BOARD_ENTER_BOOTLOADER
362#define MICROPY_PY_MACHINE_BOOTLOADER (1)
363#else
364#define MICROPY_PY_MACHINE_BOOTLOADER (0)
Luca Burelli904ccfa2023-07-04 11:54:53 +0200365#endif
366
Angus Gratton6fead312024-07-25 12:11:32 +1000367// Workaround for upstream bug https://github.com/espressif/esp-idf/issues/14273
368// Can be removed if a fix is available in supported ESP-IDF versions.
369#define MICROPY_PY_MATH_GAMMA_FIX_NEGINF (1)
370
Damien Georgef046b502021-09-22 00:00:26 +1000371#ifndef MICROPY_BOARD_STARTUP
372#define MICROPY_BOARD_STARTUP boardctrl_startup
373#endif
374
375void boardctrl_startup(void);
Damien Tournoude982c1d2023-01-12 21:04:07 -0800376
377#ifndef MICROPY_PY_NETWORK_LAN
Damien Georgee4650122023-05-09 09:52:54 +1000378#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 -0800379#define MICROPY_PY_NETWORK_LAN (1)
380#else
381#define MICROPY_PY_NETWORK_LAN (0)
382#endif
383#endif
384
385#if MICROPY_PY_NETWORK_LAN && CONFIG_ETH_USE_SPI_ETHERNET
386#ifndef MICROPY_PY_NETWORK_LAN_SPI_CLOCK_SPEED_MZ
Andrew Leech6d799372023-06-26 11:53:28 +1000387#define MICROPY_PY_NETWORK_LAN_SPI_CLOCK_SPEED_MZ (20)
Damien Tournoude982c1d2023-01-12 21:04:07 -0800388#endif
389#endif
Alessandro Gatti0b75e182024-08-10 16:37:03 +0200390
391// The minimum string length threshold for string printing to stdout operations to be GIL-aware.
392#ifndef MICROPY_PY_STRING_TX_GIL_THRESHOLD
393#define MICROPY_PY_STRING_TX_GIL_THRESHOLD (20)
394#endif
Alessandro Gatti883dc412025-03-25 22:43:23 +0100395
396// Code can override this to provide a custom ESP-IDF entry point.
397#ifndef MICROPY_ESP_IDF_ENTRY
398#define MICROPY_ESP_IDF_ENTRY app_main
399#endif