Skip to content
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

ESP crashes when using UART read() #19

Open
Psirus opened this issue Mar 7, 2023 · 0 comments
Open

ESP crashes when using UART read() #19

Psirus opened this issue Mar 7, 2023 · 0 comments

Comments

@Psirus
Copy link
Contributor

Psirus commented Mar 7, 2023

Disclaimer: I don't know what I'm doing, I have very little experience with electronics and embedded development. Maybe its just a daft beginner mistake.

I'm trying to use the UART module to read in MIDI data. This is the code:

import nesper
import nesper/gpios
import nesper/timers
import nesper/uarts

app_main():
  var uart_config = newUartConfig(baud_rate=31250)
  var uart = newUart(uart_config, UART_NUM_2, GPIO_PIN(14), GPIO_PIN(34), buffer=1024.SzBytes)
  while true:
    delayMillis(100)
    var buff = uart.read()
    if buff.len != 0:
      echo buff

And it works, for a little while. After a couple of seconds (it varies), the ESP either becomes unresponsive or crashes. A backtrace from one of the crashes is here. Thanks for your help.

Edit: I was able to work around this problem by copying the nim code from read() and moving the creation of the buffer outside of the loop. Maybe the temporary buffer isn't garbage collected, or read isn't supposed to be used in a loop like this, or something else I don't quite grasp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant