EmbeddedRelated.com
Forums

Reading a Flash byte

Started by mrobins99 November 1, 2007
I want to use a pointer to read the flash.
I have
x = * (unsigned long*)0xFFFE;
txout(x);
which works okay!

How can I use a pointer and increment it?

Beginning Microcontrollers with the MSP430

--- In m..., "mrobins99" wrote:
>
> I want to use a pointer to read the flash.
> I have
> x = * (unsigned long*)0xFFFE;
> txout(x);
> which works okay!
>
> How can I use a pointer and increment it?
>

I try this: not working!!!
Error[Pe513]: a value of type "unsigned long" cannot be assigned to
an entity of type "unsigned long *" C:\Michael
Robins\Work\END\Testing\Sample_Code\IAR\Bootloader\main.c 73

unsigned long *p;
unsigned char x;

p = (unsigned long)(0x0000FFFE);
x = * (unsigned long*)p;
txout(x);
--- In m..., "htrada2" wrote:
>
> Hi,
> it doesnt work because you ar casting to an (unsigned long).
> besides, why are you using an unsigned long pointer and then asign
> the value it points to an unsigned char??.
> I think you should have:
>
> unsigned char *p;
> unsigned char x;
>
> p = (unsigned char*)(0xFFFE);
> x = *p;
> txout(x);
> and then you could increment p.
>
> --- In m..., "mrobins99" wrote:
> >
> > --- In m..., "mrobins99" wrote:
> > >
> > > I want to use a pointer to read the flash.
> > >
> > >
> > > I have
> > > x = * (unsigned long*)0xFFFE;
> > > txout(x);
> > > which works okay!
> > >
> > > How can I use a pointer and increment it?
> > >
> >
> > I try this: not working!!!
> > Error[Pe513]: a value of type "unsigned long" cannot be assigned
to
> > an entity of type "unsigned long *" C:\Michael
> > Robins\Work\END\Testing\Sample_Code\IAR\Bootloader\main.c 73
> >
> > unsigned long *p;
> > unsigned char x;
> >
> > p = (unsigned long)(0x0000FFFE);
> > x = * (unsigned long*)p;
> > txout(x);
>

okay it works, I had trouble thinking about it for a moment...

unsigned char *p;

p = (unsigned char*)(0xFFFE);
*p++;
txout(*p);
To increment the pointer, I think you'd just want:
p++;
not
*p++;
I believe the second case actually increments the data pointed to by p, which probably won't work since you're talking about a flash location.

----- Original Message -----
From: "mrobins99"
To: m...
Sent: Thursday, November 1, 2007 1:46:29 PM (GMT-0700) America/Denver
Subject: ***SPAM*** [msp430] Re: Reading a Flash byte

--- In m... , "htrada2" wrote:
>
> Hi,
> it doesnt work because you ar casting to an (unsigned long).
> besides, why are you using an unsigned long pointer and then asign
> the value it points to an unsigned char??.
> I think you should have:
>
> unsigned char *p;
> unsigned char x;
>
> p = (unsigned char*)(0xFFFE);
> x = *p;
> txout(x);
> and then you could increment p.
>
> --- In m... , "mrobins99" wrote:
> >
> > --- In m... , "mrobins99" wrote:
> > >
> > > I want to use a pointer to read the flash.
> > >
> > >
> > > I have
> > > x = * (unsigned long*)0xFFFE;
> > > txout(x);
> > > which works okay!
> > >
> > > How can I use a pointer and increment it?
> > >
> >
> > I try this: not working!!!
> > Error[Pe513]: a value of type "unsigned long" cannot be assigned
to
> > an entity of type "unsigned long *" C:\Michael
> > Robins\Work\END\Testing\Sample_Code\IAR\Bootloader\main.c 73
> >
> > unsigned long *p;
> > unsigned char x;
> >
> > p = (unsigned long)(0x0000FFFE);
> > x = * (unsigned long*)p;
> > txout(x);
>
okay it works, I had trouble thinking about it for a moment...

unsigned char *p;

p = (unsigned char*)(0xFFFE);
*p++;
txout(*p);
Hi,
it doesnt work because you ar casting to an (unsigned long).
besides, why are you using an unsigned long pointer and then asign
the value it points to an unsigned char??.
I think you should have:

