RGBMatrix library porting to STM32

Working libraries, libraries being ported and related hardware
Post Reply
castortiu
Posts: 39
Joined: Tue Nov 07, 2017 8:34 am
Location: Seattle, WA

RGBMatrix library porting to STM32

Post by castortiu » Tue Nov 07, 2017 9:36 am

Hi,

Couple weeks started to play with ATmega32 to use the RGBMatrix library from here https://github.com/adafruit/RGB-matrix- ... xPanel.cpp only to find out the AVR fall very short on speed and memory to make this puppy work at the specs I want.

Basically from a ATmega32 I can't get a matrix more than 32x32 however I'm trying to achieve 128x32 at least 200Hz with double buffering.

The library for ATmega is heavily optimized and there was nothing to do there so I moved to the STM32, first time with this chip was a week ago after trying to find an AVR replacement and then found all the amazing work Roger has been doing on the STM32

So far I ported the RGBMatrix library and made it work at 128x32x3 (RGB) at 205Hz, however so far single buffer since each memory screen buffer takes 12K, currently the memory format is RGB(8,8,8) later I'll be working on different pixel format to allow RGB(5,6,5) or RGB(2,3,2) to reduce memory and reach double buffer as well.

My current problem is that there is heavy clock cycle loop where I need to send the info to the display over 12 wires (A,B,C,D,R1,R2,G1,G2,B1,B2, LATCH, CLK), to control the brittleness it uses BCM instead PWM, the critical loop send 128 clock cycles, the fastest way I found out to cycle the clock is using
#define TICK GPIOB->regs->BSRR = 1;
#define TOCK GPIOB->regs->BRR = 1;

Looking at the oscilloscope I can't get more than 12Mhz, currently TICK and TOCK takes 41.67ns plus another *ptr++ another 41.67 so the total of the cycle is at minimum 125ns.

The CPU is 72Mhz, is there a way to get faster speed from the GPIO?

I can't get more than 12Mhz even when the GPIO is set to mode 0b10 that is supposed to be 50Mhz.

Thanks,
Cas

stevestrong
Posts: 1838
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: RGBMatrix library porting to STM32

Post by stevestrong » Tue Nov 07, 2017 9:56 am

I think you'd be better served with using DMA to output a prepared data buffer to the BSRR register.
The data in the buffer must toggle all control bits and have all data bits.
The condition is to have all output bits on the same GPIO B port.
This way the controller must only do the image processing, e.g. transcript image data to output buffer data.
The data output to the matrix would run continuously in the background.

castortiu
Posts: 39
Joined: Tue Nov 07, 2017 8:34 am
Location: Seattle, WA

Re: RGBMatrix library porting to STM32

Post by castortiu » Tue Nov 07, 2017 10:37 am

Never played with DMA however sounds interesting, from my basic understanding from DMA it would needs to lock the memory, so working with a very basic and optimized buffer it would need

128 x 2 (tick/tock clock for columns) * 4 planes (brightness) * 12 Port pin used + 4 Not connected (whole port used) * 32 rows = 524Kb per frame, that means I would need about 64KB as DMA buffer to hold a single frame?

What is wrong with my numbers?

PS: Did you mean the ODR register?

stevestrong
Posts: 1838
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: RGBMatrix library porting to STM32

Post by stevestrong » Tue Nov 07, 2017 12:51 pm

For the Adafruit 32x32 matrix you need 13 digital pins (6 bit data, 7 bit control). total of 13 pins = 1 word. all fit to GPIO B.
6 bit data means you have 2 pixels stored in one word and transmitted in one shot.
Hence the required memory is
128x2(rising /falling clock)/2(2 pixels per data)*32(rows)*2(uint16_t)= 8kB.

in which way is your matrix different to this one?

EDIT
Ok, I see now, I misunderstood the pixels distribution, is still not clear what the 6bit pixel data actually is...

castortiu
Posts: 39
Joined: Tue Nov 07, 2017 8:34 am
Location: Seattle, WA

Re: RGBMatrix library porting to STM32

Post by castortiu » Tue Nov 07, 2017 1:09 pm

I'm not sure from the /2 came.

Yep, 1 word will fit all, however to control the 16 levels of brightness via BCM the 128 columns needs to be sent 4 times per frame.

128x2(rising/falling clock) * 4 (planes for brightness) * 2 (bytes per 13 lines output) * 32 (rows) = 64KB

Adafruit is the same, in your formula isn't missing the 4 planes to control the brightness?

EDIT: What about using an external flash? is possible to use DMA to send the data for the new frame to external memory and DMA again to send it directly from external memory to the display?

Also I'm looking at a STM32F407VET6, seems is supported by stm32duino and has 192KB, or is it too much?

https://www.ebay.com/itm/STM32F407VET6- ... 2749.l2649
Last edited by castortiu on Tue Nov 07, 2017 1:17 pm, edited 1 time in total.

stevestrong
Posts: 1838
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: RGBMatrix library porting to STM32

Post by stevestrong » Tue Nov 07, 2017 1:14 pm

Is each pixel coded in r,g,b + y(luminosity)?
If yes, then my 8kB should be x4, thus 32kB.
This will not fit in F103C8 RAM, which is 20kB large.

castortiu
Posts: 39
Joined: Tue Nov 07, 2017 8:34 am
Location: Seattle, WA

Re: RGBMatrix library porting to STM32

Post by castortiu » Tue Nov 07, 2017 1:22 pm

You right, it is 32KB, I was counting 32 rows when really is * 16 rows since every output controls 2 pairs of RGB (1 to 16) and (17 to 32) in a single shot, so even at 32KB still is too much, can external flash be used in some way?

stevestrong
Posts: 1838
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: RGBMatrix library porting to STM32

Post by stevestrong » Tue Nov 07, 2017 1:29 pm

I think you would need external RAM, and this in parallel version.

After looking to your requirements again it seems to me that an F4 board would rather fit to your application.
A generic (black) F407VET board is ~10USD, operating CPU with 168MHz clock and has (128 + 64) kB internal RAM.

EDIT
cross-posted, yes that board would fit.

Post Reply