Problems with highspeed UART and interrupt flags
# help
r
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:
Copy code
******************************************************************************
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(`:
Copy code
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
Copy code
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
And the new priority is set in
toit/src/resources/uart_esp32.cc
from line 208
Copy code
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.
e
Ah, this is not optimal.
It should probably fall back to low priority rather than throw "UNKNOWN ERROR"
r
That should work yes, try lower priority or something
e
I think the best solution is to release a new version of the pixel_strip library that has a flag for high priority.
r
Looks fine to me 🙂
2 Views