Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

How To: declare an array of pointers in flash pointing to character arrays in flash

How To: declare an array of pointers in flash pointing to character arrays in flash

2006-03-07 by Chuck Hackett

I'm attempting to convert the AVR Butterfly demo program to WinAVR from Atmel's
CodeVision version.  The program currently contains something like:

__flash char foo_1[] =   { 0, 1 };
__flash char foo_2[] =   { 2, 3 };

__flash char __flash *foobar[] = { foo_1, foo_2 };


I'm trying to create the gcc equivalent.  Studying avr-libc documentation: a
start is:

#include <avr/pgmspace.h>

prog_char foo_1[] =   { 0, 1 };
prog_char foo_2[] =   { 2, 3 };

<the puzzle> foobar[] = { foo_1, foo_2 };

But I haven't figured out <the puzzle>


While I'm at it:  Is there a good web resource for (finally) learning about the
details of more complex array and pointer declarations (arrays of pointers to
functions, arrays of pointers to arrays of yada, yada ....).  I have never
gotten this stuff "clear" in my head so that I can deal with these things
without researching it. ... the bulb has just never come on full brightness on
this subject :-) 

Thanks in advance for your help ...

Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

Re: [AVR-Chat] How To: declare an array of pointers in flash pointing to character arrays in flash

2006-03-07 by Mike Perks

Chuck Hackett wrote:

> I'm attempting to convert the AVR Butterfly demo program to WinAVR 
> from Atmel's
> CodeVision version.  The program currently contains something like:
>
> __flash char foo_1[] =   { 0, 1 };
> __flash char foo_2[] =   { 2, 3 };
>
> __flash char __flash *foobar[] = { foo_1, foo_2 };
>
>
> I'm trying to create the gcc equivalent.  Studying avr-libc 
> documentation: a
> start is:
>
> #include <avr/pgmspace.h>
>
> prog_char foo_1[] =   { 0, 1 };
> prog_char foo_2[] =   { 2, 3 };
>
> <the puzzle> foobar[] = { foo_1, foo_2 };
>
I cut and pasted some working code and changed the names. It should work 
for you.

#include <avr/pgmspace.h>

static const prog_uint8_t foo_1[] = {0, 1 };
static const prog_uint8_t foo_2[] = {2, 3 };                          
                 
const prog_uint8_t *foobar[] PROGMEM = { foo_1, foo_2 };

PGM_P pArrayPointer;
uint16_t index;

index = 1;
pArrayPointer = (PGM_P)&(foobar[index]);
this_byte = pgm_read_byte(pArrayPointer)/2; 

Mike
http://home.austin.rr.com/perks/micros/

RE: [AVR-Chat] How To: declare an array of pointers in flash pointing to character arrays in flash

2006-03-08 by Chuck Hackett

> From: Mike Perks
> 
> Chuck Hackett wrote:
> 
> > I'm attempting to convert the AVR Butterfly demo program to WinAVR
> > from Atmel's
> > CodeVision version.  The program currently contains something like:
> >
> > __flash char foo_1[] =   { 0, 1 };
> > __flash char foo_2[] =   { 2, 3 };
> >
> > __flash char __flash *foobar[] = { foo_1, foo_2 };
> > ....
>
> I cut and pasted some working code and changed the names. It should work
> for you.
> 
> #include <avr/pgmspace.h>
> 
> static const prog_uint8_t foo_1[] = {0, 1 };
> static const prog_uint8_t foo_2[] = {2, 3 };
> 
> const prog_uint8_t *foobar[] PROGMEM = { foo_1, foo_2 };
> ....

Thanks Mike.  This, along with dozens of other changes and at least I have a
clean compile now.

I'm off to try loading the Butterfly now.

Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

RE: [AVR-Chat] How To: declare an array of pointers in flash pointing to character arrays in flash

2006-03-08 by kelvin kooger

Hi,
Has anyone converted the AVR butterfly demo program using BASCOM ?

Chuck Hackett wrote:
Show quoted textHide quoted text
> From: Mike Perks
>
> Chuck Hackett wrote:
>
> > I'm attempting to convert the AVR Butterfly demo program to WinAVR
> > from Atmel's
> > CodeVision version. The program currently contains something like:
> >
> > __flash char foo_1[] = { 0, 1 };
> > __flash char foo_2[] = { 2, 3 };
> >
> > __flash char __flash *foobar[] = { foo_1, foo_2 };
> > ....
>
> I cut and pasted some working code and changed the names. It should work
> for you.
>
> #include
>
> static const prog_uint8_t foo_1[] = {0, 1 };
> static const prog_uint8_t foo_2[] = {2, 3 };
>
> const prog_uint8_t *foobar[] PROGMEM = { foo_1, foo_2 };
> ....

Thanks Mike. This, along with dozens of other changes and at least I have a
clean compile now.

I'm off to try loading the Butterfly now.

Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck



Relax. Yahoo! Mail virus scanning helps detect nasty viruses!

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.