unsigned char *p;
unsigned char x;

p = (unsigned char*)(0xFFFE);
x = *p;
txout(x);
and then you could increment p.

--- In m..., "mrobins99" wrote:
>
> --- In m..., "mrobins99" wrote:
> >
> > I want to use a pointer to read the flash.
> >
> >
> > I have
> > x = * (unsigned long*)0xFFFE;
> > txout(x);
> > which works okay!
> >
> > How can I use a pointer and increment it?
> > I try this: not working!!!
> Error[Pe513]: a value of type "unsigned long" cannot be assigned to
> an entity of type "unsigned long *" C:\Michael
> Robins\Work\END\Testing\Sample_Code\IAR\Bootloader\main.c 73
>
> unsigned long *p;
> unsigned char x;
>
> p = (unsigned long)(0x0000FFFE);
> x = * (unsigned long*)p;
> txout(x);
>
Dear Michael Robins,
Obviously you need a good C book and some more diligence reading it.
Regards,
Yuliyan

mrobins99 wrote:
> --- In m..., "htrada2" wrote:
>
>> Hi,
>> it doesnt work because you ar casting to an (unsigned long).
>> besides, why are you using an unsigned long pointer and then asign
>> the value it points to an unsigned char??.
>> I think you should have:
>>
>> unsigned char *p;
>> unsigned char x;
>>
>> p = (unsigned char*)(0xFFFE);
>> x = *p;
>> txout(x);
>> and then you could increment p.
>>
>> --- In m..., "mrobins99" wrote:
>>
>>> --- In m..., "mrobins99" wrote:
>>>
>>>> I want to use a pointer to read the flash.
>>>>
>>>>
>>>> I have
>>>> x = * (unsigned long*)0xFFFE;
>>>> txout(x);
>>>> which works okay!
>>>>
>>>> How can I use a pointer and increment it?
>>>>
>>>>
>>> I try this: not working!!!
>>> Error[Pe513]: a value of type "unsigned long" cannot be assigned
>>>
> to
>
>>> an entity of type "unsigned long *" C:\Michael
>>> Robins\Work\END\Testing\Sample_Code\IAR\Bootloader\main.c 73
>>>
>>> unsigned long *p;
>>> unsigned char x;
>>>
>>> p = (unsigned long)(0x0000FFFE);
>>> x = * (unsigned long*)p;
>>> txout(x);
>>>
>>>
> okay it works, I had trouble thinking about it for a moment...
>
> unsigned char *p;
>
> p = (unsigned char*)(0xFFFE);
> *p++;
> txout(*p);
>
Apparently IAR has some built in functions to handle this.

I found the folowing functions to get around this problem of the
limited pointer range.

unsigned type __data20_read_type(unsigned long address);
void __data20_write_type(unsigned long address, unsigned type);

I believe I have finished the bootloader portion. I will now build
the application to send the .bin file to the uC using my defined
protocol.

Thank you all for your help!

~1.5 work days to build a bootloader on a uC I have never used
before, not too bad I think!!! MPS430 is tricky compared to AVR!

