EmbeddedRelated.com
Forums

Reading entire contents of flash memory

Started by mastarre April 21, 2009
I am using an MSP430FG4618 and have found a wealth of information and examples on writing to the flash but very little on reading to it. I have written a program to fill the first half of the flash memory with sensor based data but I would not like to read that data and send it to the PC via UART.

The manual does not have any sections specifically regarding reading the memory and my extensive searching has been ineffective.

Does anyone have any hints, tips, or clues to read from 0x6000 to 0xFC00 so that I can send it across the wire to the computer?

Thanks so much,
Mike

Beginning Microcontrollers with the MSP430

int * ptr;
for (ptr = 0x6000;ptr <= 0xFC00;ptr++){
UART_TX(*ptr);
}

Just supply UART_TX() and you should be done.

mastarre said the following on 4/21/2009 2:28 PM:
> I am using an MSP430FG4618 and have found a wealth of information and
> examples on writing to the flash but very little on reading to it. I
> have written a program to fill the first half of the flash memory with
> sensor based data but I would not like to read that data and send it
> to the PC via UART.
>
> The manual does not have any sections specifically regarding reading
> the memory and my extensive searching has been ineffective.
>
> Does anyone have any hints, tips, or clues to read from 0x6000 to
> 0xFC00 so that I can send it across the wire to the computer?
>
> Thanks so much,
> Mike


unsigned char * ptr; // sorry, this might work better
for (ptr = 0x6000;ptr <= 0xFC00;ptr++){
UART_TX(*ptr);
}

Aaron Greer said the following on 4/21/2009 2:39 PM:
> int * ptr;
> for (ptr = 0x6000;ptr <= 0xFC00;ptr++){
> UART_TX(*ptr);
> }
>
> Just supply UART_TX() and you should be done.
>
> mastarre said the following on 4/21/2009 2:28 PM:
>> I am using an MSP430FG4618 and have found a wealth of information and
>> examples on writing to the flash but very little on reading to it. I
>> have written a program to fill the first half of the flash memory
>> with sensor based data but I would not like to read that data and
>> send it to the PC via UART.
>>
>> The manual does not have any sections specifically regarding reading
>> the memory and my extensive searching has been ineffective.
>>
>> Does anyone have any hints, tips, or clues to read from 0x6000 to
>> 0xFC00 so that I can send it across the wire to the computer?
>>
>> Thanks so much,
>> Mike


mastarre wrote:
> I am using an MSP430FG4618 and have found a wealth of information and examples on writing to the flash but very little on reading to it. I have written a program to fill the first half of the flash memory with sensor based data but I would not like to read that data and send it to the PC via UART.
>
> The manual does not have any sections specifically regarding reading the memory and my extensive searching has been ineffective.
>
> Does anyone have any hints, tips, or clues to read from 0x6000 to 0xFC00 so that I can send it across the wire to the computer?
>

There very many ways to do it. Here is what I do. All my com is done
with 8 bits binary. Every com packet has a checksum, both ways, and
needs an ack or data from the MSP. The MSP is treated like a slave.

So I send a 'set EEPROM address' instruction to the MSP. Then successive
'Read EEPROM' instructions and the MSP sends back say 32 bytes of data
for each of these. It is not that much slower than dumping the whole
thing unless the whole thing didn't checksum. In that case you are way
ahead by getting the data a page at a time.

Best, Dan.

--
email: y...@lakeweb.net but drop the 'x'.

--- In m..., Aaron Greer wrote:
>
> unsigned char * ptr; // sorry, this might work better
> for (ptr = 0x6000;ptr <= 0xFC00;ptr++){
> UART_TX(*ptr);
> }
>
> Aaron Greer said the following on 4/21/2009 2:39 PM:
> > int * ptr;
> > for (ptr = 0x6000;ptr <= 0xFC00;ptr++){
> > UART_TX(*ptr);
> > }
> >
> > Just supply UART_TX() and you should be done.
> >
> > mastarre said the following on 4/21/2009 2:28 PM:
> >>
> >>
> >> I am using an MSP430FG4618 and have found a wealth of information and
> >> examples on writing to the flash but very little on reading to it. I
> >> have written a program to fill the first half of the flash memory
> >> with sensor based data but I would not like to read that data and
> >> send it to the PC via UART.
> >>
> >> The manual does not have any sections specifically regarding reading
> >> the memory and my extensive searching has been ineffective.
> >>
> >> Does anyone have any hints, tips, or clues to read from 0x6000 to
> >> 0xFC00 so that I can send it across the wire to the computer?
> >>
> >> Thanks so much,
> >> Mike
> >>
> >>
>
>

