cancel
Showing results for 
Search instead for 
Did you mean: 

Hard Fault Error - STM32F100C8

ezyreach
Associate II
Posted on June 27, 2011 at 12:34

I am trying to implement EEPROM emulation in the flash memory. I am able to write and read the data from flash. When trying to write the second data it is going to HARDFAULT Error. I m not sure why this happens.

Below is the code....

void Write_Data(uint32_t Address,uint16_t *Data,uint16_t Len)

{

    uint8_t Temp_RdLen=0;

    uint16_t i=0;

    uint16_t RdLen=0;

       

    FLASH_UnlockBank1();

    Flash Bank1 Program Erase controller */

    NbrOfPage = (BANK1_WRITE_END_ADDR - BANK1_WRITE_START_ADDR)   

                                 /FLASH_PAGE_SIZE;  

    FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR |

                                          FLASH_FLAG_WRPRTERR);

        for(EraseCounter = 0; (EraseCounter < NbrOfPage) && (FLASHStatus ==

                                                      FLASH_COMPLETE); EraseCounter++)

        {

          FLASHStatus = FLASH_ErasePage(BANK1_WRITE_START_ADDR +

                                                               (FLASH_PAGE_SIZE * EraseCounter));

        } 

       

    while(Address < BANK1_WRITE_END_ADDR&& MemoryProgramStatus !=

                                                                                                         FAILED)

    {

        RdLen = (*(__IO uint32_t*)Address);

        Temp_RdLen=(uint8_t)(RdLen>>8);

        break;

    }

   

    if(Temp_RdLen == 0xFF)

    {

        while((Address < BANK1_WRITE_END_ADDR) && (FLASHStatus ==

                                                               FLASH_COMPLETE))

        {

            FLASHStatus = FLASH_ProgramHalfWord(Address, Len);

            Address+=2;

            break;

        }

       

        while((Address < BANK1_WRITE_END_ADDR) && (FLASHStatus ==

                            FLASH_COMPLETE)&& i<Len)           

        {

            FLASHStatus = FLASH_ProgramHalfWord(Address, *Data);

            Address+=2;

            Data+=1;

            if(Len-i>=2)

                i+=2;

            else if(Len-i==1)

                i+=1;

            else if(Len-i==0)

                break;                       

        }

    }

    else

    {

    }

    FLASH_LockBank1();

}

1. Before writing the data i m checking whether the data in the address 0x0800F000 is 0xFF. If so then i proceed to next step.

2. At this address - 0x0800F000 the string length is written and from 0x0800F002 the original data is written.

3. I m able to read back the data from this address also.

4. Next i m checking that whether  the data in the address 0x0800F025  is 0xFF.

5. If yes, then i m trying to write the next string length.

6. But at this point, the control goes to HARDFAULT_ERROR.

I m not sure where is the original trouble is..

11 REPLIES 11
joseph239955_st
Associate II
Posted on June 28, 2011 at 14:30

Hi there,

Even without printf, you can debug a hard fault by setting a breakpoint in you hardfault handler, and when it reach the breakpoint and halted, you can examine the fault status registers.

http://infocenter.arm.com/help/topic/com.arm.doc.dui0552a/Cihcfefj.html

If you can do a stack trace manually it can also give you the address of the code where the fault happended.

The Cortex-M3 Devices Generic User Guide (as well as Cortex-M0 and Cortex-M4 versions) can be found in:

http://infocenter.arm.com/help/topic/com.arm.doc.dui0552a/index.html

regards,

Joseph

Posted on June 28, 2011 at 17:17

I m using IAR....hence not sure how to retarget the printf for the corresponding USART....

 

You could also use sprintf() to a staging buffer, and output that to a port of your choice.

Yes the second string, i m starting to write from the address 0x0800F025.

 

 

Is the writing of data starting from odd address is not possible?

 

If so why?

 

From the manual we have

''Programming and erasing the Flash memory

The Flash memory can be programmed 16 bits (half words) at a time.''

I can't find a better cite quickly, but what is inferred by the statement is that the minimum write quanta is 16-bits, on a 16-bit boundary. The width of the array is 64-bit as I recall, and writing across boundaries makes the hardware overly complex.

''up to 64 Kb × 64 bits divided into 256 pages of 2 Kbytes each (see Table 4) for

high-density devices''

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