Live-coding an Open-Source Pico Emulator from Scratch
To make the experience fit your profile, pick a username and tell us what interests you.
The RP2040 datasheet, where we'll find all the specific details about the MCU core and peripherals.
Adobe Portable Document Format - 29.77 MB - 01/25/2021 at 18:44
ARM® v6-M Architecture Reference Manual. It'll be our main reference for implementing the emulator!
Adobe Portable Document Format - 2.16 MB - 01/25/2021 at 18:37
Pico Getting Started guide. Check out Chapter 2 for setting up the build environment. We'll use it extensively while working on the emulator.
Adobe Portable Document Format - 36.28 MB - 01/25/2021 at 18:36
Last week, we spent some time exploring the Pi Pico's bootrom and stage-2 bootloader. We explored __vector_entry, found some nice ASCII art buried deep in the Pico's SDK, and also implemented BL, LSRS and LDMIA:
The next live-streamwill take place tomorrow, 7pm GMT (11am PST, 2pm EST, 8pm CET).
If you wish, add it to your Google calendar.
Last week, we spent some time exploring the Pi Pico's bootrom and stage-2 bootloader. We explored
__vector_entry, found some nice ASCII art buried deep in the Pico's SDK, and also implemented BL, LSRS and LDMIA:
The next live-stream will take place tomorrow, 7pm GMT (11am PST, 2pm EST, 8pm CET).
If you wish, add it to your Google calendar.
This week's coding session ended with a glorious victory: UART works! 🎉
You can watch the exciting moment at 1:43:15.
Or, you can watch all the work that led into it: implementing ADDS, SUBS, NEGS, LDRB, ADCS, and UXTB.
We also spent some time tidying-up the code, came up with our own mini-assembler for the unit-tests, implemented memory write hooks and and split the code into smaller modules (e.g. UART).
To conclude the party, we started looking at the Raspberry Pi Pico's bootrom which I'll try to run inside the emulator in the next episode. 🤞
In the second episode of the RP2040 Emulator coding live-stream we had an ambitious goal: implement UART so we can see debug prints from the simulated program.
We loaded the hello_uart example program, looked at the disassembly, and started implementing the instructions in a TDD (test-driven development) manner, similar to the first live-stream:
We also took care of implementing CPU Read Hooks, which allow peripherals to intercept memory reads from their mapped regions. This allowed us to mimic the behavior of the UARTFR, indicating to the simulated code that the UART hardware is ready to receive the next character.
You can watch the complete episode here:
And check out the project's code on GitHub: https://github.com/wokwi/rp2040js
If you don't want to miss out the next episode, make sure to sign up and get a reminder when it goes live!
Meanwhile, some random programmer who watched the stream started working on a RP2040 disassembler in Python: https://github.com/pyTony/rp2040
Nice work Tony! Thank you for sharing it with us :-)
Hacking the Pico simulator on a live stream was a bit intense, but also a lot of fun!
So I decided to try turning it into a weekly thing. The next stream will be on Tuesday, 2PM EST (just like the last time):
I'll keep posting the updates here, but if you prefer to get them in your email, you can sign-up here:
See you on Tuesday!
In the first live stream we implemented 6 instructions: B, BL, LSLS, MOVS, PUSH, STR - just the bare minimum to run the main loop of the blink example.
Eventually, we got it running in the simulation, and also wrote unit tests for most of these instructions.
You can find the code in the project's repo: https://github.com/wokwi/rp2040js
Now, it's your turn: I'd love to get your feedback about the format, and learn if you want me to do more live-streaming sessions showing how I gradually evolve this project into a usable, general-purpose Raspberry Pi Pico emulator.
After digging a bit into the RP2040 datasheet, it seems like we might also need to take a look at the bootrom. Fortunately, the full source code is available on GitHub.
There's no documentation how to build it, but it turns out it's pretty straightforward. Here are the complete instructions for building the RP2040 bootrom from source:
sudo apt install cmake gcc-arm-none-eabi
Checkout the repository:
git clone https://github.com/raspberrypi/pico-bootrom
cd pico-bootrom git submodule update --init mkdir build cd build cmake .. make -j4
For the first live-stream tomorrow, we'll use the following documents:
You can find a copy of all the three documents in the Files section of the project page.
To save time, I have already set them up on my machine, so we can get straight to planning/coding (without having to wait for the 1.2GB gcc-arm-none-eabi package to download).
See you tomorrow!
Become a member to follow this project and never miss any updates