@
@ Mecrisp-Stellaris - A native code Forth implementation for ARM-Cortex M microcontrollers
@ Copyright (C) 2013 Matthias Koch
@
@ This program is free software: you can redistribute it and/or modify
@ it under the terms of the GNU General Public License as published by
@ the Free Software Foundation, either version 3 of the License, or
@ (at your option) any later version.
@
@ This program is distributed in the hope that it will be useful,
@ but WITHOUT ANY WARRANTY; without even the implied warranty of
@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ GNU General Public License for more details.
@
@ You should have received a copy of the GNU General Public License
@ along with this program. If not, see .
@
@ Schreiben und Löschen des Flash-Speichers im STM32wb55.
@ this chip has ecc flash memory protection and supports 64 bit writes
@ as 2 consecutive word accesses to one 64 bit area only
@ Write and Erase Flash in STM32wb55.
@ Porting: Rewrite this ! You need hflash! and - as far as possible - cflash!
@ for stm32wb55 we will never introduce 8 byte mode
hexflashstore_fehler:
Fehler_Quit "Flash cannot be written twice"
@ -----------------------------------------------------------------------------
Wortbirne Flag_visible, "16flash!" @ Writes 16 Bytes at once into Flash.
hexflashstore: @ ( x1 x2 x3 x4 addr -- ) x1 contains LSB of those 128 bits.
@ -----------------------------------------------------------------------------
push {r0, r1, r2, r3, r4, r5, lr}
@ Check if this goes into core - don't allow that ! No need to check for because of the second check.
@ Perform write only if desired destination is in erased state...
ldr r0, =15
ands r0, tos
beq 1f
Fehler_Quit "16flash! needs 16-aligned address"
1: ldr r0, [tos] @ tos contains address to write
adds r0, r0, #1 @ quick check if memory contains $ffffffff
bne hexflashstore_fehler
ldr r0, [tos, #4] @ check next 4 bytes at offset 4
adds r0, r0, #1
bne hexflashstore_fehler
ldr r0, [tos, #8] @ check empty at offset 8 - for stm32wb55
adds r0, r0, #1
bne hexflashstore_fehler
ldr r0, [tos, #12]
adds r0, r0, #1
bne hexflashstore_fehler
@ Okay, alle Proben bestanden.
@ Im STM32wb55 ist der Flash-Speicher gespiegelt, die wirkliche Adresse liegt weiter hinten !
@ Flash memory is mirrored, use true address later for write
@ ldr r2, =0x08000000
@ adds tos, r2
@ Bereit zum Schreiben !
@ Unlock Flash Control
ldr r2, =Flash_KEYR
ldr r3, =0x45670123
str r3, [r2]
ldr r3, =0xCDEF89AB
str r3, [r2]
@ erase previous errors
ldr r2, =Flash_SR
ldr r3, =1< 256 pages, 8 bits
@ page size 4096 byte, 12 bits
@ Set page to erase
ldr r1, =12 @ page size 12 bits
lsrs r0, r0, r1 @ shift down page size
ldr r1, =0xFF @ bitWidth 8
ands r0, r0, r1 @ mask page number
ldr r1, =Flash_PNB_Shift
lsls r0, r0, r1 @ Page number selection
ldr r1, =1<