flash/nor: add support for Nuvoton NPCX series flash
[fw/openocd] / src / flash / nor / msp432.h
1 /***************************************************************************
2  *   Copyright (C) 2018 by Texas Instruments, Inc.                         *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
16  ***************************************************************************/
17
18 #ifndef OPENOCD_FLASH_NOR_MSP432_H
19 #define OPENOCD_FLASH_NOR_MSP432_H
20
21 /* MSP432 family types */
22 #define MSP432_NO_FAMILY 0 /* Family type not determined yet */
23 #define MSP432E4         1 /* MSP432E4 family of devices */
24 #define MSP432P4         2 /* MSP432P4 family of devices */
25
26 /* MSP432 device types */
27 #define MSP432_NO_TYPE    0 /* Device type not determined yet */
28 #define MSP432P401X_DEPR  1 /* Early MSP432P401x offerings, now deprecated */
29 #define MSP432P401X       2 /* MSP432P401x device, revision C or higher */
30 #define MSP432P411X       3 /* MSP432P411x device, revision A or higher */
31 #define MSP432P401X_GUESS 4 /* Assuming it's an MSP432P401x device */
32 #define MSP432P411X_GUESS 5 /* Assuming it's an MSP432P411x device */
33 #define MSP432E401Y       6 /* MSP432E401Y device */
34 #define MSP432E411Y       7 /* MSP432E401Y device */
35 #define MSP432E4X_GUESS   8 /* Assuming it's an MSP432E4x device */
36
37 /* Common MSP432 flash parameters */
38 #define FLASH_BASE 0x00000000
39
40 /* MSP432P4 flash parameters */
41 #define P4_FLASH_MAIN_BASE FLASH_BASE
42 #define P4_FLASH_INFO_BASE 0x00200000
43 #define P4_SECTOR_LENGTH   0x1000
44 #define P4_ALGO_ENTRY_ADDR 0x01000110
45
46 /* MSP432E4 flash parameters */
47 #define E4_FLASH_BASE      FLASH_BASE
48 #define E4_FLASH_SIZE      0x100000
49 #define E4_SECTOR_LENGTH   0x4000
50 #define E4_ALGO_ENTRY_ADDR 0x20000110
51
52 /* Flash helper algorithm key addresses */
53 #define ALGO_BASE_ADDR           0x20000000
54 #define ALGO_BUFFER1_ADDR        0x20002000
55 #define ALGO_BUFFER2_ADDR        0x20003000
56 #define ALGO_PARAMS_BASE_ADDR    0x20000150
57 #define ALGO_FLASH_COMMAND_ADDR  0x20000150
58 #define ALGO_RETURN_CODE_ADDR    0x20000154
59 #define ALGO_FLASH_DEST_ADDR     0x2000015c
60 #define ALGO_FLASH_LENGTH_ADDR   0x20000160
61 #define ALGO_BUFFER1_STATUS_ADDR 0x20000164
62 #define ALGO_BUFFER2_STATUS_ADDR 0x20000168
63 #define ALGO_ERASE_PARAM_ADDR    0x2000016c
64 #define ALGO_UNLOCK_BSL_ADDR     0x20000170
65 #define ALGO_STACK_POINTER_ADDR  0x20002000
66
67 /* Flash helper algorithm key sizes */
68 #define ALGO_BUFFER_SIZE  0x1000
69 #define ALGO_WORKING_SIZE (ALGO_BUFFER2_ADDR + 0x1000 - ALGO_BASE_ADDR)
70
71 /* Flash helper algorithm flash commands */
72 #define FLASH_NO_COMMAND    0
73 #define FLASH_MASS_ERASE    1
74 #define FLASH_SECTOR_ERASE  2
75 #define FLASH_PROGRAM       4
76 #define FLASH_INIT          8
77 #define FLASH_EXIT          16
78 #define FLASH_CONTINUOUS    32
79
80 /* Flash helper algorithm return codes */
81 #define FLASH_BUSY          0x00000001
82 #define FLASH_SUCCESS       0x00000ACE
83 #define FLASH_ERROR         0x0000DEAD
84 #define FLASH_TIMEOUT_ERROR 0xDEAD0000
85 #define FLASH_VERIFY_ERROR  0xDEADDEAD
86 #define FLASH_WRONG_COMMAND 0x00000BAD
87 #define FLASH_POWER_ERROR   0x00DEAD00
88
89 /* Flash helper algorithm buffer status values */
90 #define BUFFER_INACTIVE   0x00
91 #define BUFFER_ACTIVE     0x01
92 #define BUFFER_DATA_READY 0x10
93
94 /* Flash helper algorithm erase parameters */
95 #define FLASH_ERASE_MAIN 0x01
96 #define FLASH_ERASE_INFO 0x02
97
98 /* Flash helper algorithm lock/unlock BSL options */
99 #define FLASH_LOCK_BSL   0x00
100 #define FLASH_UNLOCK_BSL 0x0b
101
102 /* Flash helper algorithm parameter block struct */
103 struct msp432_algo_params {
104         uint8_t flash_command[4];
105         uint8_t return_code[4];
106         uint8_t _reserved0[4];
107         uint8_t address[4];
108         uint8_t length[4];
109         uint8_t buffer1_status[4];
110         uint8_t buffer2_status[4];
111         uint8_t erase_param[4];
112         uint8_t unlock_bsl[4];
113 };
114
115 /* Flash helper algorithm for MSP432P401x targets */
116 const uint8_t msp432p401x_algo[] = {
117 #include "../../../contrib/loaders/flash/msp432/msp432p401x_algo.inc"
118 };
119
120 /* Flash helper algorithm for MSP432P411x targets */
121 const uint8_t msp432p411x_algo[] = {
122 #include "../../../contrib/loaders/flash/msp432/msp432p411x_algo.inc"
123 };
124
125 /* Flash helper algorithm for MSP432E4x targets */
126 const uint8_t msp432e4x_algo[] = {
127 #include "../../../contrib/loaders/flash/msp432/msp432e4x_algo.inc"
128 };
129
130 #endif /* OPENOCD_FLASH_NOR_MSP432_H */