--- In m..., "old_cow_yellow"
wrote:
>
> You seem to have more problems in c than its worth.
>
> If you want to learn c, why do you want to jump to Flash?
>
> A baseball player may occasionally use a bat to hit a fly or do
> needle work without taking off the glove.
>
> If you want to be a baseball player, learn how to hit and catch
> balls. Do not ask how to hit a fly or do embroidary.
>
> --- In m..., "mrobins99" wrote:
> >
> > new problem:
> >
> > unsigned char *p, *q;
> >
> > p = (unsigned char*)(0x1F000);
> >
> > Warning[Pe1053]: conversion from integer to smaller pointer
> >
> > cannot be > 0x0FFFF, why is this> I have up to 0x1FFFF in flash???
> >
> > --- In m..., Yuliyan Ivanov wrote:
> > >
> > > Dear Michael Robins,
> > > Obviously you need a good C book and some more diligence
reading
> it.
> > > Regards,
> > > Yuliyan
> > >
> > > mrobins99 wrote:
> > > > --- In m..., "htrada2" wrote:
> > > >
> > > >> Hi,
> > > >> it doesnt work because you ar casting to an (unsigned long).
> > > >> besides, why are you using an unsigned long pointer and then
> > asign
> > > >> the value it points to an unsigned char??.
> > > >> I think you should have:
> > > >>
> > > >> unsigned char *p;
> > > >> unsigned char x;
> > > >>
> > > >> p = (unsigned char*)(0xFFFE);
> > > >> x = *p;
> > > >> txout(x);
> > > >> and then you could increment p.
> > > >>
> > > >>
> > > >>
> > > >> --- In m..., "mrobins99"
wrote:
> > > >>
> > > >>> --- In m..., "mrobins99"
> wrote:
> > > >>>
> > > >>>> I want to use a pointer to read the flash.
> > > >>>>
> > > >>>>
> > > >>>> I have
> > > >>>> x = * (unsigned long*)0xFFFE;
> > > >>>> txout(x);
> > > >>>> which works okay!
> > > >>>>
> > > >>>> How can I use a pointer and increment it?
> > > >>>>
> > > >>>>
> > > >>> I try this: not working!!!
> > > >>> Error[Pe513]: a value of type "unsigned long" cannot be
> > assigned
> > > >>>
> > > > to
> > > >
> > > >>> an entity of type "unsigned long *" C:\Michael
> > > >>> Robins\Work\END\Testing\Sample_Code\IAR\Bootloader\main.c
73
> > > >>>
> > > >>> unsigned long *p;
> > > >>> unsigned char x;
> > > >>>
> > > >>> p = (unsigned long)(0x0000FFFE);
> > > >>> x = * (unsigned long*)p;
> > > >>> txout(x);
> > > >>>
> > > >>>
> > > >
> > > >
> > > > okay it works, I had trouble thinking about it for a moment...
> > > >
> > > > unsigned char *p;
> > > >
> > > > p = (unsigned char*)(0xFFFE);
> > > > *p++;
> > > > txout(*p);
> > > >
> > > >
> > > >
> > >
>
new problem:

unsigned char *p, *q;

p = (unsigned char*)(0x1F000);

Warning[Pe1053]: conversion from integer to smaller pointer

cannot be > 0x0FFFF, why is this> I have up to 0x1FFFF in flash???

--- In m..., Yuliyan Ivanov wrote:
>
> Dear Michael Robins,
> Obviously you need a good C book and some more diligence reading it.
> Regards,
> Yuliyan
>
> mrobins99 wrote:
> > --- In m..., "htrada2" wrote:
> >
> >> Hi,
> >> it doesnt work because you ar casting to an (unsigned long).
> >> besides, why are you using an unsigned long pointer and then
asign
> >> the value it points to an unsigned char??.
> >> I think you should have:
> >>
> >> unsigned char *p;
> >> unsigned char x;
> >>
> >> p = (unsigned char*)(0xFFFE);
> >> x = *p;
> >> txout(x);
> >> and then you could increment p.
> >>
> >>
> >>
> >> --- In m..., "mrobins99" wrote:
> >>
> >>> --- In m..., "mrobins99" wrote:
> >>>
> >>>> I want to use a pointer to read the flash.
> >>>>
> >>>>
> >>>> I have
> >>>> x = * (unsigned long*)0xFFFE;
> >>>> txout(x);
> >>>> which works okay!
> >>>>
> >>>> How can I use a pointer and increment it?
> >>>>
> >>>>
> >>> I try this: not working!!!
> >>> Error[Pe513]: a value of type "unsigned long" cannot be
assigned
> >>>
> > to
> >
> >>> an entity of type "unsigned long *" C:\Michael
> >>> Robins\Work\END\Testing\Sample_Code\IAR\Bootloader\main.c 73
> >>>
> >>> unsigned long *p;
> >>> unsigned char x;
> >>>
> >>> p = (unsigned long)(0x0000FFFE);
> >>> x = * (unsigned long*)p;
> >>> txout(x);
> >>>
> >>>
> >
> >
> > okay it works, I had trouble thinking about it for a moment...
> >
> > unsigned char *p;
> >
> > p = (unsigned char*)(0xFFFE);
> > *p++;
> > txout(*p);
> >
> >
>
You seem to have more problems in c than its worth.

