Open willianaraujo opened 1 year ago
I kept looking for the issue and found the root cause, but I'm not exactly sure why the problem started happening. I believe it could be due to an update in ESP-IDF or FreeRTOS, someone with more experience in embedded systems might know...
Basically, in the u8g2_esp32_spi_byte_cb() function when filling out the fields of the dev_config variable to send to the spi_bus_add_device() function, none of the documentation I found instructed to pass the dev_config.clock_source field, but from what I saw in the functions that are called from here, this information is needed.
So, the error above was caused because the dev_config.clock_source field is not being filled in the u8g2_esp32_spi_byte_cb function before passing the dev_config as a parameter in the line ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &dev_config, &handle_spi));
This way the initialization for the dev_config parameter would look like this:
spi_device_interface_config_t dev_config;
dev_config.address_bits = 0;
dev_config.command_bits = 0;
dev_config.dummy_bits = 0;
dev_config.mode = 0;
dev_config.duty_cycle_pos = 0;
dev_config.cs_ena_posttrans = 0;
dev_config.cs_ena_pretrans = 0;
dev_config.clock_speed_hz = 10000;
dev_config.clock_source = SPI_CLK_SRC_DEFAULT; //SOC_MOD_CLK_APB;
dev_config.spics_io_num = u8g2_esp32_hal.cs;
dev_config.flags = 0;
dev_config.queue_size = 200;
dev_config.pre_cb = NULL;
dev_config.post_cb = NULL;
//ESP_LOGI(TAG, "... Adding device bus.");
ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &dev_config, &handle_spi));
That's it. Looking at the current ESP-IDF code, I can't understand how my previous code worked without this field, as browsing through previous versions of ESP-IDF on GitHub, this information was always mandatory.
I won't mark this thread as resolved since, as I mentioned, I don't understand why it worked before. Therefore, my solution might not be the correct one, or everything I said may not make sense, but as I'm behind schedule with my project, I won't delve further into this investigation.
Cheers!
I have noticed this issue as well.
Using Kolban's HAL I get the same crash after updating from 4.2 to 5.1, but only when I have logging set to INFO or higher.
Otherwise I get the same crash.
Going to try the your solution now.
I added the clock source and it built with logging set to none.
Was still flaky telling me the argument was invalid, so I put a 2 second delay before my call to "u8g2_Setup_st7920_128x64_f();" and now it seems to run perfectly.
I am wondering if it has to do with how fast the device is booting now, and thinking maybe its trying to set that clock source before the chip can initialize it?
Either way its interesting.
Thanks for the initial post, helped me a lot.
the bug is in the line:
spi_device_interface_config_t dev_config;
in u8g2_esp32_hal.c
. Members that are not set, have garbage values.
the solution is to use memset, or simply initialize the variable with:
spi_device_interface_config_t dev_config = {0};
that assures that all members of dev_config
are intialized with 0; Then spi_bus_add_device()
will detect that the member .clock_source
is cero and set the value SPI_CLK_SRC_DEFAULT
.
I'm using an ESP32 WROOM32 DEVKIT board, a 128x64 display with ST7920 chip. My development environment is ESP-IDF in VSCode. I created a project from scratch, added only the U8G2 library directly from the official repository on GitHub following the official documentation. I also added Kolban's component, the u8g2_esp32_hal to interface with the main u8g2 library.
The first time I used this combination of libraries, still last year, it worked perfectly.... after approximately 6 months without running the development environment, I returned to work on the project, reinstalled VSCode, ESP-IDF, U8G2, and U8G2_esp32_hal, all from the official repositories in their current versions. However, now my CPU started to restart repeatedly when I try to start SPI communication between the ESP32 and the ST7920. I even suspected the hardware, so I got a new DEVKIT board, a new display, and connected the display directly to the board, without any peripherals, just display-esp, and the board keeps resetting...
My boot log is as follows:
The reason for the reset is specifically the lines below:
I realized that the error is related to the speed of my SPI, but I remember not having changed anything in relation to the SPI speed the last time I was able to make everything work. And this time it also doesn't work, even with a clean project, with all the default settings.
I tried adjusting the clock speed to 1MHz, 10MHz, and 530KHz when invoking the spi_bus_add_device( function within the u8g2_esp32_hal component, but any speed I put the cyclic reset continues.
Below my complete main code:
and below my code of the u8g2_esp32_spi_byte_cb() function of the u8g2_esp32_hal component, it is in this function that I tried those different speeds for the SPI clock:
Why can't I even run the example codes anymore, whereas last year everything worked perfectly, I even developed several applications with screens, menus, and animations on this same hardware...