elcritch / esp32_nim_net_example

esp32_nim_net_example
4 stars 1 forks source link

Issues building - missing SIGPIPE and more #1

Closed stisa closed 4 years ago

stisa commented 4 years ago

Hi, I've tried building this repo after freertos support was merged in nim, but I have some issues building. It seems that posix_freertos is missing SIGPIPE, SIG_BLOCK, SIG_UNBLOCK. I changed the flags to be --os:freertos --cpu:esp which I think is the way that the merged branch expects.

I'm on windows, building in a ESP-IDF command prompt with nim devel. (and pretty new to esp32 programming)

stisa commented 4 years ago

EDIT: Uncommenting SIGPIPE, SIG_BLOCK, SIG_UNBLOCK actually seems to work, I got a simple Wifi server example working. Probably just an issue with me not knowing what I'm doing when setting up ethernet.

I also tried uncommenting the missing values from posix_freertos_consts.nim, but no dice. Nim builds but there are problems running it.

My steps:

--- idf_monitor on COM5 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
I (347) boot: Loaded app from partition at offset 0x10000
I (347) boot: Disabling RNG early entropy source...
I (347) cpu_start: Pro cpu up.
I (351) cpu_start: Application information:
I (356) cpu_start: Project name:     hello-world
I (361) cpu_start: App version:      c893de3-dirty
I (367) cpu_start: Compile time:     Sep  7 2020 18:45:26
I (373) cpu_start: ELF file SHA256:  16b538dbcb79ea6a...
I (379) cpu_start: ESP-IDF:          v4.0.1-dirty
I (384) cpu_start: Starting app cpu, entry point is 0x4008115c
0x4008115c: call_start_cpu1 at C:/Dev/esp-idf/components/esp32/cpu_start.c:271

I (370) cpu_start: App cpu up.
I (395) heap_init: Initializing. RAM available for dynamic allocation:
I (402) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (408) heap_init: At 3FFB45D8 len 0002BA28 (174 KiB): DRAM
I (414) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (420) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (427) heap_init: At 4008A2E4 len 00015D1C (87 KiB): IRAM
I (433) cpu_start: Pro cpu start user code
I (451) spi_flash: detected chip: generic
I (452) spi_flash: flash io: dio
I (452) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Hello world!
I (4455) gpio: GPIO[4]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (5455) eth_example: esp starting ...
I (5455) eth_example: starting...
I (5455) eth_example: phy config...
I (5455) eth_example: dp83848 starting...
I (5455) eth_example: dp83848 done...
E (5565) emac_esp32: emac_esp32_init(303): reset timeout
E (5565) esp_eth: esp_eth_driver_install(192): init mac failed
ESP_ERROR_CHECK failed: esp_err_t 0xffffffff (ESP_FAIL) at 0x40085314
0x40085314: _esp_error_check_failed at C:/Dev/esp-idf/components/esp32/panic.c:726

file: "../main/ethernet_example_main.c" line 124
func: app_main
expression: esp_eth_driver_install(&config, &eth_handle)

ELF file SHA256: 16b538dbcb79ea6a

Backtrace: 0x40084d71:0x3ffb6320 0x40085317:0x3ffb6340 0x400d6051:0x3ffb6360 0x400d2332:0x3ffb63e0 0x40087545:0x3ffb6400
0x40084d71: invoke_abort at C:/Dev/esp-idf/components/esp32/panic.c:155

0x40085317: _esp_error_check_failed at C:/Dev/esp-idf/components/esp32/panic.c:727

0x400d6051: app_main at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\build/../main/ethernet_example_main.c:124 (discriminator 1)

0x400d2332: main_task at C:/Dev/esp-idf/components/esp32/cpu_start.c:553

