线程功能其实以前就尝试过,不过当时ESP32的micropython版本还很低,所以这次我们试试新的ESP32固件下线程的情况。
- import _thread
- from machine import Pin
- import time
- LED = Pin(21, Pin.OUT)
- def led(dt):
- while 1:
- LED.value(not LED.value())
- time.sleep_ms(dt)
- def task(id, dt):
- cnt = 0
- while 1:
- cnt = cnt+1
- print('task%d-%d\n'%(id, cnt))
- time.sleep_ms(dt)
- _thread.start_new_thread(led, (500,))
- _thread.start_new_thread(task, (1, 500))
- _thread.start_new_thread(task, (2, 1500))
测试发现,不使用psRAM的固件上,线程功能运行正常,稳定方便。但是在psRAM固件版本上,运行就会出错,提示如下:
引用: /home/micropython/esp-idf/components/freertos/tasks.c:686 (xTaskCreateStaticPinnedToCore)- assert failed!
abort() was called at PC 0x4008e63b on core 0
Backtrace: 0x4009084b:0x3ffb6b70 0x4009087c:0x3ffb6b90 0x4008e63b:0x3ffb6bb0 0x400f49c2:0x3ffb6bf0 0x400f4a21:0x3ffb6c30 0x400e8e35:0x3ffb6c50 0x400e0102:0x3ffb6c80 0x400dc251:0x3ffb6cb0 0x400dc2b9:0x3ffb6cd0 0x400e9d3a:0x3ffb6cf0 0x400e018c:0x3ffb6d90 0x400dc251:0x3ffb6e00 0x400dc27e:0x3ffb6e20 0x400fb20a:0x3ffb6e40 0x400fb454:0x3ffb6ee0 0x400f134c:0x3ffb6f20
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
modeIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4732
load:0x40078000,len:8256
load:0x40080400,len:6132
entry 0x4008124c
[0;32mI (453) spiram: SPI RAM mode: flash 40m sram 40m[0m
[0;32mI (453) spiram: PSRAM initialized, cache is in normal (1-core) mode.[0m
[0;32mI (454) cpu_start: Pro cpu up.[0m
[0;32mI (458) cpu_start: Single core mode[0m
[0;32mI (1327) spiram: SPI SRAM memory test OK[0m
[0;32mI (1327) heap_init: Initializing. RAM available for dynamic allocation:[0m
[0;32mI (1328) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM[0m
[0;32mI (1334) heap_init: At 3FFC51D0 len 0001AE30 (107 KiB): DRAM[0m
[0;32mI (1340) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM[0m
[0;32mI (1346) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[0m
[0;32mI (1353) heap_init: At 40095384 len 0000AC7C (43 KiB): IRAM[0m
[0;32mI (1359) cpu_start: Pro cpu start user code[0m
[0;32mI (1364) spiram: Adding pool of 4096K of external SPI memory to heap allocator[0m
[0;32mI (1372) spiram: Reserving pool of 32K of internal memory for DMA/internal allocations[0m
[0;32mI (52) cpu_start: Starting scheduler on PRO CPU.[0m
[0;32mI (202) modsocket: Initializing[0m
I (232) wifi: wifi driver task: 3ffcc378, prio:23, stack:3584, core=0
I (232) wifi: wifi firmware version: 7aac1f9
I (232) wifi: config NVS flash: enabled
I (232) wifi: config nano formating: disabled
[0;32mI (232) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE[0m
[0;32mI (242) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE[0m
I (272) wifi: Init dynamic tx buffer num: 32
I (272) wifi: Init data frame dynamic rx buffer num: 64
I (272) wifi: Init management frame dynamic rx buffer num: 64
I (272) wifi: Init static rx buffer size: 1600
I (282) wifi: Init static rx buffer num: 10
I (282) wifi: Init dynamic rx buffer num: 0
Started webrepl in normal mode
OSError: [Errno 2] ENOENT
看起来是对psRAM的支持上有冲突,需要等待固件升级了。
此内容由EEWORLD论坛网友dcexpert原创,如需转载或用于商业用途需征得作者同意并注明出处