1 /***************************************************************************
2 * Copyright (C) 2015 by Uwe Bonnes *
3 * bon@elektron.ikp.physik.tu-darmstadt.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 ***************************************************************************/
19 #ifndef OPENOCD_FLASH_NOR_STM32L4X
20 #define OPENOCD_FLASH_NOR_STM32L4X
22 /* FLASH_CR register bits */
23 #define FLASH_PG (1 << 0)
24 #define FLASH_PER (1 << 1)
25 #define FLASH_MER1 (1 << 2)
26 #define FLASH_PAGE_SHIFT 3
27 #define FLASH_BKER (1 << 11)
28 #define FLASH_BKER_G0 (1 << 13)
29 #define FLASH_MER2 (1 << 15)
30 #define FLASH_STRT (1 << 16)
31 #define FLASH_OPTSTRT (1 << 17)
32 #define FLASH_EOPIE (1 << 24)
33 #define FLASH_ERRIE (1 << 25)
34 #define FLASH_OBL_LAUNCH (1 << 27)
35 #define FLASH_OPTLOCK (1 << 30)
36 #define FLASH_LOCK (1 << 31)
38 /* FLASH_SR register bits */
39 #define FLASH_BSY (1 << 16)
40 #define FLASH_BSY2 (1 << 17)
42 /* Fast programming not used => related errors not used*/
43 #define FLASH_PGSERR (1 << 7) /* Programming sequence error */
44 #define FLASH_SIZERR (1 << 6) /* Size error */
45 #define FLASH_PGAERR (1 << 5) /* Programming alignment error */
46 #define FLASH_WRPERR (1 << 4) /* Write protection error */
47 #define FLASH_PROGERR (1 << 3) /* Programming error */
48 #define FLASH_OPERR (1 << 1) /* Operation error */
49 #define FLASH_EOP (1 << 0) /* End of operation */
50 #define FLASH_ERROR (FLASH_PGSERR | FLASH_SIZERR | FLASH_PGAERR | \
51 FLASH_WRPERR | FLASH_PROGERR | FLASH_OPERR)
53 /* register unlock keys */
54 #define KEY1 0x45670123
55 #define KEY2 0xCDEF89AB
57 /* option register unlock key */
58 #define OPTKEY1 0x08192A3B
59 #define OPTKEY2 0x4C5D6E7F
61 /* FLASH_OPTR register bits */
62 #define FLASH_RDP_MASK 0xFF
63 #define FLASH_TZEN (1 << 31)
65 /* FLASH secure block based bank 1/2 register offsets */
66 #define FLASH_SECBB1(X) (0x80 + 4 * (X - 1))
67 #define FLASH_SECBB2(X) (0xA0 + 4 * (X - 1))
69 #define FLASH_SECBB_SECURE 0xFFFFFFFF
70 #define FLASH_SECBB_NON_SECURE 0
73 #define DBGMCU_IDCODE_G0 0x40015800
74 #define DBGMCU_IDCODE_L4_G4 0xE0042000
75 #define DBGMCU_IDCODE_L5 0xE0044000
77 #define STM32_FLASH_BANK_BASE 0x08000000
78 #define STM32_FLASH_S_BANK_BASE 0x0C000000
80 #define STM32L5_REGS_SEC_OFFSET 0x10000000