In either case I would be casting ptr as an int in the for loop which would create issues. I had been attempting to use a pointer but was having issues -- the posts here were just what I needed!

I am going to dump everything into functions to keep things clean but for now the following works:

P2SEL |= 0x010;
UCA0CTL1 |= UCSSEL_2;
UCA0BR0 = 0x6D;
UCA0BR1 = 0x00;
UCA0MCTL = 4;
UCA0CTL1 &= ~UCSWRST;

unsigned char * ptr;
unsigned int length = Memend - Memstart;
for (i=0;i while(!(IFG2 & UCA0TXIFG));
UCA0TXBUF = *ptr;
*ptr++;
}
I'm pleased! Such a relief, and likewise such a simple solution. Thanks again for the help!

--- In m..., "mastarre" wrote:
>
> --- In m..., Aaron Greer wrote:
> >
> > unsigned char * ptr; // sorry, this might work better
> > for (ptr = 0x6000;ptr <= 0xFC00;ptr++){
> > UART_TX(*ptr);
> > }
> >
> > Aaron Greer said the following on 4/21/2009 2:39 PM:
> > > int * ptr;
> > > for (ptr = 0x6000;ptr <= 0xFC00;ptr++){
> > > UART_TX(*ptr);
> > > }
> > >
> > > Just supply UART_TX() and you should be done.
> > >
> > > mastarre said the following on 4/21/2009 2:28 PM:
> > >>
> > >>
> > >> I am using an MSP430FG4618 and have found a wealth of information and
> > >> examples on writing to the flash but very little on reading to it. I
> > >> have written a program to fill the first half of the flash memory
> > >> with sensor based data but I would not like to read that data and
> > >> send it to the PC via UART.
> > >>
> > >> The manual does not have any sections specifically regarding reading
> > >> the memory and my extensive searching has been ineffective.
> > >>
> > >> Does anyone have any hints, tips, or clues to read from 0x6000 to
> > >> 0xFC00 so that I can send it across the wire to the computer?
> > >>
> > >> Thanks so much,
> > >> Mike
> > >>
> > >>
> >
> >
> >
> > In either case I would be casting ptr as an int in the for loop which would create issues. I had been attempting to use a pointer but was having issues -- the posts here were just what I needed!
>
> I am going to dump everything into functions to keep things clean but for now the following works:
>
> P2SEL |= 0x010;
> UCA0CTL1 |= UCSSEL_2;
> UCA0BR0 = 0x6D;
> UCA0BR1 = 0x00;
> UCA0MCTL = 4;
> UCA0CTL1 &= ~UCSWRST;
>
> unsigned char * ptr;
> unsigned int length = Memend - Memstart;
> for (i=0;i > while(!(IFG2 & UCA0TXIFG));
> UCA0TXBUF = *ptr;
> *ptr++;
> }
> I'm pleased! Such a relief, and likewise such a simple solution. Thanks again for the help!
>
Actually, after thinking about it more, that will not work correctly. What I should be doing is more like what you suggested:

******BEGIN CODE SNIPPET*****
// First half of memory
for (readPointer = (unsigned char *)0x6000;readPointer < (unsigned char *)0xfc00;readPointer++) {
uartSendChar(*readPointer);
*readPointer++;
}
__disable_interrupt(); // End the TX interrupt

// Second half of memory
for (readPointer = (unsigned char *)0x10000;readPointer < (unsigned char *)0x20000;readPointer++) {
uartSendChar(*readPointer);
*readPointer++;
}
__disable_interrupt(); // End the TX interrupt
******END CODE SNIPPET*****

But of course I get the error
`Warning[Pe1053]: conversion from integer to smaller pointer`

The voice recorded ex does in fact list the following:
#define Memstart 0x6000 // Memory range to be filled with
#define Memend 0xfc00 // sampled data for voice recorder

#define Memstart2 0x10000 // Memory range to be filled with
#define Memend2 0x20000 // sampled data for voice recorder

but that does not seem right. Looking at the memory map of the manual (section 1-4), I am not sure what the start and end points for the 2nd section are.

Thoughts? Suggestions?

Try this:

unsigned char * ptr;
unsigned int length = Memend - Memstart;
for (i=0,ptr=(unsigned char *)Memstart;i initialize ptr somewhere, here works
while(!(IFG2 & UCA0TXIFG));
UCA0TXBUF = *ptr;
ptr++; // notice that there is no
"*" here
}