0x40087545: vPortTaskWrapper at C:/Dev/esp-idf/components/freertos/port.c:143

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (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
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:6924
load:0x40078000,len:14076
ho 0 tail 12 room 4
load:0x40080400,len:4352
entry 0x400806ec
I (71) boot: Chip Revision: 1
I (72) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (41) boot: ESP-IDF v4.0.1-dirty 2nd stage bootloader
I (41) boot: compile time 18:45:59
I (41) boot: Enabling RNG early entropy source...
I (47) boot: SPI Speed      : 40MHz
I (51) boot: SPI Mode       : DIO
I (55) boot: SPI Flash Size : 4MB
I (59) boot: Partition Table:
I (62) boot: ## Label            Usage          Type ST Offset   Length
I (70) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (77) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (85) boot:  2 factory          factory app      00 00 00010000 00100000
I (92) boot: End of partition table
I (96) boot_comm: chip revision: 1, min. application chip revision: 0
I (103) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x13078 ( 77944) map
I (140) esp_image: segment 1: paddr=0x000230a0 vaddr=0x3ffb0000 size=0x02134 (  8500) load
I (144) esp_image: segment 2: paddr=0x000251dc vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _WindowOverflow4 at C:/Dev/esp-idf/components/freertos/xtensa_vectors.S:1778

I (147) esp_image: segment 3: paddr=0x000255e4 vaddr=0x40080400 size=0x09ee4 ( 40676) load
I (173) esp_image: segment 4: paddr=0x0002f4d0 vaddr=0x00000000 size=0x00b40 (  2880)
I (174) esp_image: segment 5: paddr=0x00030018 vaddr=0x400d0018 size=0x6df14 (450324) map
0x400d0018: _stext at ??:?

I (347) boot: Loaded app from partition at offset 0x10000
I (347) boot: Disabling RNG early entropy source...
I (347) cpu_start: Pro cpu up.
I (351) cpu_start: Application information:
I (356) cpu_start: Project name:     hello-world
I (361) cpu_start: App version:      c893de3-dirty
I (367) cpu_start: Compile time:     Sep  7 2020 18:45:26
I (373) cpu_start: ELF file SHA256:  16b538dbcb79ea6a...
I (379) cpu_start: ESP-IDF:          v4.0.1-dirty
I (384) cpu_start: Starting app cpu, entry point is 0x4008115c
0x4008115c: call_start_cpu1 at C:/Dev/esp-idf/components/esp32/cpu_start.c:271

I (370) cpu_start: App cpu up.
I (395) heap_init: Initializing. RAM available for dynamic allocation:
I (402) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (408) heap_init: At 3FFB45D8 len 0002BA28 (174 KiB): DRAM
I (414) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (420) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (427) heap_init: At 4008A2E4 len 00015D1C (87 KiB): IRAM
I (433) cpu_start: Pro cpu start user code
I (451) spi_flash: detected chip: generic
I (452) spi_flash: flash io: dio
I (452) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Hello world!
I (4455) gpio: GPIO[4]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (5455) eth_example: esp starting ...
I (5455) eth_example: starting...
I (5455) eth_example: phy config...
I (5455) eth_example: dp83848 starting...
I (5455) eth_example: dp83848 done...
E (5565) emac_esp32: emac_esp32_init(303): reset timeout
E (5565) esp_eth: esp_eth_driver_install(192): init mac failed
ESP_ERROR_CHECK failed: esp_err_t 0xffffffff (ESP_FAIL) at 0x40085314
0x40085314: _esp_error_check_failed at C:/Dev/esp-idf/components/esp32/panic.c:726

file: "../main/ethernet_example_main.c" line 124
func: app_main
expression: esp_eth_driver_install(&config, &eth_handle)

ELF file SHA256: 16b538dbcb79ea6a

Backtrace: 0x40084d71:0x3ffb6320 0x40085317:0x3ffb6340 0x400d6051:0x3ffb6360 0x400d2332:0x3ffb63e0 0x40087545:0x3ffb6400
0x40084d71: invoke_abort at C:/Dev/esp-idf/components/esp32/panic.c:155

0x40085317: _esp_error_check_failed at C:/Dev/esp-idf/components/esp32/panic.c:727

0x400d6051: app_main at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\build/../main/ethernet_example_main.c:124 (discriminator 1)

0x400d2332: main_task at C:/Dev/esp-idf/components/esp32/cpu_start.c:553

0x40087545: vPortTaskWrapper at C:/Dev/esp-idf/components/freertos/port.c:143

Rebooting...

<continues...>
elcritch commented 4 years ago

That's odd regarding SIGPIPE, SIG_BLOCK, SIG_UNBLOCK. It may be a change on the devel branch, I haven't had a chance to verify the builds. Also, you need to specify -d:useMalloc and a few other things. The Nim flags are split between the nim.cfg and the Makefile. It's best to use the Makefile via make nim or just make. Still I'll check those flags.

elcritch commented 4 years ago

The second problem is that the example is setup to run on a board with an ethernet chip. It'll crash and reboot if the ethernet chip isn't present. I haven't made a generic ESP32 example, though I'd like to...

ESP-IDF prints the stack trace as the last bit with:

file: "../main/ethernet_example_main.c" line 124 func: app_main expression: esp_eth_driver_install(&config, &eth_handle)

Still you can copy pretty much almost any ESP32 example into the ./main/. Just be sure to add the lines for Nim:

    NimMain();
    printf("NimMain!\n");
    run_http_server(); // this one is a Nim proc with {.exportc.}
    printf("run_http_server\n");

Also, note that Nim's async http server only runs a few dozen requests before it crashes (due to issues with arc/orc). It's getting closer, but not quite ready yet. :/

My route, in a private repo currently, uses select to service network requests which works surprisingly well and is built into ESP-IDF. If you're interested I'll work on making it public.

elcritch commented 4 years ago

P.S. What board are you working with? I've also wrapped a fair bit of the basic FreeRTOS libraries, but I've not had time to put them in a Nim library. I'm new-ish to Nim, and haven't made a library yet.

stisa commented 4 years ago

Yeah I figured the missing ethernet chip after a while, sorry, I'm fairly new to esp programming.

I'm using the nim.cfg and makefile yeah, the ones I mentioned where just the flags I changed to match the devel compiler. But I'm planning to move it to a config.nims file, just waiting on some arc bugs to get fixed and the we'll be able to do nim prepare <file.nim> to compile, thanks to nimscript tasks.

I'm playing with an ESP32-CAM that I got months ago and never used.
As I was saying, I got the http_server/simple example with wifi to work, I'll try to clean it up an send a pr soonish. After that I think I'll try to remove the need for the separate C main file, and I think we can avoid copying nimbase.h by setting some flags, probably --cincludes:<path> (nimc).

stisa commented 4 years ago

And yeah the sigpipe changes seem fairly recente, see https://github.com/nim-lang/Nim/commit/c619cedd7cba60d588707fbbb2905c8ac85fd12a

elcritch commented 4 years ago

Oh, thanks! I'll have to test that works. It may not work with FreeRTOS posix. Uncommenting those lines will fix the Nim compile, but may break runtime with sockets.

stisa commented 4 years ago

Yeah I figured just uncommenting isn't a proper fix, nice to see you already made a PR!

elcritch commented 4 years ago

The PR was merged! https://github.com/nim-lang/Nim/pull/15303 at commit 6c49767a6c656fb097df71c41e4f123380bc1ca9.