Skip to main content
Clonimus74
Senior II
July 4, 2018
Question

Error programming bank 1

  • July 4, 2018
  • 2 replies
  • 600 views
Posted on July 04, 2018 at 13:03

Hi,

Using STM32L476QE

I get HAL_ERROR running the following code only when writing or erasing (page) at address 0x0803F800, doing the same with address 0x08040000 works fine.

both addresses are erased before the code executes.

my application runs from bank 1 (

0x0803F800 is the last page at bank 1)

there is no code at 0x0803F800 address.

ideas?

static FLASH_EraseInitTypeDef erase_init;

static uint32_t page_error;

volatile static uint8_t status = 0;

volatile HAL_StatusTypeDef result;

HAL_FLASH_Unlock();

__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);

__disable_interrupt(); 

// I tried with and without this line

//All the following fails

result = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, 0x0803F800, 0x1234567890124356);

if (result == HAL_OK)

if (*(uint64_t *)0x0803F800 == 0x1234567890124356)

status = 1;

else

status = 0;

erase_init.TypeErase = FLASH_TYPEERASE_PAGES;

erase_init.Banks = GetBank(0x0803F800); //should be 1

erase_init.Page = GetPage(0x0803F800); //should be 127

erase_init.NbPages = 1;

if (HAL_FLASHEx_Erase(&erase_init, &page_error) != HAL_OK)

status = 0;

else

status = 1;

//All the following works

__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);

if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, 0x08040000,

0x1234567890124356) == HAL_OK)

if (*(uint64_t *)0x08040000 == 0x1234567890124356)

status = 1;

else

status = 0;

erase_init.TypeErase = FLASH_TYPEERASE_PAGES;

erase_init.Banks = GetBank(0x08040000); //should be 2

erase_init.Page = GetPage(0x08040000); //should be 256

erase_init.NbPages = 1;

if (HAL_FLASHEx_Erase(&erase_init, &page_error) != HAL_OK)

status = 0;

else

status = 1;

HAL_FLASH_Lock();

while(1);

#page-erase #flash-programming #stm32l4
This topic has been closed for replies.

2 replies

Tesla DeLorean
Guru
August 10, 2018

Sorry, bumping old zombie unanswered threads off my feed

Do long constants require L suffix.

Seems like a group of related threads that could probably be merged

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Clonimus74
Senior II
August 12, 2018

I'm not sure, but writing long as it is in the code to 0x08040000 works