If you want to learn c, why do you want to jump to Flash?

A baseball player may occasionally use a bat to hit a fly or do
needle work without taking off the glove.

If you want to be a baseball player, learn how to hit and catch
balls. Do not ask how to hit a fly or do embroidary.

--- In m..., "mrobins99" wrote:
>
> new problem:
>
> unsigned char *p, *q;
>
> p = (unsigned char*)(0x1F000);
>
> Warning[Pe1053]: conversion from integer to smaller pointer
>
> cannot be > 0x0FFFF, why is this> I have up to 0x1FFFF in flash???
>
> --- In m..., Yuliyan Ivanov wrote:
> >
> > Dear Michael Robins,
> > Obviously you need a good C book and some more diligence reading
it.
> > Regards,
> > Yuliyan
> >
> > mrobins99 wrote:
> > > --- In m..., "htrada2" wrote:
> > >
> > >> Hi,
> > >> it doesnt work because you ar casting to an (unsigned long).
> > >> besides, why are you using an unsigned long pointer and then
> asign
> > >> the value it points to an unsigned char??.
> > >> I think you should have:
> > >>
> > >> unsigned char *p;
> > >> unsigned char x;
> > >>
> > >> p = (unsigned char*)(0xFFFE);
> > >> x = *p;
> > >> txout(x);
> > >> and then you could increment p.
> > >>
> > >>
> > >>
> > >> --- In m..., "mrobins99" wrote:
> > >>
> > >>> --- In m..., "mrobins99"
wrote:
> > >>>
> > >>>> I want to use a pointer to read the flash.
> > >>>>
> > >>>>
> > >>>> I have
> > >>>> x = * (unsigned long*)0xFFFE;
> > >>>> txout(x);
> > >>>> which works okay!
> > >>>>
> > >>>> How can I use a pointer and increment it?
> > >>>>
> > >>>>
> > >>> I try this: not working!!!
> > >>> Error[Pe513]: a value of type "unsigned long" cannot be
> assigned
> > >>>
> > > to
> > >
> > >>> an entity of type "unsigned long *" C:\Michael
> > >>> Robins\Work\END\Testing\Sample_Code\IAR\Bootloader\main.c 73
> > >>>
> > >>> unsigned long *p;
> > >>> unsigned char x;
> > >>>
> > >>> p = (unsigned long)(0x0000FFFE);
> > >>> x = * (unsigned long*)p;
> > >>> txout(x);
> > >>>
> > >>>
> > >
> > >
> > > okay it works, I had trouble thinking about it for a moment...
> > >
> > > unsigned char *p;
> > >
> > > p = (unsigned char*)(0xFFFE);
> > > *p++;
> > > txout(*p);
> > >
> > >
> > >
>
mrobins99 wrote:

> new problem:
>
> unsigned char *p, *q;
>
> p = (unsigned char*)(0x1F000);
>
> Warning[Pe1053]: conversion from integer to smaller pointer
>
> cannot be > 0x0FFFF, why is this> I have up to 0x1FFFF in flash???

Welcome to MSP430X!

The background is that the traditional MSP430 is a traditional 16 bit
processor. The first version of our tools to support MSP430X, V3.xx,
only supported code in high memory. To access data you have to use
built-in intrinsic functions that use an "unsigned long" to represent
the address to access.

In the new compiler, V4.xx, we have two modes om operation. In the
"small" data model the world is exactly as in V3.xx. However, in the
"medium" and "large" models we have introduced "data 20" memory. You can
use the __data20 keyword to place variables, or make pointer point to,
the high memory.

Unfortunately, this comes with a price. In the "medium" and "large"
memory model, all functions must save and restore the full 20 bit of the
permanent registers, which require lightly more stack space

Oh, by the way, I strongly recommend using "medium" over "large", since,
in "medium", the default memory is the traditional 64KB memory.

For example, when using "medium" data model, you can express your
problem like:

unsigned char __data20 * p;

p = (unsigned char __data20 *)(0x1F000);
-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.