Pico Adventures, Part 1
Recently I’ve taken to embedded programming, and have been spending some of my free time playing around with a Pi Pico2W. I’ve fallen in love with the little thing, and have had so much fun leaning how it works. Below is the story of my attempt at a bare metal blink (spoilers: I was unsuccessful).
A misguided Attempt at Bare Metal
As the Pico was being shipped to me, I read a particularly persuasive comment on Reddit - about how the Arduino isn’t real programming and blah blah blah. I became a little self conscious, and decided that I should instead only work with bare metal. Oh boy. What a mistake :D
As is custom, my first project was to blink the onboard LED. I thought my best approach would be to reverse engineer the pico-sdk, so I spent a good week trying to understand how the pico-sdk initializes and writes a bit to a GPIO pin.
You can see my notes here.
ChatGPT was incredibly helpful here. My C skills were a little rusty, so being able to ask it to explain any macro I didn’t understand was incredible! Of course, it still hallucinated some, but it was close enough for me to fill in the gaps. After figuring out that the sdk was calling some assembly for most cases, I studied the ARM lanugage manual and felt I had a good enough grasp to attempt a bare metal blink.
I wrote some code, and asked ChatGPT what it thought. It decided that my code would work, because I needed a CMake file, and memory map! After some time I had come to understand both of these things, making more great use of the examples in the pico-sdk. But even with all these things successfully compiling, it would not work!
I realized that I had spent the whole time barking up the wrong tree. The onboard LED on the Pico 2W is controlled by the Wi-Fi chip! Meaning everything I had learned was not applicable at all. A huge blow to my ego, but I had learned so much at this point, so it wasn’t a total loss. I decided to take my knowledge, cut my losses and use the pico-sdk to interface with a magnetometer I had bought, the QMC5883L.