stm32f2xx HAL_FLASH_Program returning nonsense

733 Views Asked by At

I'm trying to write to flash but the return error is not in the acceptable range.

example:

uint32_t Address = 0x0800C000;
uint8_t Data = 0x01;

HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
FLASH_Erase_Sector(FLASH_SECTOR_3, VOLTAGE_RANGE_3); //sector3 0x800C000 0x800CFFF
printf("---%u\n", HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, Data));

if ( HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, Data)==HAL_OK       ) printf("---%u\n", 0);
if ( HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, Data)==HAL_ERROR    ) printf("---%u\n", 1);
if ( HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, Data)==HAL_BUSY     ) printf("---%u\n", 2);
if ( HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, Data)==HAL_TIMEOUT  ) printf("---%u\n", 3);
if ( HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, Data) > 0x03)  printf("---none\n");

HAL_FLASH_Lock();

Pardon the sloppy code but its for testing. I always get a return of > 3. If traced it is 1073888268 but the struct says

typedef enum 
{
  HAL_OK       = 0x00,
  HAL_ERROR    = 0x01,
  HAL_BUSY     = 0x02,
  HAL_TIMEOUT  = 0x03
} HHAL_StatusTypeDef;

How can this be?

0

There are 0 best solutions below