cancel
Showing results for 
Search instead for 
Did you mean: 

L4 Flash erase issue

EFrie.3
Associate II

MCU is STM32L4R9 with 1MB. I'm having trouble getting the device to erase the upper half of the flash programmatically. Apparently the device ships with opt bytes set for dual bank.

I connected the device to the STM32 programmer through USB and turned off the DBANK option byte, which changed programming somewhat and appears to program 0x2000 sized pages now. However it still doesn't appear to erase correctly, in this case it for sure won't erase page 127 or 0x080FE000.

What puzzles me is that the programmer shows DBANK off, but the debugger still shows the OPTR DBANK bit set. Also, the note says on page 160 of datasheet rm0432-stm32l4..

Note: For 1-Mbyte and 512-Kbyte Flash memory devices, do not care about
DBANK.

However this isn't really true, as this bit does apparently do something.

6 REPLIES 6

The device always has two physical banks.

The Erase takes a sector and a bank​ coordinate.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
EFrie.3
Associate II

Hmm. I'm missing something. Even in dbank = 1 I can't erase upper half pages. In the snippet, I would assume that Page of 0 should erase first sector at 0x8080000, but it doesn't.

SET_BIT(FLASH->CR, FLASH_CR_BKER);
  MODIFY_REG(FLASH->CR, FLASH_CR_PNB, ((Page & 0xFFU) << FLASH_CR_PNB_Pos));
  SET_BIT(FLASH->CR, FLASH_CR_PER);
  SET_BIT(FLASH->CR, FLASH_CR_STRT);

EFrie.3
Associate II

Actually, it appears that the first and last pages of bank 2 aren't writing or erasing.

EFrie.3
Associate II

Actually its looking like Jlink isn't refreshing flash memory display.

_EFrie
Associate III

Coming back around to this, these smaller devices have an oddity in that the OPTR bank is always set, the memory map contains the whole thing, yet to program you have to set FLASH_CR BKER for anything in the upper half.  So 128 for 1M and 64 for 512K

 

  if (Page < 64) {
    CLEAR_BIT(FLASH->CR, FLASH_CR_BKER);
  } else {
    Page -= 64;
    SET_BIT(FLASH->CR, FLASH_CR_BKER);
  }
_EFrie
Associate III

I'm EFrie.3, it took some months to get back my login lost for unknown causes due to some ST forum bug.