cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F429I-Disco FLASH erase error

es131245
Associate II
Posted on June 05, 2015 at 03:03

Wrote some code for STM32F429I-Disco that writes data in flash but it denied to work in USB receive function.

''static int8_t CDC_Receive_HS(uint8_t*Buf,uint32_t*Len)''

But it did work in main.

What can it be?

uint32_t sector=0;

HAL_FLASH_Unlock();

static FLASH_EraseInitTypeDef erase;

erase.TypeErase=FLASH_TYPEERASE_SECTORS;

erase.VoltageRange=FLASH_VOLTAGE_RANGE_3;

erase.Sector=(uint32_t)12;

erase.NbSectors=(uint32_t)1;

if(HAL_FLASHEx_Erase(&erase,&sector)!=HAL_OK)

{uint32_t errorcode = HAL_FLASH_GetError();

    extern USBD_HandleTypeDef hUsbDeviceHS;

  uint8_t buf[512];

  buf[0]=(uint8_t)(errorcode>>24);

  buf[1]=(uint8_t)(errorcode>>16);

  buf[2]=(uint8_t)(errorcode>>8);

  buf[3]=(uint8_t)errorcode;

  USBD_CDC_SetTxBuffer(&hUsbDeviceHS,&buf[0],4);

  USBD_CDC_TransmitPacket(&hUsbDeviceHS);

}

//HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,(uint32_t)0x08100000,(uint32_t)0x87654321);

HAL_FLASH_Lock(); 

I get 00 00 00 06.
6 REPLIES 6
Posted on June 05, 2015 at 04:03

What STM32 part are we talking about?

Can't help you much with HAL, but one thing to watch for is to clear any pending error/status bits first.

Also be aware that sector erasing can take a long while to complete, and can interfere with real-time operation.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
es131245
Associate II
Posted on June 05, 2015 at 17:06

Its 429 disco with 429ZIT6U.

Few second isn't that bad. Moreother HAL doen't have any other function to erase frash exept mass erase at leave i've couldn't find one.

Can you show how to clear those bits?

And what memory areas are preffered for user data?

Posted on June 05, 2015 at 17:15

In the SPL we do this

FLASH_Unlock();
/* Clear pending flags (if any), observed post flashing */
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR| FLASH_FLAG_PGSERR);

It's tend to favour the 16KB sectors, I'd use the one at 0x08000000 for a boot loader, but the others would be good for user data, you could journal data across a pair of them. Depends of course how big the user data is, and how frequently you'd want to update it.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
es131245
Associate II
Posted on June 05, 2015 at 17:25

My data now is less than 4 floats 32bit and maybe i'm going to use +array[20] 32bits later.

I've checked 08000000 and saw data there. That why i've choosen bank2.

PS thank you. I'll check flags tonight's night =)

es131245
Associate II
Posted on June 06, 2015 at 11:00

Thx! It worked!

static FLASH_EraseInitTypeDef erase;

uint32_t sector;

FLASH->SR = FLASH_FLAG_PGPERR;

FLASH->SR = FLASH_FLAG_PGSERR;

FLASH->SR = FLASH_FLAG_EOP;

FLASH->SR = FLASH_FLAG_OPERR;

FLASH->SR = FLASH_FLAG_WRPERR;

FLASH->SR = FLASH_FLAG_PGAERR;

HAL_FLASH_Unlock();

erase.TypeErase=FLASH_TYPEERASE_SECTORS;

erase.VoltageRange=FLASH_VOLTAGE_RANGE_3;

erase.Sector=(uint32_t)12;

erase.NbSectors=(uint32_t)1;

HAL_FLASHEx_Erase(&erase,&sector);

HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,(uint32_t)0x08100000,0x12345678);

HAL_FLASH_Lock();

lpr32771
Associate
Posted on July 23, 2016 at 03:25

you should this great app: ''Night club strobe light''

Link ios: https://itunes.apple.com/us/app/night-club-strobe-light-strobe/id1128598578?ls=1&mt=8

Link preview: https://www.youtube.com/watch?v=WKEbaaBdtd0