# Unicorn Hat HD: ARM programmability?

**URL:** https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600
**Category:** Support
**Created:** [March 3, 2023, 6:20am UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600 "2023-03-03T06:20:02Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![DanielMGessel](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@DanielMGessel](https://forums.pimoroni.com/u/DanielMGessel)
#### Post date: [March 3, 2023, 6:20am UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/1 "2023-03-03T06:20:02Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)
#### Post date: [March 3, 2023, 10:14am UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/2 "2023-03-03T10:14:38Z")

</div>

From the product page

- Pixels driven by ARM STM32F and three STP16CPC26 LED drivers

[STM32F4 - ARM Cortex-M4 High-Performance MCUs - STMicroelectronics](https://www.st.com/en/microcontrollers-microprocessors/stm32f4-series.html)

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.

---

<div class="post-metadata">

### Author: ![DanielMGessel](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@DanielMGessel](https://forums.pimoroni.com/u/DanielMGessel)
#### Post date: [March 3, 2023, 2:29pm UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/3 "2023-03-03T14:29:14Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![davidb](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/davidb/32/9036_2.png) [@davidb](https://forums.pimoroni.com/u/davidb)
#### Post date: [March 5, 2023, 4:21pm UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/4 "2023-03-05T16:21:58Z")

</div>

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

---

<div class="post-metadata">

### Author: ![DanielMGessel](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@DanielMGessel](https://forums.pimoroni.com/u/DanielMGessel)
#### Post date: [March 6, 2023, 1:17am UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/5 "2023-03-06T01:17:18Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)
#### Post date: [March 6, 2023, 9:39am UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/6 "2023-03-06T09:39:56Z")

</div>

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](https://shop.pimoroni.com/pages/contact-us)

---

<div class="post-metadata">

### Author: ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)
#### Post date: [March 6, 2023, 9:49am UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/7 "2023-03-06T09:49:06Z")

</div>

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

---

<div class="post-metadata">

### Author: ![davidb](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/davidb/32/9036_2.png) [@davidb](https://forums.pimoroni.com/u/davidb)
#### Post date: [March 6, 2023, 8:53pm UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/8 "2023-03-06T20:53:09Z")

</div>

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. :)

---

<div class="post-metadata">

### Author: ![hel](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/hel/32/6075_2.png) [@hel](https://forums.pimoroni.com/u/hel)
#### Post date: [March 7, 2023, 8:31am UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/9 "2023-03-07T08:31:53Z")

</div>

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

---

<div class="post-metadata">

### Author: ![hel](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/hel/32/6075_2.png) [@hel](https://forums.pimoroni.com/u/hel)
#### Post date: [March 7, 2023, 9:22am UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/10 "2023-03-07T09:22:27Z")

</div>

[Unicorn-HAT-HD\_schematic.zip](https://forums.pimoroni.com/uploads/short-url/6AsJm5IZU4D8Z7j9U35iSRjIx2m.zip) (98.9 KB)

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

---

<div class="post-metadata">

### Author: ![DanielMGessel](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@DanielMGessel](https://forums.pimoroni.com/u/DanielMGessel)
#### Post date: [March 7, 2023, 8:26pm UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/11 "2023-03-07T20:26:05Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![davidb](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/davidb/32/9036_2.png) [@davidb](https://forums.pimoroni.com/u/davidb)
#### Post date: [March 7, 2023, 10:44pm UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/12 "2023-03-07T22:44:25Z")

</div>

If [this reference manual](https://www.st.com/resource/en/reference_manual/rm0360-stm32f030x4x6x8xc-and-stm32f070x6xb-advanced-armbased-32bit-mcus-stmicroelectronics.pdf) is relevant, it looks like it might be possible to reflash it via the USART. See the last part of section 2.5.

---

<div class="post-metadata">

### Author: ![DanielMGessel](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@DanielMGessel](https://forums.pimoroni.com/u/DanielMGessel)
#### Post date: [March 9, 2023, 8:58pm UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/13 "2023-03-09T20:58:55Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)
#### Post date: [March 9, 2023, 9:23pm UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/14 "2023-03-09T21:23:11Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![DanielMGessel](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@DanielMGessel](https://forums.pimoroni.com/u/DanielMGessel)
#### Post date: [March 12, 2023, 10:45pm UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/15 "2023-03-12T22:45:53Z")

</div>

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’).

---

<div class="post-metadata">

### Author: ![DanielMGessel](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@DanielMGessel](https://forums.pimoroni.com/u/DanielMGessel)
#### Post date: [March 17, 2023, 7:13am UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/16 "2023-03-17T07:13:51Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![DanielMGessel](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@DanielMGessel](https://forums.pimoroni.com/u/DanielMGessel)
#### Post date: [March 18, 2023, 10:36pm UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/17 "2023-03-18T22:36:52Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![davidb](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/davidb/32/9036_2.png) [@davidb](https://forums.pimoroni.com/u/davidb)
#### Post date: [March 18, 2023, 11:22pm UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/18 "2023-03-18T23:22:05Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![DanielMGessel](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@DanielMGessel](https://forums.pimoroni.com/u/DanielMGessel)
#### Post date: [March 19, 2023, 2:56pm UTC](https://forums.pimoroni.com/t/unicorn-hat-hd-arm-programmability/21600/19 "2023-03-19T14:56:31Z")

</div>

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! :)
