Unicorn Hat HD: ARM programmability?

I took advantage of the big sale and ordered a Unicorn Hat HD. I really love the LED Shim controller chip’s ability to animate without CPU intervention: it’s a a really fantastic status device! I am wondering if I’ll be able to write code for the ARM chip on the Unicorn Hat HD, or is the code fixed in ROM? Thanks!

From the product page

  • Pixels driven by ARM STM32F and three STP16CPC26 LED drivers

STM32F4 - ARM Cortex-M4 High-Performance MCUs - STMicroelectronics

The above is a bit over my head, skill level wise. Might help you on your quest though.
Keep in mind that the Unicorn HD uses SPI, and the LED shim uses i2c.

I’m hoping to do a little SPI programming: I’ve been learning gpiod (using it with the Blinkt) and the i2c ioctls (talking to the controller on the LED shim); SPI (on another Pimoroni device) seems like a natural next step. The electronics (wiring, soldering) is way over my head, but I enjoy the programming. I collected a bunch of gadgets when I was thinking of making a little C library, but life got in the way. Retired now, I’ve brought them out to play. I couldn’t resist the sale that Pimoroni has going on.

Hopefully, the ARM chip has HW to do the SPI and communicate with the LED drivers, leaving the processor itself a bit idle… But if the code is only in fixed ROM (fused, on die?), then it’s not going to be possible… It’ll still be fun to use - I’m planning to plug it into a new 3A+, where I can probably spare a core to drive some bling.

It could be interesting to know which microcontroller is in use. Is there a schematic for the hat somewhere?

Not sure. it says ARM STM32F, but that brings up 500+ different parts on STM’s website. Cortex M0 did seem to be a common feature, but that’s all the detail I could find. The EEPROM in the product identification I2c bus might hold the code; maybe that’s a route to uploading code? We might need some help from Pimoroni people… I wonder if, on redesign, they would use an RP2040, giving them a growing development ecosystem…

I didn’t see a link to a schematic, but I have seen Pimoroni provide one when asked here on the forum. You can ask and see what they say.
Contact Us for Raspberry Pi Technical Support - Pimoroni

@DanielMGessel
The Galactic and Cosmic Unicorn are PICO W onboard / RP2040 based. ;)

It looks like @hel is the admin who is most active right now. Let’s see if we can find out anything more.
I would expect it’s a STM32F0 microcontroller, but let’s see. :)

I’ve put a request in for the schematic (and some more details on the ARM chip) :)

Unicorn-HAT-HD_schematic.zip (98.9 KB)

Here you go! (sorry about the .zip - the forum wouldn’t let me upload a .pdf)

1 Like

Wow! That’s awesome. The arm chip has got some flash, which is where the code (firmware, I guess) must be; it looks to be connected to the Pi via SPI. I’ll spend some time with the datasheet for it over the next few days - see if I can figure out if there’s a flash read/write over SPI as a starting point.

If this reference manual is relevant, it looks like it might be possible to reflash it via the USART. See the last part of section 2.5.

Excellent: I’ll finally get to looking over the weekend. I suppose the question is if the uart for the STM ARM chip is accessible? Ideally, it would be wired through the GPIO connector to one on the Pi. I hope, given how straightforward it could be, that Pimoroni would have made it easy for customers to upload new code, in case a patch was necessary or enhancements were added, but pinout.xyz shows only spi connections.

You will have to have a look at the schematic. I’m on my XBOX which won’t let me download it, or l’d have a look see myself.

There’s no obvious connection to the standard Pi header uart (BCM pins 14 and 15) but it looks like the spi0 pins (7-11) can be configured as an alternative uart (8-11, TXD and RXD on 8 and 9), but I think only on the Pi4. It would mean that the Unicorn HD’s ARM chip would have to detect whether those pins were operating as UART or SPI, which I haven’t figured out yet.

Via email, I’ve nagged support for some help from an engineer (hopefully I haven’t been too whiny, tho’).

Got the Hat; looks like the CPU blocks on SPI communication (I’ve seen, and am always worried about, spin loops), which is a little different than the blinkt where there’s no file descriptor to wait on. I’ll do some investigation and see where I’m at.

1 Like

Yep - I’ve done some benchmarking; setting up a flipbook in the Pi’s memory and triggering transfers at 60 fps uses almost no user time (a bit of kernel time, but not much). It would be slick to use the ARM in the hat, but, unless there’s another SPI device needs the bus, the benefit to running on the hat would be minimal.

But it would still be slick!

You could also try to run it as a standalone device, assuming it could be powered in a convenient way. Is that also possible, do you think?

A standalone could work, but it has no wifi (unlike the Pico-W displays) so it wouldn’t be useful as a status indicator.

As it stands, I can make a 1000 frame flipbook in the Pi’s memory (768 bytes per frame, plus the one byte for the SOF command, means it would take about 3/4 of a MB - not too bad!) and the CPU overhead of triggering the SPI transfer 60 times a second is pretty minimal. The kind of simple, generic, feature I’d love to add would be a “shift in line” command, taking 16 rgb8 values for a column; the command would shift the display and fill the empty column with the new data; then I’d only need to store (and transfer) 1+16*3 bytes per update that way. That would save a bunch of memory - I could stream a novel to the Hat! :)

1 Like