ARM assembler (and compiler) maybe not working on Teensy 4.1?


#1

I tried to run the ARM assembler and the compiler on a Teensy 4.1. Using the assembler seems to result in a system crash and reset, even the simple “mult13” example. I used the unmodified uLisp 4.8f on an unmodified brand-new Teensy 4.1 (no PSRAM or other additions).
Using the very same assembler/compiler files on a WIO Terminal, also with uLisp ARM 4.8f, worked as expected.
Did I miss something? Maybe I have to give special instructions before invoking the assembler on a Teensy 4.1?
Thanks for your help!


#2

I’m pretty sure I ran the assembler successfully on the Teensy 4.1 when I first ported uLisp to it, and it worked without doing anything special.

I can’t think of anything in the latest release of uLisp that has changed in that area, but I’ll try it myself and let you know.

Which version of the Teensy 4.1 Arduino Core are you using? And what IDE are you running it on?


#3

Thanks for looking into it! The Teensy board files used are version 1.59, “teensy-compile” uses version 11.3.1.
They are invoked from Arduino IDE 2.3.6.


#4

Last time I uploaded uLisp to the Teensy 4.1 I used Teensyduino, Paul Stoffregen’s version of the Arduino IDE based on the Arduino IDE 1.8.19 and customised for his boards.

The way I got the assembler to work on Teensy 4.1 was to define the MyCode[] array, where the machine code is stored, with the FASTRUN directive. This allowed code to be executed in that memory. One possible explanation for the behaviour you’re seeing is that the effect of FASTRUN has changed in more recent versions of the compiler.


#5

Thanks for your hints! I tried several variations of marking MyCode and/or the assembler functions for RAM sections, but with no effect. When I omit FASTRUN (thus keeping RAMFUNC the way it’s used for other boards) or use DMAMEM instead, the assembler itself does work (thus writing code bytes to the array), but the Teensy crashes as soon as I try to invoke the assembler function.
I’ve no clue where to place the MyCode array on the Teensy to be able to access it both at assembly and at call time - so I posted the question on the PJRC forum. I’ll report back as soon as there are news.


#6

The answer came incredibly quick from user jmarsh at the pjrc forum and does work!

One has to edit two lines in “startup.c” from the Teensyduino core. You can find it at
arduino15/packages/teensy/hardware/avr/1.59.0/cores/teensy4

In there, change the following line (currently no. 294) from
SCB_MPU_RASR = MEM_NOCACHE | READONLY | SIZE_512K;
to
SCB_MPU_RASR = MEM_NOCACHE | READWRITE | SIZE_512K;

and the following line (currently 305) from
SCB_MPU_RASR = MEM_NOCACHE | READWRITE | NOEXEC | SIZE_512K;
to
SCB_MPU_RASR = MEM_NOCACHE | READWRITE | SIZE_512K;

That’s it! (The Teensy-specific feature that writes MyCode to the FASTRUN section remains unchanged in ulisp-arm.ino.)


#7

Thank you for tracking down the solution to this problem! I’ll add your information to the uLisp Teensy 4.0 and 4.1 page.


#8

Out of interest I just checked startup.c in the version of Teensyduino I used to run the uLisp assembler on my Teensy 4.0/4.1 boards, and it has for those two lines:

SCB_MPU_RASR = MEM_NOCACHE | READWRITE | SIZE_512K;
...
SCB_MPU_RASR = MEM_NOCACHE | READWRITE | NOEXEC | SIZE_512K;

So this confirms my theory that there has been a change in the configuration since the version I used. Also, possibly the second change isn’t strictly necessary.