ESP32_minimal
ESP32_minimal copied to clipboard
Having some troubles...
Thank you for providing this example and the writeup https://vivonomicon.com/2019/03/30/getting-started-with-bare-metal-esp32-programming/ I tried it, but it seems to be stuck. Monitoring /dev/ttyUSB0 after flashing outputs the following about once per second:
rst:0x10 (RTCWDT_RTC_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:0x3fff0000,len:0
load:0x40080400,len:508
entry 0x400805d8
ets Jun 8 2016 00:22:57
What should be happening? And what exactly do you mean in the README.md by flashing an app with the 'default 'single-app' partition'?
Good questions, thanks for bringing them up. I'm still very new to the ESP32 SoC, so please keep in mind that I don't have a complete understanding of how the boot process works yet. Most of what I've gleaned has come from the technical reference manual and Espressif's excellent ESP-IDF.
But with this demo program, nothing is actually supposed to 'happen' from an outside perspective. All that it does is increment a variable in an infinite loop to verify that the main program was successfully loaded, so you will need to observe the program running in the GDB debugger to see whether it works as expected. The easiest way to do that is to follow the instructions in the "Command Line" section of Espressif's "Using Debugger" guide:
https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/jtag-debugging/using-debugger.html#command-line
Once the program is running in a debugger session, you should be able to hit ctrl+c
to halt it and p sisyphus
to see the current value of the test variable.
The 'default single-app partition' file is included in the ESP-IDF:
https://github.com/espressif/esp-idf/blob/master/components/partition_table/partitions_singleapp.csv
And to clarify why I mentioned it in the README: the ESP32 has no re-writable non-volatile memory inside the chip, so most modules include an external Flash chip 'under the hood' which the ESP32 loads its code from when it boots. Unfortunately, I'm not quite sure how to tell the ESP32 which address on the external Flash chip its 'first-stage' bootloader is located at yet. But that configuration is stored in non-volatile memory, which means that it doesn't get erased when you overwrite a previously-flashed program. So until I work out how to configure the first-stage bootloader address in Flash, it is necessary to upload an example program from ESP-IDF (such as their 'hello world' demo) before one of these test 'bare metal' programs will work correctly. If you don't, the chip may not know where to look on its external Flash chip for the program data.
Sorry about the inconvenience and lack of clarity - I will try to make the README more clear and/or figure out how the chip configures its first-stage bootloader when I have more time to investigate.
Also, if you want to actually develop applications for the ESP32 rather than learning about its internals, using the ESP-IDF will probably be much quicker and easier than writing your own libraries and bootloader. It is Apache-licensed and it benefits from both widespread community adoption and support from the vendor.
Thanks for your reply.
I still don't understand if your code is intended to keep resetting every second (if that's what's happening), or if something went wrong in how I starting it. Is this what happens if I fail to initialize the bootloader by loading an example?
It's not supposed to reset every second, but it might if your chip has its watchdog set up. The example program only increments one variable - it does not 'pet the watchdog', so if that is enabled it will periodically reset the chip.
If I recall correctly, the watchdog settings are also stored in nonvolatile memory, so they will probably persist when you flash this test program. It is one of the options which you can configure in an ESP-IDF project using make menuconfig
. I believe the watchdog options should be under "component config -> ESP32-specific".
More info here: https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/wdts.html
Again, sorry for the rough state of this example, but it is my first bare metal ESP32 application and I've gotten a little distracted by other chips in the meantime.
Thanks. No apologies necessary - thank you for sharing your findings!