c438097efcb84e0b33088ab2a9afedeec11e77f1
[fw/openocd] / contrib / loaders / flash / msp432 / MSP432P4_FlashLibIf.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2014-2018 Texas Instruments Incorporated - http://www.ti.com/
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 *  Redistributions of source code must retain the above copyright
10 *  notice, this list of conditions and the following disclaimer.
11 *
12 *  Redistributions in binary form must reproduce the above copyright
13 *  notice, this list of conditions and the following disclaimer in the
14 *  documentation and/or other materials provided with the
15 *  distribution.
16 *
17 *  Neither the name of Texas Instruments Incorporated nor the names of
18 *  its contributors may be used to endorse or promote products derived
19 *  from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 ******************************************************************************/
34
35 #ifndef OPENOCD_LOADERS_FLASH_MSP432_MSP432P4_FLASHLIBIF_H
36 #define OPENOCD_LOADERS_FLASH_MSP432_MSP432P4_FLASHLIBIF_H
37
38 #include <stddef.h>
39 #include <stdint.h>
40
41 /* RAM loader */
42 static const uint32_t RAM_LOADER_START   = 0x01000000u; /* Code space */
43 static const uint32_t RAM_LOADER_MAIN    = 0x01000110u; /* Code space */
44 static const uint32_t RAM_LOADER_BUFFER1 = 0x20002000u; /* SBUS data space */
45 static const uint32_t RAM_LOADER_BUFFER2 = 0x20003000u; /* SBUS data space */
46 static const uint32_t RAM_LOADER_STACK   = 0x20002000u; /* SBUS data space */
47
48 /* Address for flash function to be executed */
49 static const uint32_t FLASH_FUNCTION_ADDRESS = 0x20000150u;
50
51 enum flash_command {
52         FLASH_NO_COMMAND = 0,
53         FLASH_MASS_ERASE = 1,
54         FLASH_SECTOR_ERASE = 2,
55         FLASH_PROGRAM = 4,
56         FLASH_INIT = 8,
57         FLASH_EXIT = 16,
58         FLASH_CONTINUOUS_PROGRAM = 32
59 };
60
61 /* Address for algorithm program and flash buffer */
62 static const uint32_t DST_ADDRESS             = 0x2000015Cu;
63 static const uint32_t SRC_LENGTH_ADDRESS      = 0x20000160u;
64 static const uint32_t BUFFER1_STATUS_REGISTER = 0x20000164u;
65 static const uint32_t BUFFER2_STATUS_REGISTER = 0x20000168u;
66 static const uint32_t BUFFER_INACTIVE         = 0x00000000u;
67 static const uint32_t BUFFER_ACTIVE           = 0x00000001u;
68 static const uint32_t BUFFER_DATA_READY       = 0x00000010u;
69 static const size_t   SRC_LENGTH_MAX          = 4096u;
70
71 /* erase options */
72 static const uint32_t ERASE_PARAM_ADDRESS = 0x2000016Cu;
73 static const uint32_t ERASE_MAIN          = 0x00000001u;
74 static const uint32_t ERASE_INFO          = 0x00000002u;
75
76 /* Unlock BSL */
77 static const uint32_t UNLOCK_BSL_ADDRESS  = 0x20000170u;
78 static const uint32_t LOCK_BSL_KEY        = 0x00000000u;
79 static const uint32_t UNLOCK_BSL_KEY      = 0x0000000Bu;
80
81 /* Address for return code */
82 static const uint32_t RETURN_CODE_ADDRESS = 0x20000154u;
83
84 /* Return codes */
85 static const uint32_t FLASH_BUSY          = 0x00000001u;
86 static const uint32_t FLASH_SUCCESS       = 0x00000ACEu;
87 static const uint32_t FLASH_ERROR         = 0x0000DEADu;
88 static const uint32_t FLASH_TIMEOUT_ERROR = 0xDEAD0000u;
89 static const uint32_t FLASH_VERIFY_ERROR  = 0xDEADDEADu;
90 static const uint32_t FLASH_WRONG_COMMAND = 0x00000BADu;
91 static const uint32_t FLASH_POWER_ERROR   = 0x00DEAD00u;
92
93 /* Device ID address */
94 static const uint32_t DEVICE_ID_ADDRESS = 0x0020100Cu;
95 static const uint32_t PC_REGISTER       = 15u;
96 static const uint32_t SP_REGISTER       = 13u;
97
98 /* CS silicon and boot code revisions */
99 static const uint32_t SILICON_REV_ADDRESS = 0x00201010u;
100 static const uint32_t SILICON_REV_A       = 0x00000041u;
101 static const uint32_t SILICON_REV_B       = 0x00000042u;
102 static const uint32_t SILICON_REV_C       = 0x00000043u;
103 static const uint32_t SILICON_REV_D       = 0x00000044u;
104 static const uint32_t SILICON_REV_E       = 0x00000045u;
105 static const uint32_t SILICON_REV_F       = 0x00000046u;
106 static const uint32_t SILICON_REV_G       = 0x00000047u;
107 static const uint32_t SILICON_REV_H       = 0x00000048u;
108 static const uint32_t SILICON_REV_I       = 0x00000049u;
109 static const uint32_t SILICON_REV_B_WRONG = 0x00004100u;
110
111 struct flash_interface {
112         volatile uint32_t FLASH_FUNCTION;
113         volatile uint32_t RETURN_CODE;
114         volatile uint32_t _RESERVED0;
115         volatile uint32_t DST_ADDRESS;
116         volatile uint32_t SRC_LENGTH;
117         volatile uint32_t BUFFER1_STATUS_REGISTER;
118         volatile uint32_t BUFFER2_STATUS_REGISTER;
119         volatile uint32_t ERASE_PARAM;
120         volatile uint32_t UNLOCK_BSL;
121 };
122
123 #define FLASH_LOADER_BASE ((uint32_t)0x20000150u)
124 #define FLASH_LOADER      ((struct flash_interface *) FLASH_LOADER_BASE)
125
126 #endif /* OPENOCD_LOADERS_FLASH_MSP432_MSP432P4_FLASHLIBIF_H */