cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f407 accessing internal flash

netstv
Associate II
Posted on November 04, 2015 at 23:08

I'm using the Keil v4 IDE/Toolchain

IDE-Version:

�Vision V4.70.0.0

Tool Version Numbers:

Toolchain:        MDK-ARM Professional  Version: 4.70.0.0

The STM32F407VET6 is my full version.  So I have 512MB flash.

My image size is only about 120MB.  So I want to use the last 256MB for flash storage.  As I understand it, the first sectors are 4 - 16K sectors, 1-64K sector, and 3 - 128K sectors.

My problem is this.  I want to write data to the flash @ 0x08006000.  

My snip of code that I want to have this work is:

int main(void)

{

    // GPIO_InitTypeDef  GPIO_InitStructure;

    /*!< At this stage the microcontroller clock setting is already configured to

         168 MHz, this is done through SystemInit() function which is called from

         startup file (startup_stm32f4xx.s) before to branch to application main.

         To reconfigure the default setting of SystemInit() function, refer to

         system_stm32f4xx.c file

       */

       FLASH_Status flash_status; 

        

        FLASH_Unlock();

        FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR |FLASH_FLAG_WRPERR |

                FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);

        flash_status = FLASH_EraseSector(FLASH_Sector_6, VoltageRange_3);

        if(flash_status == FLASH_COMPLETE)

            FLASH_ProgramWord(EEpromCheckByte,EEPROM_MAGIC);

        FLASH_Lock();

}

As I step from the SystemInit (from the startup_stm32f4xx.s) the FLASH->SR = 0x000000C0

So I MUST be doing something wrong in the Keil startup?  I've done this before on other ST's and it works fine.  I never had to do anything special.

What am I missing?

Thanks.

-stv

#rewrite #stm32f #flash
4 REPLIES 4
Posted on November 05, 2015 at 01:11

My problem is this.  I want to write data to the flash @ 0x08006000

0x08060000 ?? FLASH_Sector_7

The defines might be helpful.

All the F407 parts have 1MB of FLASH on die

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
netstv
Associate II
Posted on November 09, 2015 at 18:49

Sorry didn't put the defines.... I'm using the header file  stm32f4xx_flash.h

For the Voltage and flash sector.

#define VoltageRange_1        ((uint8_t)0x00)  /*!< Device operating range: 1.8V to 2.1V */

#define VoltageRange_2        ((uint8_t)0x01)  /*!<Device operating range: 2.1V to 2.7V */

#define VoltageRange_3        ((uint8_t)0x02)  /*!<Device operating range: 2.7V to 3.6V */

#define VoltageRange_4        ((uint8_t)0x03)  /*!<Device operating range: 2.7V to 3.6V + External Vpp */

/** @defgroup FLASH_Sectors

  * @{

  */ 

#define FLASH_Sector_0     ((uint16_t)0x0000) /*!< Sector Number 0 */

#define FLASH_Sector_1     ((uint16_t)0x0008) /*!< Sector Number 1 */

#define FLASH_Sector_2     ((uint16_t)0x0010) /*!< Sector Number 2 */

#define FLASH_Sector_3     ((uint16_t)0x0018) /*!< Sector Number 3 */

#define FLASH_Sector_4     ((uint16_t)0x0020) /*!< Sector Number 4 */

#define FLASH_Sector_5     ((uint16_t)0x0028) /*!< Sector Number 5 */

#define FLASH_Sector_6     ((uint16_t)0x0030) /*!< Sector Number 6 */

#define FLASH_Sector_7     ((uint16_t)0x0038) /*!< Sector Number 7 */

#define FLASH_Sector_8     ((uint16_t)0x0040) /*!< Sector Number 8 */

#define FLASH_Sector_9     ((uint16_t)0x0048) /*!< Sector Number 9 */

#define FLASH_Sector_10    ((uint16_t)0x0050) /*!< Sector Number 10 */

#define FLASH_Sector_11    ((uint16_t)0x0058) /*!< Sector Number 11 */

Here are the other defines...

#define ADDR_SECTOR_6 0x08060000

const u32 EEpromCheckByte  __attribute__((at(ADDR_SECTOR_6))) = 0; // EEprom check byte

 

u32 EEPROM_MAGIC = 0x73736767;

Maybe I have an outdated data sheet (STM32F407x.pdf) says in Chapter 7 the ''E'' of the part number STM32F407VET6  means 512MB flash.

But I think it has something to do with my Keil setup.  Because once I jump from the SystemInit() into main(), that error bit is flipped.  I'm using the Keil debugger.. Maybe I'm locking the memory somehow?  In some weird setting?

Thanks 

Posted on November 09, 2015 at 18:56

Your defines, I have the ST ones

EEpromCheckByte, EEPROM_MAGIC, etc

You shouldn't leave the main() function, put a while(1); in there so it doesn't exit.

The debugger will interfere with the Flash controller, but you seem to clear the flags. I'd compile the code, but obviously I can't.

They sell versions with 256KB, and 512KB tested, but all the die have 1MB. It costs a lot in tester time to validate the memory. ie I can test 4x 256KB parts in the time it would take for 1x 1MB, and the costs are passed along.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 09, 2015 at 19:00

Crossed on the wire, but your still have the sector number wrong

#define FLASH_Sector_0     ((uint16_t)0x0000) /*!< Sector Number 0  0x08000000*/

#define FLASH_Sector_1     ((uint16_t)0x0008) /*!< Sector Number 1  0x08004000 */

#define FLASH_Sector_2     ((uint16_t)0x0010) /*!< Sector Number 2  0x08008000 */

#define FLASH_Sector_3     ((uint16_t)0x0018) /*!< Sector Number 3  0x0800C000 */

#define FLASH_Sector_4     ((uint16_t)0x0020) /*!< Sector Number 4  0x08010000 */

#define FLASH_Sector_5     ((uint16_t)0x0028) /*!< Sector Number 5  0x08020000 */

#define FLASH_Sector_6     ((uint16_t)0x0030) /*!< Sector Number 6  0x08040000 */

#define FLASH_Sector_7     ((uint16_t)0x0038) /*!< Sector Number 7  0x08060000 */

#define FLASH_Sector_8     ((uint16_t)0x0040) /*!< Sector Number 8  0x08080000 */

#define FLASH_Sector_9     ((uint16_t)0x0048) /*!< Sector Number 9  0x080A0000 */

#define FLASH_Sector_10    ((uint16_t)0x0050) /*!< Sector Number 10 0x080C0000 */

#define FLASH_Sector_11    ((uint16_t)0x0058) /*!< Sector Number 11 0x080E0000 */

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