cancel
Showing results for 
Search instead for 
Did you mean: 

Flash programming byte

cgrenier
Associate II
Posted on May 27, 2009 at 16:36

Flash programming byte

3 REPLIES 3
cgrenier
Associate II
Posted on May 17, 2011 at 13:13

Hello,

I have data to store in the flash. Many structures of 11 bytes to save in a page. But I read from the programming manual that we could not program a byte only. How can I manage that?

I'd like to store 11 bytes. I get always a FLASH_PG_ERR!

Data will start from address 0x800C800. The first structure will be stored from 0x800C800 - 0x800C80A. The second one from 0x800C80B - 0x800C815. Is it a problem? I'm little bit confused to avoid this FLASH_PG_ERR...

[FLASH PAGE]

[DATA #1] [DATA #2] ... [DATA #n]

ivanov-i
Associate II
Posted on May 17, 2011 at 13:13

Just store 12 bytes per each structure. And always start at even address.

gabrielbonato
Associate II
Posted on May 17, 2011 at 13:13

Hello,

Address: specifies the address to be programmed.

This parameter can be 0x1FFFF804 or 0x1FFFF806.

''stm32f10x_flash.c''

/*******************************************************************************

* Function Name : FLASH_ProgramOptionByteData

* Description : Programs a half word at a specified Option Byte Data address.

* Input : - Address: specifies the address to be programmed.

* This parameter can be 0x1FFFF804 or 0x1FFFF806.

* - Data: specifies the data to be programmed.

* Output : None

* Return : FLASH Status: The returned value can be: FLASH_BUSY,

* FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or

* FLASH_TIMEOUT.

*******************************************************************************/

FLASH_Status FLASH_ProgramOptionByteData(u32 Address, u8 Data)

{

FLASH_Status status = FLASH_COMPLETE;

/* Check the parameters */

assert_param(IS_OB_DATA_ADDRESS(Address));

status = FLASH_WaitForLastOperation(ProgramTimeout);

if(status == FLASH_COMPLETE)

{

/* Authorize the small information block programming */

FLASH->OPTKEYR = FLASH_KEY1;

FLASH->OPTKEYR = FLASH_KEY2;

/* Enables the Option Bytes Programming operation */

FLASH->CR |= CR_OPTPG_Set;

*(vu16*)Address = Data;

/* Wait for last operation to be completed */

status = FLASH_WaitForLastOperation(ProgramTimeout);

if(status != FLASH_BUSY)

{

/* if the program operation is completed, disable the OPTPG Bit */

FLASH->CR &= CR_OPTPG_Reset;

}

}

/* Return the Option Byte Data Program Status */

return status;

}