-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TLS stops working after initializing the SPI Master device (IDFGH-11065) #12241
Comments
Disabling SPI before sending data does not re-enable TLS (: spi_bus_remove_device(dac_dev); |
Could you provide a minimal code to reproduce the issue? This will help us to locate the issue faster, thanks! |
I made a short demo of the error based on the "Wi-Fi Station Example". The result of his work: "Task watchdog got triggered". If you comment out "Initialize the SPI bus" then everything is ok. |
void app_main(void)
} |
I (1608) wifi station: connected to ap SSID:Misty password:qwerty Backtrace: 0x4200C03A:0x3FC98850 0x40377259:0x3FC98880 0x42077ACD:0x3FCA27C0 0x420220D9:0x3FCA27E0 0x42022502:0x3FCA2820 0x4202390A:0x3FCA2850 0x42023A08:0x3FCA28B0 0x42023A4F:0x3FCA28E0 0x4201A357:0x3FCA2920 0x42013E01:0x3FCA2960 0x42014433:0x3FCA2A10 0x42014A6E:0x3FCA2A50 0x420133C4:0x3FCA2A70 0x420766DA:0x3FCA2AA0 0x4200828D:0x3FCA2AC0 0x4207C7A3:0x3FCA2BE0 0x40377259: _xt_lowint1 at C:/Users/Alex/.espressif/esp-idf/components/xtensa/xtensa_vectors.S:1236 0x42077acd: esp_aes_dma_done at C:/Users/Alex/.espressif/esp-idf/components/mbedtls/port/aes/dma/esp_aes_gdma_impl.c:18 0x420220d9: esp_aes_wait_dma_done at C:/Users/Alex/.espressif/esp-idf/components/mbedtls/port/aes/dma/esp_aes.c:118 0x42022502: esp_aes_crypt_ctr at C:/Users/Alex/.espressif/esp-idf/components/mbedtls/port/aes/dma/esp_aes.c:1074 0x4202390a: esp_aes_gcm_update at C:/Users/Alex/.espressif/esp-idf/components/mbedtls/port/aes/esp_aes_gcm.c:481 0x42023a08: esp_aes_gcm_crypt_and_tag_partial_hw at C:/Users/Alex/.espressif/esp-idf/components/mbedtls/port/aes/esp_aes_gcm.c:578 0x42023a4f: esp_aes_gcm_crypt_and_tag at C:/Users/Alex/.espressif/esp-idf/components/mbedtls/port/aes/esp_aes_gcm.c:705 0x4201a357: mbedtls_cipher_aead_encrypt at C:/Users/Alex/.espressif/esp-idf/components/mbedtls/mbedtls/library/cipher.c:1350 0x42013e01: mbedtls_ssl_encrypt_buf at C:/Users/Alex/.espressif/esp-idf/components/mbedtls/mbedtls/library/ssl_msg.c:993 0x42014433: mbedtls_ssl_write_record at C:/Users/Alex/.espressif/esp-idf/components/mbedtls/mbedtls/library/ssl_msg.c:2757 0x42014a6e: ssl_write_real at C:/Users/Alex/.espressif/esp-idf/components/mbedtls/mbedtls/library/ssl_msg.c:5685 0x420133c4: esp_mbedtls_write at C:/Users/Alex/.espressif/esp-idf/components/esp-tls/esp_tls_mbedtls.c:266 (discriminator 15) 0x420766da: esp_tls_conn_write at C:/Users/Alex/.espressif/esp-idf/components/esp-tls/esp_tls.c:137 0x4200828d: app_main at C:/Distr/ESP-IDF/tls_error_demo/main/tls_error_demo.cpp:272 0x4207c7a3: main_task at C:/Users/Alex/.espressif/esp-idf/components/freertos/app_startup.c:208 (discriminator 13) |
Are you going to fix this bug? I have an additional clarification to this issue. The TLS hang only occurs when the spi bus is initialized in SPI_DMA_DISABLED mode. If the mode is SPI_DMA_CH_AUTO, then TLS works correctly. I have to use DMA to send/receive two bytes to get around the bug |
try creting separate task for tls operation with large stack. I had same problem when doing tls operation in app_main, it can fail due to small stack. .. |
I have provided above a simple example demonstrating this error. It does not launch additional tasks, it does not limit or allocate memory, but it freezes TLS after SPI initialization. No, the problem here is not with memory, the problem is with the SPI driver, which breaks something in DMA. The encryption functions in the ESP32-S3 are implemented in hardware and are invoked using DMA. The SPI driver can also use DMA. When initialized in SPI_DMA_DISABLED mode, SPI should not touch anything in DMA, but it still does something there and breaks DMA. The log shows that the watchdog timer is triggered because the call "esp_aes_wait_dma_done" was waiting too long for completion. Yes, I tried in my program to increase the stack of a task that sends results via TLS. There were 4000 bytes, I made 14000 bytes, then 24000, 34000 - the result did not change |
Hi @DemTerritory , Thanks for detailed issue report, your information helped a lot! We have confirmed this is an issue in the SPI driver. Here's the fix in review:
Hopefully this will show up on Github soon. If you still find problems with the patch above, please poke me. Thanks again! Michael |
Yes this fix works for me. |
You are welcome! |
Answers checklist.
IDF version.
v5.2-dev-2756-g2bc1f2f574
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
None
Development Kit.
ESP32-S3 LOLIN Mini
Power Supply used.
USB
What is the expected behavior?
If the SPI Master device is not initialized, then TLS works normally. After initialization SPI, TLS hangs and watchdog got triggered.
What is the actual behavior?
If the SPI Master device is not initialized, then TLS works normally. After initialization SPI, TLS hangs and watchdog got triggered.
Steps to reproduce.
If the SPI Master device is not initialized, then TLS works normally:
ret_bytes = esp_tls_conn_write(tls, header.c_str(), header.length()); // OK !!!
After initialization SPI, TLS hangs and watchdog got triggered:
ESP_ERROR_CHECK(spi_bus_initialize(DAC_HOST, &dac_bus_cfg, SPI_DMA_DISABLED)); // SPI_DMA_DISABLED !!!
...
ret_bytes = esp_tls_conn_write(tls, header.c_str(), header.length()); // hangs up !!!
In backtrace pay attention to "esp_aes_dma_wait_complete", despite the fact that I did not enable DMA for SPI
Debug Logs.
More Information.
No response
The text was updated successfully, but these errors were encountered: