RP2040_Creating a New UF2

Where I describe how to edit, assemble, link, and UF2 Mecrisp-Stellaris for the RP2040 and specifically, the Adafruit Feather RP2040.

Sources

Updated

Now that I have gone through over 20 assemble/link/UF2 cycles, I have a better understanding of what needs to be done, specific to macOS Big Sur.

  1. Follow the comments as to “The process…” particularly as it regards getting macOS to run the ARM toolchain. This has to happen first.
  2. Reduce the complexity of Mecrisp-Stellaris. Matthias has performed a remarkable job in getting so many processors to run this version of Forth. This achievement needs to be applauded and appreciated. That said, unless you are running a significant number of versions, delete those that you aren’t using. In my case, I used the 128k/128K version to determine what was required for the RP2040. This is my base moving forward.
  3. Terry’s directions below (Understatement), however, its even easier. If you have performed point 2, then the solution is simply:
cd mecrisp-stellaris-x.x.x
./release
# put board in USB mode, drag/drop UF2 file and go to work

Really important things to do: (Instructions below)

  1. Implement Terry’s improvement on Stair-Stepping by adding a CR to the OK prompt.
  2. Implement Piotr’s improvement on uploading

Understatement

(With apologies to Terry Porter) Terry’s page above as Mecrisp Patching was extremely helpful and contained this nugget. Which is true, however, it takes a little bit of additional work to get there with the RP2040.

  • cd mecrisp-stellaris-x.x.x/mecrisp-stellaris-source
  • ./assemble
  • ./tidyup
  • The new image is now available in mecrisp-stellaris-x.x.x/your-mcu/mecrisp-stellaris-your-mcu.bin (except Linux)

Let the journey begin…

The process (and pitfalls) on macOS Big Sur

In order to assemble the ARM code, one must have the GCC ARM toolchain. As I have I have macOS, I chose to install it using homebrew as in

brew install gcc-arm-embedded

I then attempted to ./assemble and was faced with an incredible number of “macOS malware messages”. Long story, short:

# find the offending ARM applications, for example... 
which arm-none-eabi-ld
/opt/homebrew/bin//arm-none-eabi-ld
# using Finder Shift-CMD-G /opt/homebrew/bin/
# right-click on the offending app, select Open and answer the question "macOS cannot verify the developer of “arm-none-eabi-gcc”. Are you sure you want to open it?"  click on Open.
# You will need to do this several times, I didn't capture the specific ones I required
# I suggest you run to confirm each command works, replacing the app below with the one in question
arm-none-eabi-ld --help
# if it displays help contents for the app named, you are good to go

(One more helpful hint, would be to remove all but one of the processor-specific assemble instructions in ./assemble and run it. See #2 in Updated above.)

Another app which isn’t on macOS is md5sum. And if md5sum doesn’t run, then you have problems. I replaced md5sum with md5 in the ./assemble program and I believe it works. The MD5sum issue was for processors other than the RP2040. Do this only if you notice you are having an issue with MD5sum, not being found.

Now you have the right .bin files, now you need the .uf2 file to perform the simple drag-drop operation of loading Forth on your board.

In this case, the RP2040 has a second program to run called release and it is in:

mecrisp-stellaris-2.5.9a/rp2040-ra/

Run release and it will create the required UF2 file.

A note regarding command-line

  • I use Sublime Text (ST3) as my editor and when I’m on the command-line, “st” invokes the ST3.
  • I’m using macOS Big Sur and use applications installed by Homebrew. If your system is different, your commands may differ.

Important Note!

If you had added via .init the ability to automatically add a CR to every OK (to fix stair-stepping), you must delete it if you are going to use the above method of adding via the compiled code AND the below method of checking for “ok.\r\n”. For if you do both, you will end up with “OK.\r\r\n” which will cause a compilation error!

An Example - Fix Stairstepping

Using Terry’s suggestion let’s fix the problem and attempt to create a new uf2 image.

1. Edit the file mecrisp-stellaris-source/common/datastackandmacros.s and change:

st mecrisp-stellaris-source/common/datastackandmacros.s 
# Option-CMD-f (Find/Replace)
\Meldung\n
\Meldung\r\n
# 5 lines are changed

2. One step command to assemble/link/UF2 code, very, very nice!

cd mecrisp-stellaris-x.x.x/
./release

3. Download uf2 file to board and test.

It worked!!!

Example - Speed Up Serial Port in Python

Source: Piotr Wiszowaty Note

“I’ve written the following little script to send programs. The script waits for an “ok.” before sending consecutive lines so the transmission is somewhat faster than when using a fixed delay per line."

Uses: picocom -b 115200 /dev/ttyACM0 –imap lfcrlf,crcrlf –omap delbs,crlf –send-cmd “./xfr.py”

#!/usr/bin/env python3
import sys
for l in open(sys.argv[1], "rt"):
    sys.stdout.write(l)
    r = sys.stdin.readline()
    sys.stderr.write(r)
    if not r.endswith("ok.\n"):
        sys.exit(1)
st

The above version works extremely well and could be a finished product. Great job, Piotr! However, Piotr continued to work on it and released this version.

I did make the change above which changed the response from “ok.\n” to “ok.\r\n”, this needs to be changed in xfr as well (line 69) as in:

if not response.endswith("ok.\r\n"):

Not working: Enable Color Output

Color Terminal Error Messages

For the color switch, add “ .equ color,1 “ to your .s file in the mecrisp-stellaris-source/your-cpu directory as below and rebuild your kernel.

@ ————————————————————————
@ Switches for capabilities of this chip
@ ————————————————————————
.equ color,1
cd mecrisp-stellaris-source/rp2040-ra
st mecrisp-stellaris-pico-core.s
# Add line under @ Switches for...
.equ color, 1
# close file
cd ../..

Comments powered by Talkyard.