@mikrojs/firmware 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/bin/idf.py +7 -0
  4. package/chips.json +3 -0
  5. package/cmake.js +9 -0
  6. package/components/mikrojs/CMakeLists.txt +187 -0
  7. package/components/mikrojs/Kconfig +55 -0
  8. package/components/mikrojs/idf_component.yml +6 -0
  9. package/components/mikrojs/include/mem.h +3 -0
  10. package/components/mikrojs/include/mik_color.h +3 -0
  11. package/components/mikrojs/include/mik_http_internal.h +77 -0
  12. package/components/mikrojs/include/mikrojs.h +5 -0
  13. package/components/mikrojs/include/mikrojs_esp32.h +65 -0
  14. package/components/mikrojs/include/private.h +10 -0
  15. package/components/mikrojs/include/utils.h +3 -0
  16. package/components/mikrojs/mik_ble.cpp +1588 -0
  17. package/components/mikrojs/mik_ble_c_shim.c +61 -0
  18. package/components/mikrojs/mik_ble_c_shim.h +37 -0
  19. package/components/mikrojs/mik_config.cpp +167 -0
  20. package/components/mikrojs/mik_deploy.cpp +584 -0
  21. package/components/mikrojs/mik_http.cpp +916 -0
  22. package/components/mikrojs/mik_i2c.cpp +364 -0
  23. package/components/mikrojs/mik_main.cpp +542 -0
  24. package/components/mikrojs/mik_neopixel.cpp +437 -0
  25. package/components/mikrojs/mik_nvs_kv.cpp +219 -0
  26. package/components/mikrojs/mik_pin.cpp +195 -0
  27. package/components/mikrojs/mik_pwm.cpp +525 -0
  28. package/components/mikrojs/mik_recovery.cpp +86 -0
  29. package/components/mikrojs/mik_rtc.cpp +305 -0
  30. package/components/mikrojs/mik_serial_io.cpp +362 -0
  31. package/components/mikrojs/mik_sleep.cpp +226 -0
  32. package/components/mikrojs/mik_sntp.cpp +275 -0
  33. package/components/mikrojs/mik_spi.cpp +330 -0
  34. package/components/mikrojs/mik_uart.cpp +497 -0
  35. package/components/mikrojs/mik_wifi.cpp +1434 -0
  36. package/components/mikrojs/platform_esp32.cpp +192 -0
  37. package/components/mikrojs/test/CMakeLists.txt +32 -0
  38. package/components/mikrojs/test/abort_test.cpp +254 -0
  39. package/components/mikrojs/test/ble_test.cpp +714 -0
  40. package/components/mikrojs/test/fs_js_test.cpp +458 -0
  41. package/components/mikrojs/test/fs_pub_test.cpp +312 -0
  42. package/components/mikrojs/test/http_test.cpp +475 -0
  43. package/components/mikrojs/test/i2c_test.cpp +138 -0
  44. package/components/mikrojs/test/modules_extended_test.cpp +137 -0
  45. package/components/mikrojs/test/modules_test.cpp +131 -0
  46. package/components/mikrojs/test/pins_test.cpp +47 -0
  47. package/components/mikrojs/test/pwm_test.cpp +166 -0
  48. package/components/mikrojs/test/repl_protocol_test.cpp +405 -0
  49. package/components/mikrojs/test/rtc_test.cpp +331 -0
  50. package/components/mikrojs/test/runtime_test.cpp +89 -0
  51. package/components/mikrojs/test/sleep_test.cpp +222 -0
  52. package/components/mikrojs/test/sntp_test.cpp +249 -0
  53. package/components/mikrojs/test/stdio_test.cpp +449 -0
  54. package/components/mikrojs/test/sys_test.cpp +165 -0
  55. package/components/mikrojs/test/text_encoding_test.cpp +224 -0
  56. package/components/mikrojs/test/timers_js_test.cpp +244 -0
  57. package/components/mikrojs/test/timers_test.cpp +79 -0
  58. package/components/mikrojs/test/wifi_test.cpp +599 -0
  59. package/default-app/main/CMakeLists.txt +3 -0
  60. package/default-app/main/main.cpp +5 -0
  61. package/discover.js +77 -0
  62. package/index.d.ts +7 -0
  63. package/index.js +20 -0
  64. package/package.json +61 -0
  65. package/partitions.csv +5 -0
  66. package/prebuilds/esp32/bootloader/bootloader.bin +0 -0
  67. package/prebuilds/esp32/flasher_args.json +24 -0
  68. package/prebuilds/esp32/mikrojs.bin +0 -0
  69. package/prebuilds/esp32/partition_table/partition-table.bin +0 -0
  70. package/prebuilds/esp32c3/bootloader/bootloader.bin +0 -0
  71. package/prebuilds/esp32c3/flasher_args.json +24 -0
  72. package/prebuilds/esp32c3/mikrojs.bin +0 -0
  73. package/prebuilds/esp32c3/partition_table/partition-table.bin +0 -0
  74. package/prebuilds/esp32c6/bootloader/bootloader.bin +0 -0
  75. package/prebuilds/esp32c6/flasher_args.json +24 -0
  76. package/prebuilds/esp32c6/mikrojs.bin +0 -0
  77. package/prebuilds/esp32c6/partition_table/partition-table.bin +0 -0
  78. package/prebuilds/esp32s3/bootloader/bootloader.bin +0 -0
  79. package/prebuilds/esp32s3/flasher_args.json +24 -0
  80. package/prebuilds/esp32s3/mikrojs.bin +0 -0
  81. package/prebuilds/esp32s3/partition_table/partition-table.bin +0 -0
  82. package/project.cmake +101 -0
  83. package/resolve.js +54 -0
  84. package/sdkconfig.defaults +127 -0
  85. package/sdkconfig.defaults.esp32 +8 -0
  86. package/sdkconfig.defaults.esp32c3 +15 -0
  87. package/sdkconfig.defaults.esp32c6 +26 -0
  88. package/sdkconfig.defaults.esp32s3 +22 -0
