Page 1 of 1

Using Large arrays

Posted: Mon Jan 14, 2013 12:12 am
by kreyl
I am using stm32f205RB MCU. I want to write a driver for LCD Nokia2630.
I need to have a large amount of data in MCU's memory, somewhat about 20kB. This is just an array of uint8_t.
But even with much smaller array I cannot figure out what is happening.

Code: Select all

bool Changed[AREA_H_CNT][AREA_W_CNT];

static WORKING_AREA(waLcdThread, 256);

static msg_t LcdThread(void *arg) {
    (void)arg;
    chRegSetThreadName("Lcd");
    while(1) {
        for(uint8_t xc=0; xc<AREA_W_CNT; xc++) {
            for(uint8_t yc=0; yc<AREA_H_CNT; yc++) {
                if(Changed[yc][xc]) {
                    Changed[yc][xc] = false;
                    uint8_t x = xc * AREA_H, y = yc * AREA_W;
                    Uart.Printf("%u; %u;   %u; %u\r", xc, yc, x, y);
                    chThdSleepMilliseconds(99);
                } // if changed
            } // xc
        } // yc
    } // while 1
    return 0;
}

At initialization (not shown here) all array members are set to true.
The thread just iterates the array, and, when true is found, changes it to false and prints indexes.
Since nobody else sets values back to true, I should see all indexes printed once. And I really do - when AREA_H_CNT and AREA_W_CNT are 3 and 15, respectively. But when I increase the values, it seems that several array members are not changing. Therefore I have their indexes printed eternally.
Definitely this relates to memory allocation, but I do not understand why. Changed[][] is outside the thread, and I want it remain there - since in nearest future I will need mentioned 20kB array. I do not want OS switching such a context :)
What am I missing?
Thank you in advance.

Re: Using Large arrays

Posted: Mon Jan 14, 2013 8:55 am
by Tectu
Might I ask why you need such an amount of RAM to drive your LCD? Do you want to create an internal framebuffer?

Also, do you know that there's already a graphic display library for ChibiOS/RT out there where you only need to write and insert your driver? There's already some nokia driver you could simply copy and edit.


~ Tectu

Re: Using Large arrays

Posted: Mon Jan 14, 2013 11:41 pm
by skute
You don't have the values of AREA_H_CNT and AREA_W_CNT posted. Is it possible that these are larger than 255 such that you are overflowing the uint8_t sized index variables (xc, yc) in your for loops? The same question applies to the uint8_t sized variables x, y.

Re: Using Large arrays

Posted: Sat Jan 19, 2013 5:41 pm
by kreyl
Tectu:
Yes, I noticed the library and maybe soon will use it, thank you. Yes, this is large framebuffer; the point is to speed-up writing by dividing writing to buffer (fast) and outputting buffer to LCD. LCD requires no less than 12 bit per pixel, and I am using UART with DMA to send them, and still want to make CPU clk as low as possible to save energy - and so on.
Maybe, eventually I decide to get rid of buffer, though.

scute:
Those values are small enough, since LCD is 160x128 pixels.

All:
Thank you very much for your attention, I found problem in Printf function: there was a large array inside, which was not static and therefore I had thread stack overflow.

Re: Using Large arrays

Posted: Sat Jan 19, 2013 9:43 pm
by Tectu
Since your LCD seems to be connected over UART, it must have an LCD controller, right? Therefore, I am pretty sure it has a function to set the current pointer. Therefore you don't need a frame buffer to be able to only refresh sections of a display at a time. Simply just do that.
Most LCD controllers do also have windowing function. This allows you stream a constant pixel stream into a given area, instead of all across the display. It looks like this could be what you need. But maybe I'm just getting your wrong


~ Tectu