https://toitlang.org/ logo
GPIO pin in use; how to debug this?
# help
o
I'm trying to connect to an ublox neo-6m via uart; I've soldered the wires from pins 20 and 21 of my ESP32 C3 to the RX and TX terminals on the gps board (crossed, so RX -> TX and TX -> RX). When I try to run a minimal program, it bails out with an "already in use exception". How can I find out what's going wrong? Program:
Copy code
import gpio
import uart
import ublox-gnss

RX ::= 20
TX ::= 21

main:
  port := uart.Port
    --rx=gpio.Pin RX          //   <--- this is line 10
    --tx=gpio.Pin TX
    --baud-rate=9600

  task::
    reader := port.in
    while line := reader.read-line:
      print "Received: $line"
Error:
Copy code
******************************************************************************
Decoding by `jag`, device has version <2.0.0-alpha.158>
******************************************************************************
EXCEPTION error. 
ALREADY_IN_USE
  0: gpio-use_                 <sdk>/gpio/pin.toit:394:3
  1: Pin                       <sdk>/gpio/pin.toit:131:17
  2: main                      gps.toit:10:10
******************************************************************************

[jaguar] ERROR: program 112446b3-9c37-933d-895c-0408ccd4026d stopped - exit code 1
f
I don't see anything special about pin 20/21. Is there any other program running on the device that could have opened the pin (and maybe not closed it)?
o
No, that program is the only thing running on it. It has an RGB LED attached to pins 5, 6, and 7, but that is not used atm.
f
Could you triple check with
jag container list
? I looked through the sources, and unless I missed something, this error indicates that something has the pin opened.
Wait.
I see it now.
Found it. It's a bug on our side. We apply the ESP32 pin pool to the ESP32C3, and the ESP32 doesn't have any pin 20: https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/peripherals/gpio.html
Fixing now.
I uploaded a PR and triggered a build for the esp32c3. Here is the updated envelope. https://drive.google.com/file/d/1c9j0bb9Kg5BZFmlQr0PkHswC4emQO4XF/view?usp=sharing You should be able to flash it with
jag flash --chip esp32c3 ./firmware-esp32c3.envelope
. You would need to unzip it first:
gunzip ./firmware-esp32c3.envelope.gz
. (Make sure not to extract the envelope itself. Some tools recognize that it is an AR file and then extract that as well).
o
Thanks, will try that tomorrow!
f
We will hopefully make a release very soon too. Thanks for reporting.
o
No problem, I was just puzzled!
@floitsch it works -- thank you very much for diagnosing/fixing it so quickly!
f
Great! We will release the fix as soon as possible.
6 Views