2015-06-04 06:03 PM
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,§or)!=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.2015-06-04 07:03 PM
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.2015-06-05 08:06 AM
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?2015-06-05 08:15 AM
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.
2015-06-05 08:25 AM
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 =)2015-06-06 02:00 AM
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,§or); HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,(uint32_t)0x08100000,0x12345678); HAL_FLASH_Lock();2016-07-22 06:25 PM