[原创] 【ESP32学习】使用线程

dcexpert   2018-8-16 20:06 楼主
线程功能其实以前就尝试过,不过当时ESP32的micropython版本还很低,所以这次我们试试新的ESP32固件下线程的情况。
  1. import _thread
  2. from machine import Pin
  3. import time

  4. LED = Pin(21, Pin.OUT)

  5. def led(dt):
  6.     while 1:
  7.         LED.value(not LED.value())
  8.         time.sleep_ms(dt)

  9. def task(id, dt):
  10.     cnt = 0
  11.     while 1:
  12.         cnt = cnt+1
  13.         print('task%d-%d\n'%(id, cnt))
  14.         time.sleep_ms(dt)

  15. _thread.start_new_thread(led, (500,))
  16. _thread.start_new_thread(task, (1, 500))
  17. _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
I (453) spiram: SPI RAM mode: flash 40m sram 40m
I (453) spiram: PSRAM initialized, cache is in normal (1-core) mode.
I (454) cpu_start: Pro cpu up.
I (458) cpu_start: Single core mode
I (1327) spiram: SPI SRAM memory test OK
I (1327) heap_init: Initializing. RAM available for dynamic allocation:
I (1328) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (1334) heap_init: At 3FFC51D0 len 0001AE30 (107 KiB): DRAM
I (1340) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (1346) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (1353) heap_init: At 40095384 len 0000AC7C (43 KiB): IRAM
I (1359) cpu_start: Pro cpu start user code
I (1364) spiram: Adding pool of 4096K of external SPI memory to heap allocator
I (1372) spiram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (52) cpu_start: Starting scheduler on PRO CPU.
I (202) modsocket: Initializing
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
I (232) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (242) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
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原创,如需转载或用于商业用途需征得作者同意并注明出处


回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复