Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 1 | // Options to control how MicroPython is built for this port, |
| 2 | // overriding defaults in py/mpconfig.h. |
| 3 | |
Jim Mussared | 8db517f | 2019-08-09 18:07:50 +1000 | [diff] [blame] | 4 | // Board-specific definitions |
| 5 | #include "mpconfigboard.h" |
| 6 | |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | #include <alloca.h> |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 9 | #include "esp_random.h" |
robert | b406289 | 2020-08-22 20:56:26 +0200 | [diff] [blame] | 10 | #include "esp_system.h" |
MikeTeachman | 6d5296e | 2021-11-09 20:41:34 -0800 | [diff] [blame] | 11 | #include "freertos/FreeRTOS.h" |
MikeTeachman | 0b145fd | 2024-02-20 21:37:30 -0800 | [diff] [blame] | 12 | #include "driver/i2s_std.h" |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 13 | #include "esp_wifi_types.h" |
Jim Mussared | 96008ff | 2019-09-13 23:04:13 +1000 | [diff] [blame] | 14 | |
Damien George | c8cd5a9 | 2022-02-18 15:50:01 +1100 | [diff] [blame] | 15 | #ifndef MICROPY_CONFIG_ROM_LEVEL |
| 16 | #define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES) |
| 17 | #endif |
| 18 | |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 19 | // object representation and NLR handling |
| 20 | #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_A) |
Andrew Leech | 6d79937 | 2023-06-26 11:53:28 +1000 | [diff] [blame] | 21 | #if CONFIG_IDF_TARGET_ARCH_XTENSA |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 22 | #define MICROPY_NLR_SETJMP (1) |
Damien George | 6823514 | 2021-07-18 12:11:21 +1000 | [diff] [blame] | 23 | #endif |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 24 | |
| 25 | // memory allocation policies |
| 26 | #define MICROPY_ALLOC_PATH_MAX (128) |
| 27 | |
Damien George | f6d6308 | 2023-12-18 13:38:16 +1100 | [diff] [blame] | 28 | // 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 George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 42 | // emitters |
| 43 | #define MICROPY_PERSISTENT_CODE_LOAD (1) |
Andrew Leech | 6d79937 | 2023-06-26 11:53:28 +1000 | [diff] [blame] | 44 | #if CONFIG_IDF_TARGET_ARCH_RISCV |
Andrew Leech | 55dc482 | 2024-10-08 17:19:34 +1100 | [diff] [blame] | 45 | #if CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT |
| 46 | #define MICROPY_EMIT_RV32 (0) |
| 47 | #else |
Alessandro Gatti | 6007f3e | 2024-07-02 22:49:47 +0200 | [diff] [blame] | 48 | #define MICROPY_EMIT_RV32 (1) |
Andrew Leech | 55dc482 | 2024-10-08 17:19:34 +1100 | [diff] [blame] | 49 | #endif |
Andrew Leech | 6d79937 | 2023-06-26 11:53:28 +1000 | [diff] [blame] | 50 | #else |
| 51 | #define MICROPY_EMIT_XTENSAWIN (1) |
Damien George | 6823514 | 2021-07-18 12:11:21 +1000 | [diff] [blame] | 52 | #endif |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 53 | |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 54 | // optimisations |
Damien George | d0758d8 | 2023-12-11 12:01:40 +1100 | [diff] [blame] | 55 | #ifndef MICROPY_OPT_COMPUTED_GOTO |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 56 | #define MICROPY_OPT_COMPUTED_GOTO (1) |
Damien George | d0758d8 | 2023-12-11 12:01:40 +1100 | [diff] [blame] | 57 | #endif |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 58 | |
| 59 | // Python internal features |
| 60 | #define MICROPY_READER_VFS (1) |
| 61 | #define MICROPY_ENABLE_GC (1) |
Angus Gratton | e3955f4 | 2024-08-06 16:13:33 +1000 | [diff] [blame] | 62 | #define MICROPY_STACK_CHECK_MARGIN (1024) |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 63 | #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 64 | #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) |
IhorNehrutsa | a724545 | 2025-02-19 09:23:04 +0200 | [diff] [blame] | 65 | #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 George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 67 | #define MICROPY_WARNINGS (1) |
| 68 | #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 69 | #define MICROPY_STREAMS_POSIX_API (1) |
Thorsten von Eicken | 902da05 | 2020-11-11 17:46:18 -0800 | [diff] [blame] | 70 | #define MICROPY_USE_INTERNAL_ERRNO (0) // errno.h from xtensa-esp32-elf/sys-include/sys |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 71 | #define MICROPY_USE_INTERNAL_PRINTF (0) // ESP32 SDK requires its own printf |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 72 | #define MICROPY_SCHEDULER_DEPTH (8) |
| 73 | #define MICROPY_VFS (1) |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 74 | |
| 75 | // control over Python builtins |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 76 | #define MICROPY_PY_STR_BYTES_CMP_WARN (1) |
Jim Mussared | bfc8e88 | 2021-08-04 15:35:00 +1000 | [diff] [blame] | 77 | #define MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS (1) |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 78 | #define MICROPY_PY_BUILTINS_HELP_TEXT esp32_help_text |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 79 | #define MICROPY_PY_IO_BUFFEREDWRITER (1) |
Jim Mussared | f5f9edf | 2022-08-18 15:01:26 +1000 | [diff] [blame] | 80 | #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 George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 83 | #define MICROPY_PY_THREAD (1) |
| 84 | #define MICROPY_PY_THREAD_GIL (1) |
| 85 | #define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32) |
| 86 | |
Angus Gratton | 05dcb8b | 2023-08-02 16:51:07 +1000 | [diff] [blame] | 87 | #define MICROPY_GC_SPLIT_HEAP (1) |
| 88 | #define MICROPY_GC_SPLIT_HEAP_AUTO (1) |
| 89 | |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 90 | // extended modules |
Glenn Moloney | 9f835df | 2023-10-10 13:06:59 +1100 | [diff] [blame] | 91 | #ifndef MICROPY_PY_ESPNOW |
| 92 | #define MICROPY_PY_ESPNOW (1) |
Glenn Moloney | 7fa322a | 2020-09-24 15:37:04 +1000 | [diff] [blame] | 93 | #endif |
Damien George | da2b5fa | 2021-02-14 01:36:30 +1100 | [diff] [blame] | 94 | #ifndef MICROPY_PY_BLUETOOTH |
| 95 | #define MICROPY_PY_BLUETOOTH (1) |
Damien George | 5dbb822 | 2021-03-17 12:35:59 +1100 | [diff] [blame] | 96 | #define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS (1) |
| 97 | #define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK (1) |
Angus Gratton | 6565b3c | 2024-08-15 16:00:08 +1000 | [diff] [blame] | 98 | // 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 George | da2b5fa | 2021-02-14 01:36:30 +1100 | [diff] [blame] | 102 | #define MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE (1) |
Damien George | 5dbb822 | 2021-03-17 12:35:59 +1100 | [diff] [blame] | 103 | #define MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING (1) |
Damien George | da2b5fa | 2021-02-14 01:36:30 +1100 | [diff] [blame] | 104 | #define MICROPY_BLUETOOTH_NIMBLE (1) |
| 105 | #define MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY (1) |
| 106 | #endif |
IhorNehrutsa | 5552896 | 2023-12-19 16:28:06 +0200 | [diff] [blame] | 107 | #define MICROPY_PY_HASHLIB_MD5 (1) |
Jim Mussared | f5f9edf | 2022-08-18 15:01:26 +1000 | [diff] [blame] | 108 | #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 Mussared | 45ac651 | 2022-08-18 16:24:27 +1000 | [diff] [blame] | 112 | #define MICROPY_PY_OS_INCLUDEFILE "ports/esp32/modos.c" |
Damien George | 98b05e3 | 2018-04-27 23:51:00 +1000 | [diff] [blame] | 113 | #define MICROPY_PY_OS_DUPTERM (1) |
Jim Mussared | f5f9edf | 2022-08-18 15:01:26 +1000 | [diff] [blame] | 114 | #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 George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 118 | #define MICROPY_PY_MACHINE (1) |
Damien George | 7d39db2 | 2023-11-22 13:00:02 +1100 | [diff] [blame] | 119 | #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/esp32/modmachine.c" |
Damien George | bfc3dde | 2024-03-14 11:09:14 +1100 | [diff] [blame] | 120 | #define MICROPY_PY_MACHINE_RESET (1) |
Damien George | e1ec6af | 2023-11-24 18:25:30 +1100 | [diff] [blame] | 121 | #define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1) |
Damien George | f523b86 | 2023-11-27 11:43:15 +1100 | [diff] [blame] | 122 | #define MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ (1) |
Damien George | 95d8b5f | 2023-10-11 13:48:49 +1100 | [diff] [blame] | 123 | #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 George | 95d8b5f | 2023-10-11 13:48:49 +1100 | [diff] [blame] | 126 | #define MICROPY_PY_MACHINE_ADC_INIT (1) |
purewack | 5f058e9 | 2025-01-02 11:44:00 +0000 | [diff] [blame] | 127 | #define MICROPY_PY_MACHINE_ADC_DEINIT (1) |
Damien George | 95d8b5f | 2023-10-11 13:48:49 +1100 | [diff] [blame] | 128 | #define MICROPY_PY_MACHINE_ADC_READ (1) |
| 129 | #define MICROPY_PY_MACHINE_ADC_READ_UV (1) |
Damien George | 03eae48 | 2023-10-25 19:13:11 +1100 | [diff] [blame] | 130 | #define MICROPY_PY_MACHINE_ADC_BLOCK (1) |
| 131 | #define MICROPY_PY_MACHINE_ADC_BLOCK_INCLUDEFILE "ports/esp32/machine_adc_block.c" |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 132 | #define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new |
Jim Mussared | 71f4faa | 2021-08-11 14:26:23 +1000 | [diff] [blame] | 133 | #define MICROPY_PY_MACHINE_BITSTREAM (1) |
Damien George | 7d39db2 | 2023-11-22 13:00:02 +1100 | [diff] [blame] | 134 | #define MICROPY_PY_MACHINE_DHT_READINTO (1) |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 135 | #define MICROPY_PY_MACHINE_PULSE (1) |
Damien George | af64c2d | 2021-06-24 12:37:50 +1000 | [diff] [blame] | 136 | #define MICROPY_PY_MACHINE_PWM (1) |
Damien George | af64c2d | 2021-06-24 12:37:50 +1000 | [diff] [blame] | 137 | #define MICROPY_PY_MACHINE_PWM_DUTY (1) |
| 138 | #define MICROPY_PY_MACHINE_PWM_INCLUDEFILE "ports/esp32/machine_pwm.c" |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 139 | #define MICROPY_PY_MACHINE_I2C (1) |
Damien George | 6bda80d | 2022-06-01 11:58:30 +1000 | [diff] [blame] | 140 | #define MICROPY_PY_MACHINE_I2C_TRANSFER_WRITE1 (1) |
Damien George | 122d901 | 2021-09-02 12:37:00 +1000 | [diff] [blame] | 141 | #define MICROPY_PY_MACHINE_SOFTI2C (1) |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 142 | #define MICROPY_PY_MACHINE_SPI (1) |
Damien George | afe0634 | 2021-09-02 12:39:28 +1000 | [diff] [blame] | 143 | #define MICROPY_PY_MACHINE_SOFTSPI (1) |
Damien George | 1f9243f | 2021-07-18 12:11:10 +1000 | [diff] [blame] | 144 | #ifndef MICROPY_PY_MACHINE_DAC |
IhorNehrutsa | 495be71 | 2023-11-12 20:46:26 +0200 | [diff] [blame] | 145 | #define MICROPY_PY_MACHINE_DAC (SOC_DAC_SUPPORTED) |
Damien George | 1f9243f | 2021-07-18 12:11:10 +1000 | [diff] [blame] | 146 | #endif |
Damien George | 0fc0cca | 2021-07-18 12:11:15 +1000 | [diff] [blame] | 147 | #ifndef MICROPY_PY_MACHINE_I2S |
Ihor Nehrutsa | 3069fee | 2023-11-13 14:07:59 +0200 | [diff] [blame] | 148 | #define MICROPY_PY_MACHINE_I2S (SOC_I2S_SUPPORTED) |
Damien George | 0fc0cca | 2021-07-18 12:11:15 +1000 | [diff] [blame] | 149 | #endif |
Damien George | f2f3ef1 | 2023-10-09 12:12:18 +1100 | [diff] [blame] | 150 | #define MICROPY_PY_MACHINE_I2S_INCLUDEFILE "ports/esp32/machine_i2s.c" |
| 151 | #define MICROPY_PY_MACHINE_I2S_FINALISER (1) |
MikeTeachman | 0b145fd | 2024-02-20 21:37:30 -0800 | [diff] [blame] | 152 | #define MICROPY_PY_MACHINE_I2S_CONSTANT_RX (I2S_DIR_RX) |
| 153 | #define MICROPY_PY_MACHINE_I2S_CONSTANT_TX (I2S_DIR_TX) |
Damien George | 5b4a2ba | 2023-10-10 23:46:07 +1100 | [diff] [blame] | 154 | #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-hh | a04a141 | 2024-03-10 15:14:20 +0100 | [diff] [blame] | 157 | #define MICROPY_PY_MACHINE_UART_IRQ (1) |
Damien George | 60929ec | 2023-10-10 18:19:03 +1100 | [diff] [blame] | 158 | #define MICROPY_PY_MACHINE_WDT (1) |
| 159 | #define MICROPY_PY_MACHINE_WDT_INCLUDEFILE "ports/esp32/machine_wdt.c" |
Jim Mussared | eb51ca4 | 2023-02-01 14:20:45 +1100 | [diff] [blame] | 160 | #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 Leech | 6d79937 | 2023-06-26 11:53:28 +1000 | [diff] [blame] | 170 | #elif CONFIG_IDF_TARGET_ESP32C6 |
| 171 | #define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32c6" |
Jim Mussared | eb51ca4 | 2023-02-01 14:20:45 +1100 | [diff] [blame] | 172 | #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 George | ea186de | 2021-09-22 00:35:46 +1000 | [diff] [blame] | 176 | #ifndef MICROPY_PY_NETWORK_WLAN |
| 177 | #define MICROPY_PY_NETWORK_WLAN (1) |
| 178 | #endif |
Damien George | 66a86a0 | 2021-02-18 21:24:34 +1100 | [diff] [blame] | 179 | #ifndef MICROPY_HW_ENABLE_SDCARD |
Nicko van Someren | 8e3af7d | 2019-05-04 19:00:35 -0600 | [diff] [blame] | 180 | #define MICROPY_HW_ENABLE_SDCARD (1) |
Damien George | 66a86a0 | 2021-02-18 21:24:34 +1100 | [diff] [blame] | 181 | #endif |
Damien George | 58ebeca | 2018-03-09 17:25:58 +1100 | [diff] [blame] | 182 | #define MICROPY_HW_SOFTSPI_MIN_DELAY (0) |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 183 | #define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (esp_rom_get_cpu_ticks_per_us() * 1000000 / 200) // roughly |
Jim Mussared | f5f9edf | 2022-08-18 15:01:26 +1000 | [diff] [blame] | 184 | #define MICROPY_PY_SSL (1) |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 185 | #define MICROPY_SSL_MBEDTLS (1) |
Jim Mussared | f5f9edf | 2022-08-18 15:01:26 +1000 | [diff] [blame] | 186 | #define MICROPY_PY_WEBSOCKET (1) |
Damien George | c1d4352 | 2018-04-27 23:57:57 +1000 | [diff] [blame] | 187 | #define MICROPY_PY_WEBREPL (1) |
Damien George | d41f6dd | 2021-09-02 12:39:50 +1000 | [diff] [blame] | 188 | #define MICROPY_PY_ONEWIRE (1) |
Jim Mussared | f5f9edf | 2022-08-18 15:01:26 +1000 | [diff] [blame] | 189 | #define MICROPY_PY_SOCKET_EVENTS (MICROPY_PY_WEBREPL) |
Jim Mussared | 6a9bd1c | 2019-10-01 23:47:37 +1000 | [diff] [blame] | 190 | #define MICROPY_PY_BLUETOOTH_RANDOM_ADDR (1) |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 191 | |
| 192 | // fatfs configuration |
| 193 | #define MICROPY_FATFS_ENABLE_LFN (1) |
| 194 | #define MICROPY_FATFS_RPATH (2) |
| 195 | #define MICROPY_FATFS_MAX_SS (4096) |
Damien George | b5f33ac | 2019-02-25 23:46:17 +1100 | [diff] [blame] | 196 | #define MICROPY_FATFS_LFN_CODE_PAGE 437 /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */ |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 197 | |
dotnfc | d7f63f9 | 2023-09-12 17:15:27 +0800 | [diff] [blame] | 198 | // task size |
| 199 | #ifndef MICROPY_TASK_STACK_SIZE |
| 200 | #define MICROPY_TASK_STACK_SIZE (16 * 1024) |
| 201 | #endif |
| 202 | |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 203 | #define MP_STATE_PORT MP_STATE_VM |
| 204 | |
Andrew Leech | 4247921 | 2024-05-23 17:23:41 +1000 | [diff] [blame] | 205 | #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 Leech | 5ae622e | 2024-05-23 22:08:12 +1000 | [diff] [blame] | 210 | #define MICROPY_SCHEDULER_STATIC_NODES (1) |
| 211 | #define MICROPY_HW_USB_CDC_DTR_RTS_BOOTLOADER (1) |
Andrew Leech | 4247921 | 2024-05-23 17:23:41 +1000 | [diff] [blame] | 212 | |
| 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 Romero | 5f2d05d | 2024-12-04 16:30:56 +0100 | [diff] [blame] | 220 | |
| 221 | #ifndef MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE |
| 222 | #define MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE (1) // Support machine.USBDevice |
| 223 | #endif |
Andrew Leech | 4247921 | 2024-05-23 17:23:41 +1000 | [diff] [blame] | 224 | #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 George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 273 | // type definitions for the specific machine |
| 274 | |
Damien George | 69661f3 | 2020-02-27 15:36:53 +1100 | [diff] [blame] | 275 | #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p))) |
Andrew Leech | 55dc482 | 2024-10-08 17:19:34 +1100 | [diff] [blame] | 276 | #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 George | 69661f3 | 2020-02-27 15:36:53 +1100 | [diff] [blame] | 279 | void *esp_native_code_commit(void *, size_t, void *); |
Damien George | b47e155 | 2019-10-06 23:29:40 +1100 | [diff] [blame] | 280 | #define MP_PLAT_COMMIT_EXEC(buf, len, reloc) esp_native_code_commit(buf, len, reloc) |
Andrew Leech | 55dc482 | 2024-10-08 17:19:34 +1100 | [diff] [blame] | 281 | #endif |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 282 | #define MP_SSIZE_MAX (0x7fffffff) |
| 283 | |
Jim Mussared | f5f9edf | 2022-08-18 15:01:26 +1000 | [diff] [blame] | 284 | #if MICROPY_PY_SOCKET_EVENTS |
| 285 | #define MICROPY_PY_SOCKET_EVENTS_HANDLER extern void socket_events_handler(void); socket_events_handler(); |
Damien George | 999c8b9 | 2018-04-27 23:53:45 +1000 | [diff] [blame] | 286 | #else |
Jim Mussared | f5f9edf | 2022-08-18 15:01:26 +1000 | [diff] [blame] | 287 | #define MICROPY_PY_SOCKET_EVENTS_HANDLER |
Damien George | 999c8b9 | 2018-04-27 23:53:45 +1000 | [diff] [blame] | 288 | #endif |
| 289 | |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 290 | #if MICROPY_PY_THREAD |
| 291 | #define MICROPY_EVENT_POLL_HOOK \ |
| 292 | do { \ |
Damien George | 98a3911 | 2020-02-06 01:05:47 +1100 | [diff] [blame] | 293 | extern void mp_handle_pending(bool); \ |
| 294 | mp_handle_pending(true); \ |
Jim Mussared | f5f9edf | 2022-08-18 15:01:26 +1000 | [diff] [blame] | 295 | MICROPY_PY_SOCKET_EVENTS_HANDLER \ |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 296 | MP_THREAD_GIL_EXIT(); \ |
Daniƫl van de Giessen | 665f0e2 | 2022-02-23 17:28:32 +0100 | [diff] [blame] | 297 | ulTaskNotifyTake(pdFALSE, 1); \ |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 298 | MP_THREAD_GIL_ENTER(); \ |
| 299 | } while (0); |
| 300 | #else |
Alessandro Gatti | 82e382a | 2024-12-04 12:30:25 +0100 | [diff] [blame] | 301 | #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 George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 306 | #define MICROPY_EVENT_POLL_HOOK \ |
| 307 | do { \ |
Damien George | 98a3911 | 2020-02-06 01:05:47 +1100 | [diff] [blame] | 308 | extern void mp_handle_pending(bool); \ |
| 309 | mp_handle_pending(true); \ |
Jim Mussared | f5f9edf | 2022-08-18 15:01:26 +1000 | [diff] [blame] | 310 | MICROPY_PY_SOCKET_EVENTS_HANDLER \ |
Alessandro Gatti | 82e382a | 2024-12-04 12:30:25 +0100 | [diff] [blame] | 311 | MICROPY_PY_WAIT_FOR_INTERRUPT; \ |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 312 | } while (0); |
| 313 | #endif |
| 314 | |
Damien George | f4641b2 | 2020-02-07 12:11:22 +1100 | [diff] [blame] | 315 | // Functions that should go in IRAM |
Damien George | b4b77c1 | 2023-12-11 12:01:09 +1100 | [diff] [blame] | 316 | // 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 George | 549448e | 2021-09-24 12:50:59 +1000 | [diff] [blame] | 319 | #define MICROPY_WRAP_MP_BINARY_OP(f) IRAM_ATTR f |
Damien George | b4b77c1 | 2023-12-11 12:01:09 +1100 | [diff] [blame] | 320 | #endif |
Damien George | 549448e | 2021-09-24 12:50:59 +1000 | [diff] [blame] | 321 | #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 George | 7cbf826 | 2021-04-28 10:52:19 +1000 | [diff] [blame] | 326 | #define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) IRAM_ATTR f |
Damien George | e9e9c76 | 2021-04-28 10:57:34 +1000 | [diff] [blame] | 327 | #define MICROPY_WRAP_MP_SCHED_KEYBOARD_INTERRUPT(f) IRAM_ATTR f |
Damien George | f4641b2 | 2020-02-07 12:11:22 +1100 | [diff] [blame] | 328 | |
Damien George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 329 | #define UINT_FMT "%u" |
| 330 | #define INT_FMT "%d" |
| 331 | |
| 332 | typedef int32_t mp_int_t; // must be pointer size |
| 333 | typedef uint32_t mp_uint_t; // must be pointer size |
| 334 | typedef 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 George | bc08c88 | 2016-12-06 12:20:10 +1100 | [diff] [blame] | 339 | #define MICROPY_PY_SYS_PLATFORM "esp32" |
Damien George | 2ccf030 | 2019-07-10 15:38:48 +1000 | [diff] [blame] | 340 | |
Seon Rozenblum | 1904833 | 2021-11-12 11:23:49 +1100 | [diff] [blame] | 341 | // 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 George | 2ccf030 | 2019-07-10 15:38:48 +1000 | [diff] [blame] | 346 | #ifndef MICROPY_HW_ENABLE_MDNS_QUERIES |
Carlosgg | 1f35576 | 2023-06-25 22:48:39 +0100 | [diff] [blame] | 347 | #define MICROPY_HW_ENABLE_MDNS_QUERIES (1) |
Damien George | 2ccf030 | 2019-07-10 15:38:48 +1000 | [diff] [blame] | 348 | #endif |
| 349 | |
| 350 | #ifndef MICROPY_HW_ENABLE_MDNS_RESPONDER |
Carlosgg | 1f35576 | 2023-06-25 22:48:39 +0100 | [diff] [blame] | 351 | #define MICROPY_HW_ENABLE_MDNS_RESPONDER (1) |
Damien George | 2ccf030 | 2019-07-10 15:38:48 +1000 | [diff] [blame] | 352 | #endif |
Damien George | f046b50 | 2021-09-22 00:00:26 +1000 | [diff] [blame] | 353 | |
Trent Piepho | af67be7 | 2024-03-02 01:25:10 -0800 | [diff] [blame] | 354 | #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 Piepho | 9fc4506 | 2024-03-02 01:10:20 -0800 | [diff] [blame] | 362 | #ifdef MICROPY_BOARD_ENTER_BOOTLOADER |
| 363 | #define MICROPY_PY_MACHINE_BOOTLOADER (1) |
| 364 | #else |
| 365 | #define MICROPY_PY_MACHINE_BOOTLOADER (0) |
Luca Burelli | 904ccfa | 2023-07-04 11:54:53 +0200 | [diff] [blame] | 366 | #endif |
| 367 | |
Angus Gratton | 6fead31 | 2024-07-25 12:11:32 +1000 | [diff] [blame] | 368 | // 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 George | f046b50 | 2021-09-22 00:00:26 +1000 | [diff] [blame] | 372 | #ifndef MICROPY_BOARD_STARTUP |
| 373 | #define MICROPY_BOARD_STARTUP boardctrl_startup |
| 374 | #endif |
| 375 | |
| 376 | void boardctrl_startup(void); |
Damien Tournoud | e982c1d | 2023-01-12 21:04:07 -0800 | [diff] [blame] | 377 | |
| 378 | #ifndef MICROPY_PY_NETWORK_LAN |
Damien George | e465012 | 2023-05-09 09:52:54 +1000 | [diff] [blame] | 379 | #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 Tournoud | e982c1d | 2023-01-12 21:04:07 -0800 | [diff] [blame] | 380 | #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 Leech | 6d79937 | 2023-06-26 11:53:28 +1000 | [diff] [blame] | 388 | #define MICROPY_PY_NETWORK_LAN_SPI_CLOCK_SPEED_MZ (20) |
Damien Tournoud | e982c1d | 2023-01-12 21:04:07 -0800 | [diff] [blame] | 389 | #endif |
| 390 | #endif |
Alessandro Gatti | 0b75e18 | 2024-08-10 16:37:03 +0200 | [diff] [blame] | 391 | |
| 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 Gatti | 883dc41 | 2025-03-25 22:43:23 +0100 | [diff] [blame] | 396 | |
| 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 |