Skip to content

Commit d40831b

Browse files
committed
Improved MicroPython configuration handling and checking
1 parent b503ebd commit d40831b

File tree

10 files changed

+159
-100
lines changed

10 files changed

+159
-100
lines changed

firmware/MaixPy.bin

0 Bytes
Binary file not shown.

firmware/MaixPy_firmware.zip

101 Bytes
Binary file not shown.

firmware/MaixPy_sqlite.bin

0 Bytes
Binary file not shown.

firmware/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# MicroPython for Kendryte K210
22

33

4-
To flush the pre-built firmware to your K210 board, run (in this directory):
4+
To flash the pre-built firmware to your K210 board, run (in this directory):
55

66
```
77
./kflash.py -p /dev/ttyUSB0 -b 2000000 -t MaixPy.bin

k210-freertos/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ static void mp_task_proc1(void *pvParameter)
260260

261261
thread_msg_t msg;
262262

263+
vTaskDelay(5);
263264
if (flash_fs_ok) {
264265
// set mount point for flash file system
265266
mp_vfs_mount_t *vfs = m_new_obj_maybe(mp_vfs_mount_t);
@@ -283,6 +284,7 @@ static void mp_task_proc1(void *pvParameter)
283284
}
284285
}
285286

287+
vTaskDelay(5);
286288
// ==== Main 2nd MicroPPython instance loop ========
287289
while (1) {
288290
// === Wait for command from main (or other) MicroPython task ===
@@ -543,6 +545,7 @@ int main()
543545
while (!task0_started) {
544546
vTaskDelay(10);
545547
}
548+
vTaskDelay(50);
546549
res = xTaskCreateAtProcessor(
547550
MAIN_TASK_PROC ^ 1, // MPy instance #2 processor
548551
mp_task_proc1, // function entry

k210-freertos/mpy_support/mpconfigport.h

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
// Options to control how MicroPython is built
3939
// ===========================================
4040

41+
#define MICROPY_HW_BOARD_NAME "Sipeed_board"
42+
#define MICROPY_HW_MCU_NAME "Kendryte-K210"
43+
#define MICROPY_PY_SYS_PLATFORM "K210/FreeRTOS"
44+
#define MICROPY_PY_LOBO_VERSION "1.11.5"
45+
#define MICROPY_PY_LOBO_VERSION_NUM (0x011105)
46+
4147
/*
4248
Several basic configurations can be selected for build:
4349
-------------------------------------------------------
@@ -46,6 +52,19 @@
4652
3. Two MicroPython instances with PyStack enabled
4753
4. Two MicroPython instances without PyStack enabled
4854
-------------------------------------------------------
55+
56+
The following options are configurable on runtime from MicroPython:
57+
-------------------------------------------------------------------
58+
- running two MPy instances
59+
- using PyStack
60+
- heap size
61+
- PyStack size
62+
- MicroPython task(s) stack size
63+
- default CPU frequency
64+
- default REPL baudrate
65+
- boot menu pin
66+
- default log level
67+
- MicroPython VM divisor
4968
*/
5069

5170
//---------------------------------------------------------------------------
@@ -64,7 +83,7 @@
6483
#define MICROPY_K210_KPU_USED (0)
6584

6685
// sqlite3 module uses ~416 KB of code (and SRAM) space
67-
#define MICROPY_PY_USE_SQLITE (1)
86+
#define MICROPY_PY_USE_SQLITE (0)
6887

6988
//---- K210 Memory usage -------------------------------------------------------------------------------------
7089
// MicroPython heap is allocated from FreeRTOS heap which is allocated at system start
@@ -97,16 +116,31 @@
97116
// including MicroPython heap and PyStack
98117
#define FREE_RTOS_TOTAL_HEAP_SIZE (( size_t )(K210_SRAM_SIZE - FIRMWARE_SIZE - RESERVED_FOR_SYSTEM))
99118
// === Reserved size of FreeRTOS heap
100-
#define MICRO_PY_FREE_RTOS_RESERVED (3*256*1024)
119+
#define MICRO_PY_FREE_RTOS_RESERVED (7*128*1024)
101120
// === FreeRTOS heap used for MicroPython heap
102121
#define MICRO_PY_MAX_HEAP_SIZE (FREE_RTOS_TOTAL_HEAP_SIZE - MICRO_PY_FREE_RTOS_RESERVED)
122+
#define MICRO_PY_MIN_HEAP_SIZE (128*1024)
103123
#if MICROPY_USE_TWO_MAIN_TASKS
104124
#define MICROPY_HEAP_SIZE (MICRO_PY_MAX_HEAP_SIZE * 5 / 8)
105125
#define MICROPY_HEAP_SIZE2 (MICRO_PY_MAX_HEAP_SIZE * 3 / 8)
106126
#else
107127
#define MICROPY_HEAP_SIZE (MICRO_PY_MAX_HEAP_SIZE)
108128
#define MICROPY_HEAP_SIZE2 (0)
109129
#endif
130+
131+
// === MicroPython main task stack size in bytes ===
132+
#define MICROPY_TASK_STACK_RESERVED (512)
133+
#define MICROPY_TASK_STACK_SIZE (32 * 1024)
134+
// === MicroPython main task stack size in stack_type units (64-bits) ===
135+
#define MICROPY_TASK_STACK_LEN (MICROPY_TASK_STACK_SIZE / sizeof(StackType_t))
136+
137+
#define MICRO_PY_MIN_PYSTACK_SIZE (2*1024)
138+
#define MICRO_PY_MAX_PYSTACK_SIZE (32*1024)
139+
#if MICROPY_ENABLE_PYSTACK
140+
#define MICROPY_PYSTACK_SIZE (4096)
141+
#else
142+
#define MICROPY_PYSTACK_SIZE (0)
143+
#endif
110144
//------------------------------------------------------------------------------------------------------------
111145

112146

@@ -185,18 +219,6 @@ extern void vm_loop_hook();
185219
#define MICROPY_THREAD_STACK_SIZE (2048) // default thread stack size in STACK UNITS (8 bytes)
186220
#define MICROPY_TASK_PRIORITY (8) // default thread priority
187221

188-
// === MicroPython main task stack size in bytes ===
189-
#define MICROPY_TASK_STACK_RESERVED (512)
190-
#define MICROPY_TASK_STACK_SIZE (32 * 1024)
191-
// === MicroPython main task stack size in stack_type units (64-bits) ===
192-
#define MICROPY_TASK_STACK_LEN (MICROPY_TASK_STACK_SIZE / sizeof(StackType_t))
193-
194-
#if MICROPY_ENABLE_PYSTACK
195-
#define MICROPY_PYSTACK_SIZE (4096)
196-
#else
197-
#define MICROPY_PYSTACK_SIZE (0)
198-
#endif
199-
200222
// === Buffer size for UART used as RELP standard input/output ===
201223
#define MICRO_PY_UARTHS_BUFFER_SIZE (1280)
202224

@@ -593,12 +615,6 @@ extern const struct _mp_obj_module_t mp_module_usqlite3;
593615
#define MICROPY_PY_MACHINE (1)
594616
#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new
595617

596-
#define MICROPY_HW_BOARD_NAME "Sipeed_board"
597-
#define MICROPY_HW_MCU_NAME "Kendryte-K210"
598-
#define MICROPY_PY_SYS_PLATFORM "K210/FreeRTOS"
599-
#define MICROPY_PY_LOBO_VERSION "1.11.4"
600-
#define MICROPY_PY_LOBO_VERSION_NUM (0x011104)
601-
602618
#define MP_STATE_PORT MP_STATE_VM
603619

604620
#define MICROPY_PORT_ROOT_POINTERS \

k210-freertos/mpy_support/mpthreadport.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ TaskHandle_t mp_thread_create(void *entry, thread_entry_args_t *arg, size_t task
349349
pystack_size = MICROPY_PYSTACK_SIZE; //use default PyStackstack size
350350
}
351351
else {
352-
if (pystack_size < MP_THREAD_MIN_PYSTACK_SIZE) pystack_size = MP_THREAD_MIN_PYSTACK_SIZE;
353-
else if (pystack_size > MP_THREAD_MAX_PYSTACK_SIZE) pystack_size = MP_THREAD_MAX_PYSTACK_SIZE;
352+
if (pystack_size < MICRO_PY_MIN_PYSTACK_SIZE) pystack_size = MICRO_PY_MIN_PYSTACK_SIZE;
353+
else if (pystack_size > MICRO_PY_MAX_PYSTACK_SIZE) pystack_size = MICRO_PY_MAX_PYSTACK_SIZE;
354354
}
355355
pystack_size = (pystack_size / 8) * 8;
356356
}

k210-freertos/mpy_support/mpthreadport.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@
6868
#define MP_THREAD_DEFAULT_STACK_SIZE 1024 // in stack_type units (64-bits)
6969
#define MP_THREAD_MAX_STACK_SIZE (16*1024) // in stack_type units (64-bits)
7070

71-
#define MP_THREAD_MIN_PYSTACK_SIZE 2048
72-
#define MP_THREAD_MAX_PYSTACK_SIZE 65536
73-
7471
#define THREAD_NAME_MAX_SIZE 16
7572
#define THREAD_MGG_BROADCAST 0xFFFFEEEE
7673
#define THREAD_MSG_TYPE_NONE 0

0 commit comments

Comments
 (0)