flash.h
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
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 distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #ifndef __FLASH_H__
33 #define __FLASH_H__
34 
35 #include <stdbool.h>
36 #include <ti/devices/msp432p4xx/inc/msp.h>
37 
38 /* Define to ensure that our current MSP432 has the FLCTL module. This
39  definition is included in the device specific header file */
40 #ifdef __MCU_HAS_FLCTL__
41 
42 //*****************************************************************************
43 //
46 //
47 //*****************************************************************************
48 
49 //*****************************************************************************
50 //
51 // If building with a C++ compiler, make all of the definitions in this header
52 // have a C binding.
53 //
54 //*****************************************************************************
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59 
60 //*****************************************************************************
61 //
62 // Control specific variables
63 //
64 //*****************************************************************************
65 #define FLASH_BURST_PRG_BIT 0x03
66 
67 /* Interrupts */
68 #define FLASH_PROGRAM_ERROR FLCTL_IFG_PRG_ERR
69 #define FLASH_BENCHMARK_INT FLCTL_IFG_BMRK
70 #define FLASH_ERASE_COMPLETE FLCTL_IFG_ERASE
71 #define FLASH_BRSTPRGM_COMPLETE FLCTL_IFG_PRGB
72 #define FLASH_WRDPRGM_COMPLETE FLCTL_IFG_PRG
73 #define FLASH_POSTVERIFY_FAILED FLCTL_IFG_AVPST
74 #define FLASH_PREVERIFY_FAILED FLCTL_IFG_AVPRE
75 #define FLASH_BRSTRDCMP_COMPLETE FLCTL_IFG_RDBRST
76 
77 #define FLASH_NORMAL_READ_MODE FLCTL_BANK0_RDCTL_RD_MODE_0
78 #define FLASH_MARGIN0_READ_MODE FLCTL_BANK0_RDCTL_RD_MODE_1
79 #define FLASH_MARGIN1_READ_MODE FLCTL_BANK0_RDCTL_RD_MODE_2
80 #define FLASH_PROGRAM_VERIFY_READ_MODE FLCTL_BANK0_RDCTL_RD_MODE_3
81 #define FLASH_ERASE_VERIFY_READ_MODE FLCTL_BANK0_RDCTL_RD_MODE_4
82 #define FLASH_LEAKAGE_VERIFY_READ_MODE FLCTL_BANK0_RDCTL_RD_MODE_5
83 #define FLASH_MARGIN0B_READ_MODE FLCTL_BANK0_RDCTL_RD_MODE_9
84 #define FLASH_MARGIN1B_READ_MODE FLCTL_BANK0_RDCTL_RD_MODE_10
85 
86 #define FLASH_PRGBRSTCTLSTAT_BURSTSTATUS_COMPLETE FLCTL_PRGBRST_CTLSTAT_BURST_STATUS_7
87 
88 #define FLASH_BANK0 0x00
89 #define FLASH_BANK1 0x01
90 #define FLASH_DATA_READ 0x00
91 #define FLASH_INSTRUCTION_FETCH 0x01
92 
93 #define FLASH_MAIN_MEMORY_SPACE_BANK0 0x01
94 #define FLASH_MAIN_MEMORY_SPACE_BANK1 0x02
95 #define FLASH_INFO_MEMORY_SPACE_BANK0 0x03
96 #define FLASH_INFO_MEMORY_SPACE_BANK1 0x04
97 
98 #define FLASH_MAIN_SPACE FLCTL_RDBRST_CTLSTAT_MEM_TYPE_0
99 #define FLASH_INFO_SPACE FLCTL_RDBRST_CTLSTAT_MEM_TYPE_1
100 #define FLASH_1_PATTERN FLCTL_RDBRST_CTLSTAT_DATA_CMP
101 #define FLASH_0_PATTERN 0x00
102 
103 #define FLASH_SECTOR0 FLCTL_BANK0_MAIN_WEPROT_PROT0
104 #define FLASH_SECTOR1 FLCTL_BANK0_MAIN_WEPROT_PROT1
105 #define FLASH_SECTOR2 FLCTL_BANK0_MAIN_WEPROT_PROT2
106 #define FLASH_SECTOR3 FLCTL_BANK0_MAIN_WEPROT_PROT3
107 #define FLASH_SECTOR4 FLCTL_BANK0_MAIN_WEPROT_PROT4
108 #define FLASH_SECTOR5 FLCTL_BANK0_MAIN_WEPROT_PROT5
109 #define FLASH_SECTOR6 FLCTL_BANK0_MAIN_WEPROT_PROT6
110 #define FLASH_SECTOR7 FLCTL_BANK0_MAIN_WEPROT_PROT7
111 #define FLASH_SECTOR8 FLCTL_BANK0_MAIN_WEPROT_PROT8
112 #define FLASH_SECTOR9 FLCTL_BANK0_MAIN_WEPROT_PROT9
113 #define FLASH_SECTOR10 FLCTL_BANK0_MAIN_WEPROT_PROT10
114 #define FLASH_SECTOR11 FLCTL_BANK0_MAIN_WEPROT_PROT11
115 #define FLASH_SECTOR12 FLCTL_BANK0_MAIN_WEPROT_PROT12
116 #define FLASH_SECTOR13 FLCTL_BANK0_MAIN_WEPROT_PROT13
117 #define FLASH_SECTOR14 FLCTL_BANK0_MAIN_WEPROT_PROT14
118 #define FLASH_SECTOR15 FLCTL_BANK0_MAIN_WEPROT_PROT15
119 #define FLASH_SECTOR16 FLCTL_BANK0_MAIN_WEPROT_PROT16
120 #define FLASH_SECTOR17 FLCTL_BANK0_MAIN_WEPROT_PROT17
121 #define FLASH_SECTOR18 FLCTL_BANK0_MAIN_WEPROT_PROT18
122 #define FLASH_SECTOR19 FLCTL_BANK0_MAIN_WEPROT_PROT19
123 #define FLASH_SECTOR20 FLCTL_BANK0_MAIN_WEPROT_PROT20
124 #define FLASH_SECTOR21 FLCTL_BANK0_MAIN_WEPROT_PROT21
125 #define FLASH_SECTOR22 FLCTL_BANK0_MAIN_WEPROT_PROT22
126 #define FLASH_SECTOR23 FLCTL_BANK0_MAIN_WEPROT_PROT23
127 #define FLASH_SECTOR24 FLCTL_BANK0_MAIN_WEPROT_PROT24
128 #define FLASH_SECTOR25 FLCTL_BANK0_MAIN_WEPROT_PROT25
129 #define FLASH_SECTOR26 FLCTL_BANK0_MAIN_WEPROT_PROT26
130 #define FLASH_SECTOR27 FLCTL_BANK0_MAIN_WEPROT_PROT27
131 #define FLASH_SECTOR28 FLCTL_BANK0_MAIN_WEPROT_PROT28
132 #define FLASH_SECTOR29 FLCTL_BANK0_MAIN_WEPROT_PROT29
133 #define FLASH_SECTOR30 FLCTL_BANK0_MAIN_WEPROT_PROT30
134 #define FLASH_SECTOR31 FLCTL_BANK0_MAIN_WEPROT_PROT31
135 
136 #define FLASH_NOVER 0
137 #define FLASH_BURSTPOST FLCTL_PRGBRST_CTLSTAT_AUTO_PST
138 #define FLASH_BURSTPRE FLCTL_PRGBRST_CTLSTAT_AUTO_PRE
139 #define FLASH_REGPRE FLCTL_PRG_CTLSTAT_VER_PRE
140 #define FLASH_REGPOST FLCTL_PRG_CTLSTAT_VER_PST
141 #define FLASH_FULLVER (FLCTL_PRGBRST_CTLSTAT_AUTO_PST | \
142  FLCTL_PRGBRST_CTLSTAT_AUTO_PRE | FLCTL_PRG_CTLSTAT_VER_PRE \
143  | FLCTL_PRG_CTLSTAT_VER_PST)
144 
145 #define FLASH_COLLATED_WRITE_MODE 0x01
146 #define FLASH_IMMEDIATE_WRITE_MODE 0x02
147 
148 #define __INFO_FLASH_TECH_START__ 0x00200000
149 #define __INFO_FLASH_TECH_MIDDLE__ 0x00202000
150 
151 
152 //*****************************************************************************
153 //
154 // Prototypes for the APIs.
155 //
156 //*****************************************************************************
157 
158 //*****************************************************************************
159 //
178 //
179 //*****************************************************************************
180 extern void FlashCtl_getMemoryInfo(uint32_t addr, uint32_t *bankNum,
181  uint32_t *sectorNum);
182 
183 //*****************************************************************************
184 //
198 //
199 //*****************************************************************************
200 extern void FlashCtl_enableReadBuffering(uint_fast8_t memoryBank,
201  uint_fast8_t accessMethod);
202 
203 //*****************************************************************************
204 //
218 //
219 //*****************************************************************************
220 extern void FlashCtl_disableReadBuffering(uint_fast8_t memoryBank,
221  uint_fast8_t accessMethod);
222 
223 //*****************************************************************************
224 //
280 //
281 //*****************************************************************************
282 extern bool FlashCtl_unprotectSector(uint_fast8_t memorySpace,
283  uint32_t sectorMask);
284 
285 //*****************************************************************************
286 //
342 //
343 //*****************************************************************************
344 extern bool FlashCtl_protectSector(uint_fast8_t memorySpace,
345  uint32_t sectorMask);
346 
347 //*****************************************************************************
348 //
403 //
404 //*****************************************************************************
405 extern bool FlashCtl_isSectorProtected(uint_fast8_t memorySpace,
406  uint32_t sector);
407 
408 //*****************************************************************************
409 //
443 //
444 //*****************************************************************************
445 extern bool FlashCtl_verifyMemory(void* verifyAddr, uint32_t length,
446  uint_fast8_t pattern);
447 
448 //*****************************************************************************
449 //
469 //
470 //*****************************************************************************
471 extern bool FlashCtl_performMassErase(void);
472 
473 //*****************************************************************************
474 //
481 //
482 //*****************************************************************************
483 extern void FlashCtl_initiateMassErase(void);
484 
485 //*****************************************************************************
486 //
511 //
512 //*****************************************************************************
513 extern bool FlashCtl_eraseSector(uint32_t addr);
514 
515 //*****************************************************************************
516 //
546 //
547 //*****************************************************************************
548 extern bool FlashCtl_programMemory(void* src, void* dest, uint32_t length);
549 
550 //*****************************************************************************
551 //
567 //
568 //*****************************************************************************
569 extern void FlashCtl_setProgramVerification(uint32_t verificationSetting);
570 
571 //*****************************************************************************
572 //
588 //
589 //*****************************************************************************
590 extern void FlashCtl_clearProgramVerification(uint32_t verificationSetting);
591 
592 //*****************************************************************************
593 //
611 //
612 //*****************************************************************************
613 extern void FlashCtl_enableWordProgramming(uint32_t mode);
614 
615 //*****************************************************************************
616 //
623 //
624 //*****************************************************************************
625 extern void FlashCtl_disableWordProgramming(void);
626 
627 //*****************************************************************************
628 //
638 //
639 //*****************************************************************************
640 extern uint32_t FlashCtl_isWordProgrammingEnabled(void);
641 
642 //*****************************************************************************
643 //
663 //
664 //*****************************************************************************
665 extern bool FlashCtl_setReadMode(uint32_t flashBank, uint32_t readMode);
666 
667 //*****************************************************************************
668 //
685 //
686 //*****************************************************************************
687 extern uint32_t FlashCtl_getReadMode(uint32_t flashBank);
688 
689 //*****************************************************************************
690 //
702 //
703 //*****************************************************************************
704 extern void FlashCtl_setWaitState(uint32_t bank, uint32_t waitState);
705 
706 //*****************************************************************************
707 //
715 //
716 //*****************************************************************************
717 extern uint32_t FlashCtl_getWaitState(uint32_t bank);
718 
719 //*****************************************************************************
720 //
743 //
744 //*****************************************************************************
745 extern void FlashCtl_enableInterrupt(uint32_t flags);
746 
747 //*****************************************************************************
748 //
768 //
769 //*****************************************************************************
770 extern void FlashCtl_disableInterrupt(uint32_t flags);
771 
772 //*****************************************************************************
773 //
792 //
793 //*****************************************************************************
794 extern uint32_t FlashCtl_getEnabledInterruptStatus(void);
795 
796 //*****************************************************************************
797 //
813 //
814 //*****************************************************************************
815 extern uint32_t FlashCtl_getInterruptStatus(void);
816 
817 //*****************************************************************************
818 //
850 //
851 //*****************************************************************************
852 extern void FlashCtl_clearInterruptFlag(uint32_t flags);
853 
854 //*****************************************************************************
855 //
872 //
873 //*****************************************************************************
874 extern void FlashCtl_registerInterrupt(void (*intHandler)(void));
875 
876 //*****************************************************************************
877 //
888 //
889 //*****************************************************************************
890 extern void FlashCtl_unregisterInterrupt(void);
891 
892 
893 //*****************************************************************************
894 //
909 //
910 //*****************************************************************************
911 extern void FlashCtl_initiateSectorErase(uint32_t addr);
912 
913 
914 /* The following functions are advanced functions that are used by the flash
915  * driver to remask a failed bit in the event of a post or pre verification
916  * failure. They are meant to be advanced functions and should not be used
917  * by the majority of users (unless you are writing your own flash driver).
918  */
919 extern uint8_t __FlashCtl_remaskData8Post(uint8_t data, uint32_t addr);
920 extern uint8_t __FlashCtl_remaskData8Pre(uint8_t data, uint32_t addr);
921 extern uint32_t __FlashCtl_remaskData32Post(uint32_t data, uint32_t addr);
922 extern uint32_t __FlashCtl_remaskData32Pre(uint32_t data, uint32_t addr);
923 extern void __FlashCtl_remaskBurstDataPost(uint32_t addr, uint32_t size);
924 extern void __FlashCtl_remaskBurstDataPre(uint32_t addr, uint32_t size);
925 
926 //*****************************************************************************
927 //
928 // Mark the end of the C bindings section for C++ compilers.
929 //
930 //*****************************************************************************
931 #ifdef __cplusplus
932 }
933 #endif
934 
935 //*****************************************************************************
936 //
937 // Close the Doxygen group.
939 //
940 //*****************************************************************************
941 
942 #endif /* __MCU_HAS_FLCTL__ */
943 
944 #endif // __FLASH_H__
uint32_t FlashCtl_getInterruptStatus(void)
Definition: flash.c:1227
uint32_t FlashCtl_getReadMode(uint32_t flashBank)
Definition: flash.c:740
bool FlashCtl_performMassErase(void)
Definition: flash.c:765
bool FlashCtl_setReadMode(uint32_t flashBank, uint32_t readMode)
Definition: flash.c:711
void FlashCtl_setProgramVerification(uint32_t verificationSetting)
Definition: flash.c:1121
uint32_t FlashCtl_isWordProgrammingEnabled(void)
Definition: flash.c:1175
void FlashCtl_enableWordProgramming(uint32_t mode)
Definition: flash.c:1156
uint32_t FlashCtl_getWaitState(uint32_t bank)
Definition: flash.c:1202
void FlashCtl_registerInterrupt(void(*intHandler)(void))
Definition: flash.c:1242
void FlashCtl_enableReadBuffering(uint_fast8_t memoryBank, uint_fast8_t accessMethod)
Definition: flash.c:420
void FlashCtl_getMemoryInfo(uint32_t addr, uint32_t *bankNum, uint32_t *sectorNum)
Definition: flash.c:138
void FlashCtl_initiateSectorErase(uint32_t addr)
Definition: flash.c:963
uint32_t FlashCtl_getEnabledInterruptStatus(void)
Definition: flash.c:1232
void FlashCtl_enableInterrupt(uint32_t flags)
Definition: flash.c:1217
bool FlashCtl_verifyMemory(void *verifyAddr, uint32_t length, uint_fast8_t pattern)
Definition: flash.c:527
void FlashCtl_unregisterInterrupt(void)
Definition: flash.c:1255
void FlashCtl_clearProgramVerification(uint32_t verificationSetting)
Definition: flash.c:1138
bool FlashCtl_programMemory(void *src, void *dest, uint32_t length)
Definition: flash.c:1003
bool FlashCtl_unprotectSector(uint_fast8_t memorySpace, uint32_t sectorMask)
Definition: flash.c:454
void FlashCtl_initiateMassErase(void)
Definition: flash.c:755
uint32_t __FlashCtl_remaskData32Pre(uint32_t data, uint32_t addr)
Definition: flash.c:1390
bool FlashCtl_protectSector(uint_fast8_t memorySpace, uint32_t sectorMask)
Definition: flash.c:481
void FlashCtl_clearInterruptFlag(uint32_t flags)
Definition: flash.c:1237
bool FlashCtl_isSectorProtected(uint_fast8_t memorySpace, uint32_t sector)
Definition: flash.c:508
void FlashCtl_setWaitState(uint32_t bank, uint32_t waitState)
Definition: flash.c:1186
uint32_t __FlashCtl_remaskData32Post(uint32_t data, uint32_t addr)
Definition: flash.c:1342
void __FlashCtl_remaskBurstDataPost(uint32_t addr, uint32_t size)
Definition: flash.c:1503
bool FlashCtl_eraseSector(uint32_t addr)
Definition: flash.c:862
void __FlashCtl_remaskBurstDataPre(uint32_t addr, uint32_t size)
Definition: flash.c:1438
uint8_t __FlashCtl_remaskData8Pre(uint8_t data, uint32_t addr)
Definition: flash.c:1305
void FlashCtl_disableInterrupt(uint32_t flags)
Definition: flash.c:1222
uint8_t __FlashCtl_remaskData8Post(uint8_t data, uint32_t addr)
Definition: flash.c:1268
void FlashCtl_disableWordProgramming(void)
Definition: flash.c:1170
void FlashCtl_disableReadBuffering(uint_fast8_t memoryBank, uint_fast8_t accessMethod)
Definition: flash.c:437

Copyright 2018, Texas Instruments Incorporated