guild icon
Toit
#Problems with highspeed UART and interrupt flags
Thread channel in help
Rikke
Rikke 01/06/2023 10:34 AM
Hello,
We have a problem with creating a 2nd UART. The first UART is low speed, and we want to make a second UART with --baud_rate=2_500_000 from the toit-pixel-strip package. We get the following error when creating the driver:
****************************************************************************** Decoding by `jag`, device has version <2.0.0-alpha.47> ****************************************************************************** EXCEPTION error. UNKNOWN ERROR 0x105(261) 0: uart_create_ <sdk>/uart.toit:310:3 1: Port <sdk>/uart.toit:99:13 2: UartPixelStrip <pkg:toit-pixel-strip>/uart.toit:124:13 3: setLED_.<block> ../src/pinout.toit:254:18 4: catch.<block> <sdk>/core/exceptions.toit:124:10 5: catch <sdk>/core/exceptions.toit:122:1 6: catch <sdk>/core/exceptions.toit:73:10 7: setLED_ ../src/pinout.toit:253:12 8: update_connection_LED_ ../src/pinout.toit:195:5 9: update_AP_status_LED ../src/pinout.toit:191:3 10: main ../src/gateway.toit:35:3 ******************************************************************************
followed by ALREADY_IN_USE everytime it is called.

The UNKNOWN ERROR 0x105 has been traced down to a ESP_ERR_NOT_FOUND error, and located in the file intr_alloc.c in function esp_err_t esp_intr_alloc_intrstatus(:
Rikke
Rikke 01/06/2023 10:34 AM
third_party/esp-idf/components/esp_hw_support/intr_alloc.c:486: int intr=get_available_int(flags, cpu, force, source); third_party/esp-idf/components/esp_hw_support/intr_alloc.c-487- if (intr==-1) { third_party/esp-idf/components/esp_hw_support/intr_alloc.c-488- //None found. Bail out. third_party/esp-idf/components/esp_hw_support/intr_alloc.c-489- portEXIT_CRITICAL(&spinlock); third_party/esp-idf/components/esp_hw_support/intr_alloc.c-490- free(ret); third_party/esp-idf/components/esp_hw_support/intr_alloc.c-491- return ESP_ERR_NOT_FOUND; third_party/esp-idf/components/esp_hw_support/intr_alloc.c-492- }

This happens when the uart create is called with ESP_INTR_FLAG_LEVEL3.
The flag is set because of the high baud rate as seen in toit/lib/uart.toit from line 95

tx_flags := (invert_tx ? 1 : 0) + (invert_rx ? 2 : 0) if high_priority == null: high_priority = baud_rate >= 460800 if high_priority: tx_flags |= 8
Rikke
Rikke 01/06/2023 10:34 AM
And the new priority is set in toit/src/resources/uart_esp32.cc from line 208
int interrupt_flags = ESP_INTR_FLAG_IRAM; if ((args.options & 8) != 0) { // High speed setting. interrupt_flags |= ESP_INTR_FLAG_LEVEL3;

If we comment out the new priority settings, the second UART works like before :๐Ÿ™‚: It looks like we don't have the resources for the level 3 priority uart interrupts.
If we set the baud rate lower on toit-pixel-strip, the uart create works, but that means the LEDs aren't working properly.
erikcorry
erikcorry 01/06/2023 12:39 PM
Ah, this is not optimal.
erikcorry
erikcorry 01/06/2023 12:39 PM
It should probably fall back to low priority rather than throw "UNKNOWN ERROR"
Rikke
Rikke 01/06/2023 12:52 PM
That should work yes, try lower priority or something
erikcorry
erikcorry 01/06/2023 02:05 PM
I think the best solution is to release a new version of the pixel_strip library that has a flag for high priority.
Rikke
Rikke 01/06/2023 03:10 PM
Looks fine to me :๐Ÿ™‚:
9 messages in total