AnsweredAssumed Answered

stm32f4xx FLASH_ProgramWord error, FLASH_ERROR_PROGRAM

Question asked by Angelo Dureghello on Apr 2, 2014
Latest reply on Apr 3, 2014 by Clive One
Dear,

i am getting this error, this is my flash write routine:

#include <stm32f4xx_flash.h>
#include "flash.h"

uint8_t flash_status;

volatile uint32_t* flash_location_sect3 = (volatile uint32_t*)0x800C000;

#define FLASH_CFG_ULONGS  512

int save_data_to_flash(unsigned long *data)
{
        int x;
 
        flash_status = FLASH_COMPLETE;
 
        FLASH_Unlock();
 
        FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR |FLASH_FLAG_WRPERR |
                FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
 
        /* Get the number of the start and end sectors */
        //sector_start = GetSector(FLASH_USER_START_ADDR);
        //secto_end = GetSector(FLASH_USER_END_ADDR);
 
        flash_status = FLASH_EraseSector(FLASH_Sector_3, VoltageRange_3);
 
        if (flash_status != FLASH_COMPLETE) {
                FLASH_Lock();
                return ERR_BAD_ERASE;
        }
 
        for (x = 0; x < FLASH_CFG_ULONGS; ++x) {
 
                if (*flash_location_sect3 != 0xffffffff)
                        return 254;
 
                //program first run status bit
                flash_status =
                        FLASH_ProgramWord((uint32_t)flash_location_sect3, *data);
 
                flash_location_sect3++;
                data++;
 
                if (flash_status != FLASH_COMPLETE) {
                        FLASH_Lock();
                        return flash_status;
                }
        }
        return -1;
}

I already checked that:
- erase works properly
- write fail probably at second FLASH_ProgramWord() (since i see the first value written correctly)

The error i am getting is FLASH_ERROR_PROGRAM (7)
Every help is welcome.

Outcomes