--- In m..., Aaron Greer wrote:
>
> Try this:
>
> unsigned char * ptr;
> unsigned int length = Memend - Memstart;
> for (i=0,ptr=(unsigned char *)Memstart;i > initialize ptr somewhere, here works
> while(!(IFG2 & UCA0TXIFG));
> UCA0TXBUF = *ptr;
> ptr++; // notice that there is no
> "*" here
> }
>
>
>
That works excellent and looks a little bit like what I had modified my last posting to. I will go with that!

There is still one problem though and that is that declaring ptr as char indicates that the data it references is a char, which is correct, but the address of the 2nd part of memory exceeds the size of char (0x20000) so I get the following error:

Warning[Pe1053]: conversion from integer to smaller pointer

When I apply what you wrote to the 2nd half:
unsigned char * ptr2;
unsigned long length2 = Memend2- Memstart2;
for (i=0,ptr2=(unsigned char *)Memstart2;i uartSendChar(*ptr2);
ptr2++;
}

So my question is, I want to pull 8bit data and send that down the pipe. If I change the ptr2 to a larger type, will the data it pulls still be 8bits? I have always been told that the type of ptr should match the type of data it references.

Can I borrow a little bit more of your expertise in an answer to that question?

Thank you so much!

You should read this:
http://focus.ti.com/general/docs/techdocsabstract.tsp?abstractName=slaa376
mastarre said the following on 4/22/2009 12:59 PM:
> --- In m... , Aaron
> Greer wrote:
> >
> > Try this:
> >
> > unsigned char * ptr;
> > unsigned int length = Memend - Memstart;
> > for (i=0,ptr=(unsigned char *)Memstart;i > > initialize ptr somewhere, here works
> > while(!(IFG2 & UCA0TXIFG));
> > UCA0TXBUF = *ptr;
> > ptr++; // notice that there is no
> > "*" here
> > }
> >
> >
> >
> >
> >
> That works excellent and looks a little bit like what I had modified
> my last posting to. I will go with that!
>
> There is still one problem though and that is that declaring ptr as
> char indicates that the data it references is a char, which is
> correct, but the address of the 2nd part of memory exceeds the size of
> char (0x20000) so I get the following error:
>
> Warning[Pe1053]: conversion from integer to smaller pointer
>
> When I apply what you wrote to the 2nd half:
> unsigned char * ptr2;
> unsigned long length2 = Memend2- Memstart2;
> for (i=0,ptr2=(unsigned char *)Memstart2;i > uartSendChar(*ptr2);
> ptr2++;
> }
>
> So my question is, I want to pull 8bit data and send that down the
> pipe. If I change the ptr2 to a larger type, will the data it pulls
> still be 8bits? I have always been told that the type of ptr should
> match the type of data it references.
>
> Can I borrow a little bit more of your expertise in an answer to that
> question?
>
> Thank you so much!
>


--- In m..., Aaron Greer wrote:
>
> You should read this:
> http://focus.ti.com/general/docs/techdocsabstract.tsp?abstractName=slaa376
> mastarre said the following on 4/22/2009 12:59 PM:
> >
> >
> > --- In m... , Aaron
> > Greer wrote:
> > >
> > > Try this:
> > >
> > > unsigned char * ptr;
> > > unsigned int length = Memend - Memstart;
> > > for (i=0,ptr=(unsigned char *)Memstart;i > > > initialize ptr somewhere, here works
> > > while(!(IFG2 & UCA0TXIFG));
> > > UCA0TXBUF = *ptr;
> > > ptr++; // notice that there is no
> > > "*" here
> > > }
> > >
> > >
> > >
> > >
> > >
> > That works excellent and looks a little bit like what I had modified
> > my last posting to. I will go with that!
> >
> > There is still one problem though and that is that declaring ptr as
> > char indicates that the data it references is a char, which is
> > correct, but the address of the 2nd part of memory exceeds the size of
> > char (0x20000) so I get the following error:
> >
> > Warning[Pe1053]: conversion from integer to smaller pointer
> >
> > When I apply what you wrote to the 2nd half:
> > unsigned char * ptr2;
> > unsigned long length2 = Memend2- Memstart2;
> > for (i=0,ptr2=(unsigned char *)Memstart2;i > > uartSendChar(*ptr2);
> > ptr2++;
> > }
> >
> > So my question is, I want to pull 8bit data and send that down the
> > pipe. If I change the ptr2 to a larger type, will the data it pulls
> > still be 8bits? I have always been told that the type of ptr should
> > match the type of data it references.
> >
> > Can I borrow a little bit more of your expertise in an answer to that
> > question?
> >
> > Thank you so much!
> >
> >
> >
>
>
I found the PDF on google but found the examples to be worthless. Now that the link comes from the TI site I see `associated files` as well. PERFECT!!

Thank you, you have taught me how to fish :)