ESP32 crash when using the nothing symbol


#1

For an I2C scanner I wanted to realize the output of the addresses as hexadecimal values. For this I oriented myself on David’s examples and wrote this solution:

(defun pc (i) (princ (code-char (+ i (if (<= i 9) 48 55)))))

(defun pb (i) 
  (pc (ash i -4)) 
  (pc (logand i 15))
)


(defun scn () 
  (dotimes (p 127)
    (with-i2c (str p)
      (if (not str) (princ ". ") 
          (progn (princ "0x") (princ (pb p)))
))))

The output looks like this:

7900> (scn)
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . 0x388 . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . .
nil

Although address 56 (decimal) is correctly converted to 0x38, an additional 8 is appended. This comes from the return value of the function.
In the reference I found the symbol “nothing”, which I wanted to use to prevent the additional output:

(defun pb (i) 
  (pc (ash i -4)) 
  (pc (logand i 15))
  (nothing)
)

The result is a ESP core crash:

7897> (scn)
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . 0x38
Error: 'Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:

Any idea what could be causing ESP to crash here? Is it the right strategy to use the noting symbol here?


#2

Hi,

nothing is a symbol, not a function. So you should not execute it (put inside parenthesis). This should work:

(defun pb (i) 
  (pc (ash i -4)) 
  (pc (logand i 15))
  nothing)

Oh, and definatelly yes, it is the right strategy to use nothing symbol here. Suppressing return value is the main reason it exists :)


#3

Again the solution was so simple. Now it works as I wanted it to.
Thanks a lot for the explanation. Very helpful!


#4

@rsm is correct, but nevertheless, calling (nothing) as a function should give a uLisp error, not a crash. I’ll log that as a bug.


#5

My Adafruit Grand Central M4 gives me this:

30640> (nothing)
Error: '��' can't be used as a function
30640> 

The question marks are 27 E0, hex, in ‘gtkterm’ on Linux.
Maybe that’s the source of the cras… er, hiccup. :)


#6