cancel
Showing results for 
Search instead for 
Did you mean: 

Adress Type (Flash Memory)

leventeyigel52
Associate II
Posted on January 13, 2012 at 10:23

Hi,

I want to read all the datas of the Flash Memory on STM32F103RB

// Adress start value = 0x08000000 ,end value = 0x0801FFFF;

while(Adress != 0x0801FFF) {

 FLASH_Unlock();             

 Data=*((uint16_t *) Adres);  //read at 0x08000000 flash memory address 

        FLASH_Lock(); 

        Adres=Adres+2;

        USART_SendData(USART2,Data); 

}

When this program runs, Adress data turns decimal type and i can't see the values .

What can i do for describing Adress's data type to increasing hexadecimal type ?

7 REPLIES 7
rosarium
Associate II
Posted on January 13, 2012 at 12:06

In the linker script:

MEMORY

{

  

RAM_C (xrw) : ORIGIN = 0x10000000, LENGTH = 64K

  

RAM_D (xrw) : ORIGIN = 0x20000000, LENGTH = 128K

  

FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K

}

leventeyigel52
Associate II
Posted on January 13, 2012 at 12:21

I tried to say how can i define the adress value and increase it. 

I have a for loop and the adress value is increase in the loop, thus i can get the values on all of the adresses in flash memory ?

When i define ''u32 Adress=0x08000000;'' or ''uint32_t Adress'' or ''uint64_t Adress;'' this returns me decimal values and i dont want this,i want to debug with hexadecimal form.

 Can you read the source code  and give me advice about this ? 

leventeyigel52
Associate II
Posted on January 13, 2012 at 12:24

for(i=0;i<65536;i++) {

        FLASH_Unlock();             

        Data=*((uint16_t *) Adress); //read at Adress^s value flash memory address 

        FLASH_Lock(); 

        Adress=Adress+2;

        USART_SendData(USART2,Data); 

        }

I have the problem at this loop and Adress increasing problem.

Posted on January 13, 2012 at 12:32

a) You don't need to Lock/Unlock the flash memory to read it

b) USART_SendData is not going to consume 16-bit words c) You need to check the TXE status of the USART before sending each byte d) Your terminal address is wrong

// Address start value = 0x08000000 ,end value = 0x0801FFFF;
uint16_t Data;
uint32_t Address;
Address = 0x08000000;
while(Address < 0x0801FFFF) // 512KB limit
{
Data= *((uint16_t *)Address); //read at 0x08000000+ flash memory address 
Address += 2;
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2,((Data >> 0) & 0xFF)); // Send Low Byte
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2,((Data >> 8) & 0xFF)); // Send High Byte
}

This will send the data as raw 8-bit bytes. Plus it will probably overflow the console, and get some corruption. Usually you'd send it in small blocks, with a checksum. Want the data in hex digits, then you're going to need to break the bytes down into ASCII hex/alpha characters. Want pretty formatting, you'll need to add the code to do that.

void SendHexByte(uint16_t Data)
{
static const char Hex[]=''0123456789ABCDEF'';
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2,(Hex[(Data >> 4) & 0xF)]); // Send High Nibble
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2,(Hex[(Data >> 0) & 0xF)]); // Send Low Nibble
}

void DumpFlash(void)
{
uint16_t Data;
uint32_t Address;
for(Address = 0x08000000; Address<
0x08020000
; Address += 2)
{
Data= *((uint16_t *)Address); //read at 0x08000000+ flash memory address 
SendHexByte(((Data >> 0) & 0xFF)); // Send Low Byte
SendHexByte(((Data >> 8) & 0xFF)); // Send High Byte
}
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
leventeyigel52
Associate II
Posted on January 13, 2012 at 13:59

I solved this problem thanks to you ..

Thanks clive1 !!!!!

leventeyigel52
Associate II
Posted on January 16, 2012 at 08:51

clive1

your code helped me,thanks a lot again . I'll ask you a question again

I want to see these adresses and datas like ->

0x08000000  0x07CE

0x08000002  0xFFFF

.. ..

...

...

0x0801FFFF  0xFFFF

on  the hyper terminal screen

Adress value is 32-bit so I can't write the algorithm or code  for this.

Can u help me about it ?How can we send Adress's value 

Posted on January 16, 2012 at 14:46

void SendChar(char Data)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, Data);
}
void SendHexByte(uint16_t Data)
{
static const char Hex[]=''0123456789ABCDEF'';
SendChar(Hex[((Data >> 4) & 0xF])); // Send High Nibble
SendChar(Hex[((Data >> 0) & 0xF)]); // Send Low Nibble
}
void SendHexWord(uint16t Data)
{
SendHexByte(((Data >> 8) & 0xFF)); // Send High Byte
SendHexByte(((Data >> 0) & 0xFF)); // Send Low Byte
}
void SendHexDword(uint32t Data)
{
SendHexWord((uint16_t)((Data >> 16) & 0xFFFF)); // Send High Word
SendHexWord((uint16_t)((Data >> 0) & 0xFFFF)); // Send Low Word
}
void DumpFlash(void)
{
uint16_t Data;
uint32_t Address;
for(Address = 0x08000000; Address<0x08020000; Address += 2)
{
Data= *((uint16_t *)Address); //read at 0x08000000+ flash memory address
SendChar('0')
SendChar('x')
SendHexDword(Address);
SendChar(' ')
SendChar('0')
SendChar('x')
SendHexWord(Data);
SendChar('
');
SendChar('
');
}
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..