chipKIT® Development Platform

Inspired by Arduino™

does PROGMEM works succesful on CHIPKIT?

Created Wed, 29 Feb 2012 20:40:17 +0000 by acmilangr


Wed, 29 Feb 2012 20:40:17 +0000

hi i am working o led panels displays using UNO32 chip (PIC32MX320F128).

becouse i will need more SRAM i would like to know if PROGMEM fuction works 100%


Wed, 29 Feb 2012 23:20:21 +0000

Included in "wiring.h"

#if !defined(__AVR__)
    #define _BV(bit) (1ul << (bit))

    #define PROGMEM
    #define pgm_read_byte(x)        (*((char *)x))
//  #define pgm_read_word(x)        (*((short *)(x & 0xfffffffe)))
    #define pgm_read_word(x)        ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x)))
    #define pgm_read_byte_near(x)   (*((char *)x))
    #define pgm_read_byte_far(x)    (*((char *)x))
//  #define pgm_read_word_near(x)   (*((short *)(x & 0xfffffffe))
//  #define pgm_read_word_far(x)    (*((short *)(x & 0xfffffffe)))
    #define pgm_read_word_near(x)   ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x)))
    #define pgm_read_word_far(x)    ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x))))

    #define strcpy_P                strcpy
    #define strcat_P                strcat

    #define prog_void               const void
    #define prog_char               const char
    #define prog_uchar              const unsigned char
    #define prog_int8_t             const int8_t
    #define prog_uint8_t            const uint8_t
    #define prog_int16_t            const int16_t
    #define prog_uint16_t           const uint16_t
    #define prog_int32_t            const int32_t
    #define prog_uint32_t           const uint32_t
    #define prog_int64_t            const int64_t
    #define prog_uint64_t           const uint64_t

Why s word wrap on in a code block?


Thu, 01 Mar 2012 08:58:56 +0000

someone told me that const works as well. is this true?


Thu, 01 Mar 2012 17:57:12 +0000

I saw the answer you got on the Arduino support forums yesterday. What Nick said is correct. That's what I was trying to show you above.

There are MACRO's in place that transform the code at compile time.


Sat, 03 Mar 2012 20:11:57 +0000

#define _6x8_gr_big_A { B00111111,B01000100,B01000100,B01000100,B00111111,B00000000 } #define _6x8_gr_big_B { B01111111,B01001001,B01001001,B01001001,B00111110,B00000000 }

const byte index_small[2][6]={_6x8_gr_big_A,_6x8_gr_big_B};

on this code i am comfused with memory it starts with define and there is an index array that holds all there,

where that bytes are stored?


Sat, 03 Mar 2012 23:14:13 +0000

[color=#FF0000]const[/color] byte index_small[2][6]={ Would place it somewhere in the 128K Flash memory.


Mon, 05 Mar 2012 08:50:51 +0000

Note that

char foo PROGMEM[] ="abcdefg";

will generate flash data in current Arduino programs, but not in ChipKit programs (because it doesn't have "const.") That's because of an avr-gcc compiler error; with newer versions of avr-gcc, this will generate error messages like:

optiLoader.cpp:688:17: error: variable 'image_328' must be const in order to be put into read-only section by means of 'attribute((progmem))'