package/index.js ADDED
@@ -0,0 +1,20 @@
1
+ import {existsSync} from 'node:fs'
2
+ import {dirname, join} from 'node:path'
3
+ import {fileURLToPath} from 'node:url'
4
+
5
+ const __dirname = dirname(fileURLToPath(import.meta.url))
6
+
7
+ export const componentDir = join(__dirname, 'components')
8
+ export const configDir = __dirname
9
+ export const defaultAppDir = join(__dirname, 'default-app')
10
+ export const projectCmakePath = join(__dirname, 'project.cmake')
11
+
12
+ const prebuildsRoot = join(__dirname, 'prebuilds')
13
+
14
+ export function prebuiltFirmwareDir(chip) {
15
+ return join(prebuildsRoot, chip)
16
+ }
17
+
18
+ export function hasPrebuiltFirmware(chip) {
19
+ return existsSync(join(prebuildsRoot, chip, 'flasher_args.json'))
20
+ }
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@mikrojs/firmware",
3
+ "version": "0.0.7",
4
+ "description": "Mikro.js ESP32 firmware: ESP-IDF component, build tools, and project template",
5
+ "keywords": [
6
+ "esp-idf",
7
+ "esp32",
8
+ "firmware",
9
+ "mikrojs"
10
+ ],
11
+ "homepage": "https://github.com/mikrojs/mikrojs#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/mikrojs/mikrojs/issues"
14
+ },
15
+ "license": "MIT",
16
+ "author": "Bjørge Næss <bjoerge@gmail.com>",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/mikrojs/mikrojs.git"
20
+ },
21
+ "bin": {
22
+ "idf.py": "./bin/idf.py"
23
+ },
24
+ "files": [
25
+ "components",
26
+ "default-app",
27
+ "prebuilds",
28
+ "sdkconfig.defaults",
29
+ "sdkconfig.defaults.*",
30
+ "partitions.csv",
31
+ "bin",
32
+ "chips.json",
33
+ "cmake.js",
34
+ "discover.js",
35
+ "index.js",
36
+ "index.d.ts",
37
+ "project.cmake",
38
+ "resolve.js"
39
+ ],
40
+ "type": "module",
41
+ "sideEffects": false,
42
+ "types": "./index.d.ts",
43
+ "exports": {
44
+ ".": {
45
+ "types": "./index.d.ts",
46
+ "default": "./index.js"
47
+ },
48
+ "./cmake": "./cmake.js",
49
+ "./discover": "./discover.js",
50
+ "./package.json": "./package.json"
51
+ },
52
+ "dependencies": {
53
+ "esbuild": "^0.28.0",
54
+ "@mikrojs/native": "0.0.7",
55
+ "@mikrojs/quickjs": "0.0.7"
56
+ },
57
+ "engines": {
58
+ "node": ">=24.0.0"
59
+ },
60
+ "scripts": {}
61
+ }
package/partitions.csv ADDED
@@ -0,0 +1,5 @@
1
+ # Name, Type, SubType, Offset, Size, Flags
2
+ nvs, data, nvs, 0x9000, 0x6000,
3
+ phy_init, data, phy, 0xf000, 0x1000,
4
+ factory, app, factory, 0x10000, 0x280000,
5
+ user, data, littlefs, , 0x100000,
@@ -0,0 +1,24 @@
1
+ {
2
+ "write_flash_args" : [ "--flash-mode", "dio",
3
+ "--flash-size", "4MB",
4
+ "--flash-freq", "40m" ],
5
+ "flash_settings" : {
6
+ "flash_mode": "dio",
7
+ "flash_size": "4MB",
8
+ "flash_freq": "40m"
9
+ },
10
+ "flash_files" : {
11
+ "0x1000" : "bootloader/bootloader.bin",
12
+ "0x8000" : "partition_table/partition-table.bin",
13
+ "0x10000" : "mikrojs.bin"
14
+ },
15
+ "bootloader" : { "offset" : "0x1000", "file" : "bootloader/bootloader.bin", "encrypted" : "false" },
16
+ "partition-table" : { "offset" : "0x8000", "file" : "partition_table/partition-table.bin", "encrypted" : "false" },
17
+ "app" : { "offset" : "0x10000", "file" : "mikrojs.bin", "encrypted" : "false" },
18
+ "extra_esptool_args" : {
19
+ "after" : "hard-reset",
20
+ "before" : "default-reset",
21
+ "stub" : true,
22
+ "chip" : "esp32"
23
+ }
24
+ }
Binary file
@@ -0,0 +1,24 @@
1
+ {
2
+ "write_flash_args" : [ "--flash-mode", "dio",
3
+ "--flash-size", "4MB",
4
+ "--flash-freq", "80m" ],
5
+ "flash_settings" : {
6
+ "flash_mode": "dio",
7
+ "flash_size": "4MB",
8
+ "flash_freq": "80m"
9
+ },
10
+ "flash_files" : {
11
+ "0x0" : "bootloader/bootloader.bin",
12
+ "0x8000" : "partition_table/partition-table.bin",
13
+ "0x10000" : "mikrojs.bin"
14
+ },
15
+ "bootloader" : { "offset" : "0x0", "file" : "bootloader/bootloader.bin", "encrypted" : "false" },
16
+ "partition-table" : { "offset" : "0x8000", "file" : "partition_table/partition-table.bin", "encrypted" : "false" },
17
+ "app" : { "offset" : "0x10000", "file" : "mikrojs.bin", "encrypted" : "false" },
18
+ "extra_esptool_args" : {
19
+ "after" : "hard-reset",
20
+ "before" : "default-reset",
21
+ "stub" : true,
22
+ "chip" : "esp32c3"
23
+ }
24
+ }
Binary file
@@ -0,0 +1,24 @@
1
+ {
2
+ "write_flash_args" : [ "--flash-mode", "dio",
3
+ "--flash-size", "4MB",
4
+ "--flash-freq", "80m" ],
5
+ "flash_settings" : {
6
+ "flash_mode": "dio",
7
+ "flash_size": "4MB",
8
+ "flash_freq": "80m"
9
+ },
10
+ "flash_files" : {
11
+ "0x0" : "bootloader/bootloader.bin",
12
+ "0x8000" : "partition_table/partition-table.bin",
13
+ "0x10000" : "mikrojs.bin"
14
+ },
15
+ "bootloader" : { "offset" : "0x0", "file" : "bootloader/bootloader.bin", "encrypted" : "false" },
16
+ "partition-table" : { "offset" : "0x8000", "file" : "partition_table/partition-table.bin", "encrypted" : "false" },
17
+ "app" : { "offset" : "0x10000", "file" : "mikrojs.bin", "encrypted" : "false" },
18
+ "extra_esptool_args" : {
19
+ "after" : "hard-reset",
20
+ "before" : "default-reset",
21
+ "stub" : true,
22
+ "chip" : "esp32c6"
23
+ }
24
+ }
Binary file
@@ -0,0 +1,24 @@
1
+ {
2
+ "write_flash_args" : [ "--flash-mode", "dio",
3
+ "--flash-size", "4MB",
4
+ "--flash-freq", "80m" ],
5
+ "flash_settings" : {
6
+ "flash_mode": "dio",
7
+ "flash_size": "4MB",
8
+ "flash_freq": "80m"
9
+ },
10
+ "flash_files" : {
11
+ "0x0" : "bootloader/bootloader.bin",
12
+ "0x8000" : "partition_table/partition-table.bin",
13
+ "0x10000" : "mikrojs.bin"
14
+ },
15
+ "bootloader" : { "offset" : "0x0", "file" : "bootloader/bootloader.bin", "encrypted" : "false" },
16
+ "partition-table" : { "offset" : "0x8000", "file" : "partition_table/partition-table.bin", "encrypted" : "false" },
17
+ "app" : { "offset" : "0x10000", "file" : "mikrojs.bin", "encrypted" : "false" },
18
+ "extra_esptool_args" : {
19
+ "after" : "hard-reset",
20
+ "before" : "default-reset",
21
+ "stub" : true,
22
+ "chip" : "esp32s3"
23
+ }
24
+ }
Binary file
package/project.cmake ADDED
@@ -0,0 +1,101 @@
1
+ # project.cmake — reusable CMake module for mikrojs firmware projects
2
+ #
3
+ # Usage in user's CMakeLists.txt:
4
+ # cmake_minimum_required(VERSION 3.22)
5
+ # include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6
+ # execute_process(
7
+ # COMMAND node <path-to>/resolve.js projectCmakePath
8
+ # OUTPUT_VARIABLE _MIK_CMAKE OUTPUT_STRIP_TRAILING_WHITESPACE)
9
+ # include(${_MIK_CMAKE})
10
+ # project(my-firmware)
11
+
12
+ # ── Validate ESP-IDF version ─────────────────────────────────────────
13
+ if(IDF_VERSION_MAJOR LESS 6)
14
+ message(FATAL_ERROR
15
+ "mikrojs requires ESP-IDF >= 6.0.0, found ${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}.${IDF_VERSION_PATCH}. "
16
+ "Install a supported version via EIM: https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/index.html"
17
+ )
18
+ endif()
19
+
20
+ add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-incompatible-pointer-types>)
21
+ add_compile_options(-Wno-format)
22
+
23
+ # resolve.js is next to this file
24
+ get_filename_component(_MIK_RESOLVE "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
25
+ set(_MIK_RESOLVE "${_MIK_RESOLVE}/resolve.js")
26
+
27
+ # ── Resolve firmware package paths ───────────────────────────────────
28
+ execute_process(
29
+ COMMAND node ${_MIK_RESOLVE} componentDir
30
+ OUTPUT_VARIABLE _MIK_COMPONENT_DIR
31
+ OUTPUT_STRIP_TRAILING_WHITESPACE
32
+ )
33
+
34
+ if(NOT _MIK_COMPONENT_DIR)
35
+ message(FATAL_ERROR "@mikrojs/firmware not found. Run 'pnpm install' or 'npm install' first.")
36
+ endif()
37
+
38
+ execute_process(
39
+ COMMAND node ${_MIK_RESOLVE} configDir
40
+ OUTPUT_VARIABLE _MIK_CONFIG_DIR
41
+ OUTPUT_STRIP_TRAILING_WHITESPACE
42
+ )
43
+ execute_process(
44
+ COMMAND node ${_MIK_RESOLVE} defaultAppDir
45
+ OUTPUT_VARIABLE _MIK_DEFAULT_APP_DIR
46
+ OUTPUT_STRIP_TRAILING_WHITESPACE
47
+ )
48
+
49
+ # ── Board and driver package discovery ───────────────────────────────
50
+ execute_process(
51
+ COMMAND node ${_MIK_RESOLVE} discover ${CMAKE_CURRENT_LIST_DIR}
52
+ OUTPUT_VARIABLE _BOARD_JSON
53
+ OUTPUT_STRIP_TRAILING_WHITESPACE
54
+ )
55
+
56
+ # Start with the mikrojs component dir and default main
57
+ set(EXTRA_COMPONENT_DIRS "${_MIK_COMPONENT_DIR}")
58
+
59
+ # Use the firmware package's default main/ component unless the project has its own
60
+ if(NOT EXISTS "${CMAKE_SOURCE_DIR}/main/CMakeLists.txt")
61
+ set(EXTRA_COMPONENT_DIRS "${EXTRA_COMPONENT_DIRS};${_MIK_DEFAULT_APP_DIR}")
62
+ endif()
63
+
64
+ # ── Default sdkconfig and partition table from firmware package ───────
65
+ # CMAKE_CURRENT_LIST_DIR is the firmware package (where this file lives).
66
+ # CMAKE_SOURCE_DIR is the consuming project (e.g. esp32/).
67
+ set(_SDKCONFIG_LIST "")
68
+ list(APPEND _SDKCONFIG_LIST "${_MIK_CONFIG_DIR}/sdkconfig.defaults")
69
+ if(EXISTS "${_MIK_CONFIG_DIR}/sdkconfig.defaults.${IDF_TARGET}")
70
+ list(APPEND _SDKCONFIG_LIST "${_MIK_CONFIG_DIR}/sdkconfig.defaults.${IDF_TARGET}")
71
+ endif()
72
+ # Project-level overrides come after firmware defaults (later = higher priority).
73
+ if(EXISTS "${CMAKE_SOURCE_DIR}/sdkconfig.defaults")
74
+ list(APPEND _SDKCONFIG_LIST "${CMAKE_SOURCE_DIR}/sdkconfig.defaults")
75
+ endif()
76
+ if(EXISTS "${CMAKE_SOURCE_DIR}/sdkconfig.defaults.${IDF_TARGET}")
77
+ list(APPEND _SDKCONFIG_LIST "${CMAKE_SOURCE_DIR}/sdkconfig.defaults.${IDF_TARGET}")
78
+ endif()
79
+
80
+ # Partition table: generate a sdkconfig fragment with the absolute path
81
+ if(EXISTS "${CMAKE_SOURCE_DIR}/partitions.csv")
82
+ set(_PARTITION_CSV "${CMAKE_SOURCE_DIR}/partitions.csv")
83
+ else()
84
+ set(_PARTITION_CSV "${_MIK_CONFIG_DIR}/partitions.csv")
85
+ endif()
86
+ set(_PARTITION_FRAGMENT "${CMAKE_SOURCE_DIR}/build/sdkconfig.partitions")
87
+ file(WRITE "${_PARTITION_FRAGMENT}" "CONFIG_PARTITION_TABLE_CUSTOM_FILENAME=\"${_PARTITION_CSV}\"\n")
88
+ list(APPEND _SDKCONFIG_LIST "${_PARTITION_FRAGMENT}")
89
+
90
+ if(_BOARD_JSON)
91
+ string(JSON _BOARD_COMPONENT_DIRS GET "${_BOARD_JSON}" "components")
92
+ string(JSON _BOARD_SDKCONFIG_DEFAULTS GET "${_BOARD_JSON}" "sdkconfigs")
93
+ if(_BOARD_COMPONENT_DIRS)
94
+ set(EXTRA_COMPONENT_DIRS "${EXTRA_COMPONENT_DIRS};${_BOARD_COMPONENT_DIRS}")
95
+ endif()
96
+ if(_BOARD_SDKCONFIG_DEFAULTS)
97
+ list(APPEND _SDKCONFIG_LIST "${_BOARD_SDKCONFIG_DEFAULTS}")
98
+ endif()
99
+ endif()
100
+
101
+ set(SDKCONFIG_DEFAULTS "${_SDKCONFIG_LIST}")
package/resolve.js ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Resolve package paths for CMake. Called by CMakeLists.txt files.
4
+ *
5
+ * Usage: node resolve.js <query> [args...]
6
+ *
7
+ * Queries:
8
+ * componentDir — EXTRA_COMPONENT_DIRS parent (contains mikrojs/)
9
+ * configDir — directory with sdkconfig.defaults + partitions.csv
10
+ * defaultAppDir — directory containing default main/ component
11
+ * projectCmakePath — path to project.cmake
12
+ * quickjs — path to quickjs.cmake
13
+ * native — JSON with native package paths
14
+ * version — firmware package version
15
+ * discover <dir> — discover board/driver components from project dir
16
+ */
17
+ import {componentDir, projectCmakePath} from './cmake.js'
18
+ import {configDir, defaultAppDir} from './index.js'
19
+
20
+ const query = process.argv[2]
21
+
22
+ if (query === 'componentDir') {
23
+ process.stdout.write(componentDir)
24
+ } else if (query === 'configDir') {
25
+ process.stdout.write(configDir)
26
+ } else if (query === 'defaultAppDir') {
27
+ process.stdout.write(defaultAppDir)
28
+ } else if (query === 'projectCmakePath') {
29
+ process.stdout.write(projectCmakePath)
30
+ } else if (query === 'quickjs') {
31
+ const m = await import('@mikrojs/quickjs')
32
+ process.stdout.write(m.cmakePath)
33
+ } else if (query === 'native') {
34
+ const n = await import('@mikrojs/native/cmake')
35
+ process.stdout.write(
36
+ JSON.stringify({
37
+ include: n.includePath,
38
+ src: n.srcPath,
39
+ runtime: n.runtimePath,
40
+ scripts: n.scriptsPath,
41
+ bytecodeCmake: n.bytecodeCmakePath,
42
+ }),
43
+ )
44
+ } else if (query === 'version') {
45
+ const {default: pkg} = await import('./package.json', {with: {type: 'json'}})
46
+ process.stdout.write(pkg.version)
47
+ } else if (query === 'discover') {
48
+ const projectDir = process.argv[3]
49
+ const {discover} = await import('./discover.js')
50
+ process.stdout.write(JSON.stringify(discover(projectDir)))
51
+ } else {
52
+ process.stderr.write(`Unknown query: ${query}\n`)
53
+ process.exit(1)
54
+ }
@@ -0,0 +1,127 @@
1
+ # --- Task & stack sizes ---
2
+ # Main task runs the mikrojs runtime directly. Deep JS → native → JS chains
3
+ # overflow 16 KB; 24 KB gives ~8 KB headroom with no observed waste on
4
+ # simpler apps. See packages/@mikrojs/firmware/components/mikrojs/MEMORY_ANALYSIS.md.
5
+ CONFIG_ESP_MAIN_TASK_STACK_SIZE=24576
6
+ CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4096
7
+ CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048
8
+
9
+ # --- Partition table ---
10
+ CONFIG_PARTITION_TABLE_CUSTOM=y
11
+ # CONFIG_PARTITION_TABLE_CUSTOM_FILENAME is set by project.cmake
12
+
13
+ # --- Flash ---
14
+ CONFIG_ESPTOOLPY_FLASHFREQ="80m"
15
+ # ESP-IDF defaults C6 (and some others) to 2MB flash. Modern dev kits ship
16
+ # with 4MB+, and the partition table grew past 2MB once BLE was enabled.
17
+ CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
18
+ CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
19
+
20
+ # --- RAM optimization ---
21
+ # Use -Os to reduce code size (less IRAM pressure, smaller function frames)
22
+ CONFIG_COMPILER_OPTIMIZATION_SIZE=y
23
+
24
+ # Move system functions from IRAM to flash (IRAM and DRAM share the same
25
+ # SRAM on single-core chips like C3/C6, so freeing IRAM also frees DRAM)
26
+ CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH=y
27
+ CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y
28
+ CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y
29
+
30
+ # Trade WiFi throughput for ~15-20KB IRAM savings. Fine for mikrojs
31
+ # workloads (HTTP requests, small payloads — not high-throughput streaming).
32
+ CONFIG_ESP_WIFI_IRAM_OPT=n
33
+ CONFIG_ESP_WIFI_RX_IRAM_OPT=n
34
+
35
+ # SPI master ISR doesn't need to run during flash writes
36
+ CONFIG_SPI_MASTER_ISR_IN_IRAM=n
37
+
38
+ # No ISRs post events while cache is disabled
39
+ CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=n
40
+
41
+ # Keep UART ISR in IRAM so it runs during flash writes (LittleFS).
42
+ # Without this, the 128-byte RX FIFO overflows during deploy.
43
+ CONFIG_UART_ISR_IN_IRAM=y
44
+
45
+ # --- LittleFS ---
46
+ # Track modification time so fs.stat() / fs.readDir() surface mtime
47
+ # (exposed as ms-since-epoch on the StatResult object).
48
+ CONFIG_LITTLEFS_USE_MTIME=y
49
+
50
+ # --- Logging ---
51
+ # Production default: NONE. No log output on serial console, keeps the
52
+ # REPL protocol stream clean. The bootloader is also silenced.
53
+ #
54
+ # CONFIG_LOG_DYNAMIC_LEVEL_CONTROL=y enables esp_log_level_set() at
55
+ # runtime, which we use in mik__apply_nvs_log_level() to flip specific
56
+ # mikrojs tags to DEBUG based on the MIK_LOG_LEVEL NVS env var. This
57
+ # costs a few hundred bytes of flash (the tag-level hash table) and
58
+ # near-zero RAM.
59
+ #
60
+ # We intentionally do NOT raise CONFIG_LOG_MAXIMUM_LEVEL. libmikrojs's
61
+ # log calls go through platform->log → esp_log_writev (a real function
62
+ # call, not a macro), so they're always compiled in and only filtered
63
+ # at runtime. Raising MAXIMUM_LEVEL would pull in debug format strings
64
+ # from every ESP-IDF subsystem (BLE/WiFi/lwIP/drivers) — measured at
65
+ # +121 KB flash + 3 KB RAM on ESP32-C6. Not worth it for dev
66
+ # diagnostics we can already get via the runtime path.
67
+ CONFIG_LOG_DEFAULT_LEVEL_NONE=y
68
+ CONFIG_LOG_DEFAULT_LEVEL=0
69
+ CONFIG_LOG_DYNAMIC_LEVEL_CONTROL=y
70
+ CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y
71
+ CONFIG_BOOTLOADER_LOG_LEVEL=0
72
+
73
+ # --- Bluetooth / BLE (NimBLE host, peripheral + broadcaster roles) ---
74
+ CONFIG_BT_ENABLED=y
75
+ CONFIG_BT_NIMBLE_ENABLED=y
76
+ CONFIG_BT_BLUEDROID_ENABLED=n
77
+ CONFIG_BT_NIMBLE_ROLE_PERIPHERAL=y
78
+ CONFIG_BT_NIMBLE_ROLE_BROADCASTER=y
79
+ CONFIG_BT_NIMBLE_ROLE_CENTRAL=n
80
+ CONFIG_BT_NIMBLE_ROLE_OBSERVER=n
81
+ CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE=4096
82
+ CONFIG_BT_NIMBLE_ATT_PREFERRED_MTU=256
83
+ # Software coexistence for chips that share the 2.4 GHz radio between WiFi and BLE
84
+ # (ESP32, ESP32-S3, ESP32-C3). Harmless on chips with separate radios (ESP32-C6).
85
+ CONFIG_ESP_COEX_SW_COEXIST_ENABLE=y
86
+
87
+ # Disable unused C++ features
88
+ CONFIG_COMPILER_CXX_EXCEPTIONS=n
89
+ CONFIG_COMPILER_CXX_RTTI=n
90
+
91
+ # Disable unused VFS features (~6KB savings)
92
+ CONFIG_VFS_SUPPORT_SELECT=n
93
+
94
+ # --- Assertions & error strings ---
95
+ CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y
96
+ CONFIG_ESP_ERR_TO_NAME_LOOKUP=n
97
+ CONFIG_HAL_DEFAULT_ASSERTION_LEVEL=0
98
+
99
+ # --- lwIP ---
100
+ CONFIG_LWIP_IPV6=n
101
+
102
+ # --- MbedTLS: TLS 1.2 + 1.3, AES-GCM/CCM, ECDHE ---
103
+ CONFIG_MBEDTLS_SSL_PROTO_TLS1_3=y
104
+ # Disable unused features
105
+ CONFIG_MBEDTLS_SSL_RENEGOTIATION=n
106
+ CONFIG_MBEDTLS_SSL_ALPN=y
107
+ CONFIG_MBEDTLS_PKCS7_C=n
108
+ CONFIG_MBEDTLS_PEM_WRITE_C=n
109
+
110
+ CONFIG_MBEDTLS_X509_CRL_PARSE_C=n
111
+ CONFIG_MBEDTLS_X509_CSR_PARSE_C=n
112
+
113
+ CONFIG_MBEDTLS_ERROR_STRINGS=n
114
+ CONFIG_MBEDTLS_FS_IO=n
115
+
116
+ # Disable rarely used ECC curves (keep P-256, P-384, Curve25519)
117
+ # Note: secp192r1, secp224r1, secp192k1, secp224k1 removed in MbedTLS 4.x
118
+ CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED=n
119
+ CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED=n
120
+ CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED=n
121
+ CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED=n
122
+ CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=n
123
+
124
+ # Use smaller cert bundle (common CAs only)
125
+ CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN=y
126
+ CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_CROSS_SIGNED_VERIFY=y
127
+
@@ -0,0 +1,8 @@
1
+ # ESP32: uses UART for console I/O
2
+ # No overrides needed — base sdkconfig.defaults handles UART targets.
3
+
4
+ # Enable PSRAM if present (e.g. WROVER modules with 4-8 MB).
5
+ # IGNORE_NOTFOUND: fall back to internal SRAM if not present.
6
+ CONFIG_SPIRAM=y
7
+ CONFIG_SPIRAM_USE_MALLOC=y
8
+ CONFIG_SPIRAM_IGNORE_NOTFOUND=y
@@ -0,0 +1,15 @@
1
+ # ESP32-C3: route ESP-IDF stdio/ESP_LOG to UART0 rather than the
2
+ # built-in USB Serial/JTAG. See sdkconfig.defaults.esp32c6 for the
3
+ # reasoning (avoid ESP-IDF auto-registering the USB-JTAG VFS / stdio
4
+ # stack at boot). mikrojs installs the USB-Serial/JTAG driver itself
5
+ # via the public API in mik_serial_io.cpp for REPL/TLV transport.
6
+ #
7
+ # Secondary console on USB-Serial/JTAG so panic dumps + bootloader
8
+ # messages still reach a dev monitor attached over USB (the primary
9
+ # UART usually isn't wired up on dev boards). ESP-IDF writes panic
10
+ # output directly to USB-JTAG hardware registers, which doesn't
11
+ # conflict with mikrojs's driver-level registration for regular
12
+ # REPL traffic.
13
+ CONFIG_ESP_CONSOLE_UART_DEFAULT=y
14
+ CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=n
15
+ CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG=y
@@ -0,0 +1,26 @@
1
+ # ESP32-C6: route ESP-IDF stdio/ESP_LOG to UART0 rather than the
2
+ # built-in USB Serial/JTAG. This prevents ESP-IDF's startup code from
3
+ # registering the USB-JTAG VFS and pulling it into newlib's stdio
4
+ # before app_main() runs — an early-boot init sequence heavy enough
5
+ # to tip marginal battery supplies past brown-out on some boards.
6
+ #
7
+ # mikrojs still exposes USB-Serial/JTAG as a REPL/TLV transport — see
8
+ # mik_serial_io.cpp, which installs the USB-Serial/JTAG driver through
9
+ # the public API and bypasses VFS entirely. Auto-detection picks
10
+ # whichever interface receives the first byte, same UX as before.
11
+ #
12
+ # ESP_LOG going to UART is harmless in production (we ship with
13
+ # CONFIG_LOG_DEFAULT_LEVEL_NONE=y); for dev, plug a USB-TTL onto
14
+ # UART0 TX/RX to see logs — or re-enable the USB-JTAG console per
15
+ # project if a given board isn't battery-boot-constrained.
16
+ #
17
+ # Secondary console on USB-Serial/JTAG: keeps panic dumps + bootloader
18
+ # messages reachable via the USB monitor even though the primary
19
+ # console is UART0. Without this, a panic is invisible to anyone
20
+ # monitoring over USB (which is most dev boards), because the panic
21
+ # handler writes to the primary console only. During a panic ESP-IDF
22
+ # writes directly to the USB-JTAG hardware registers — it doesn't
23
+ # conflict with mikrojs's driver-level USB-JTAG use for REPL traffic.
24
+ CONFIG_ESP_CONSOLE_UART_DEFAULT=y
25
+ CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=n
26
+ CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG=y
@@ -0,0 +1,22 @@
1
+ # ESP32-S3: route ESP-IDF stdio/ESP_LOG to UART0 rather than the
2
+ # built-in USB Serial/JTAG. See sdkconfig.defaults.esp32c6 for the
3
+ # reasoning (avoid ESP-IDF auto-registering the USB-JTAG VFS / stdio
4
+ # stack at boot). mikrojs installs the USB-Serial/JTAG driver itself
5
+ # via the public API in mik_serial_io.cpp for REPL/TLV transport.
6
+ #
7
+ # Secondary console on USB-Serial/JTAG so panic dumps + bootloader
8
+ # messages still reach a dev monitor attached over USB (the primary
9
+ # UART usually isn't wired up on dev boards). ESP-IDF writes panic
10
+ # output directly to USB-JTAG hardware registers, which doesn't
11
+ # conflict with mikrojs's driver-level registration for regular
12
+ # REPL traffic.
13
+ CONFIG_ESP_CONSOLE_UART_DEFAULT=y
14
+ CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=n
15
+ CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG=y
16
+
17
+ # Enable PSRAM if present. Default mode is quad; boards with octal PSRAM
18
+ # (e.g. XIAO ESP32-S3) must override with CONFIG_SPIRAM_MODE_OCT=y.
19
+ # IGNORE_NOTFOUND: fall back to internal SRAM if PSRAM init fails.
20
+ CONFIG_SPIRAM=y
21
+ CONFIG_SPIRAM_USE_MALLOC=y
22
+ CONFIG_SPIRAM_IGNORE_NOTFOUND=y