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_A_H__ 33 #define __FLASH_A_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_A module. This 39 definition is included in the device specific header file */ 40 #ifdef __MCU_HAS_FLCTL_A__ 41 42 //***************************************************************************** 43 // 44 //! \addtogroup flash_a_api 45 //! @{ 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_A_BURST_PRG_BIT 0x03 66 #define FLASH_A_SECTOR_SIZE 4096 67 68 /* Interrupts */ 69 #define FLASH_A_PROGRAM_ERROR FLCTL_A_IFG_PRG_ERR 70 #define FLASH_A_BENCHMARK_INT FLCTL_A_IFG_BMRK 71 #define FLASH_A_ERASE_COMPLETE FLCTL_A_IFG_ERASE 72 #define FLASH_A_BRSTPRGM_COMPLETE FLCTL_A_IFG_PRGB 73 #define FLASH_A_WRDPRGM_COMPLETE FLCTL_A_IFG_PRG 74 #define FLASH_A_POSTVERIFY_FAILED FLCTL_A_IFG_AVPST 75 #define FLASH_A_PREVERIFY_FAILED FLCTL_A_IFG_AVPRE 76 #define FLASH_A_BRSTRDCMP_COMPLETE FLCTL_A_IFG_RDBRST 77 78 #define FLASH_A_NORMAL_READ_MODE FLCTL_A_BANK0_RDCTL_RD_MODE_0 79 #define FLASH_A_MARGIN0_READ_MODE FLCTL_A_BANK0_RDCTL_RD_MODE_1 80 #define FLASH_A_MARGIN1_READ_MODE FLCTL_A_BANK0_RDCTL_RD_MODE_2 81 #define FLASH_A_PROGRAM_VERIFY_READ_MODE FLCTL_A_BANK0_RDCTL_RD_MODE_3 82 #define FLASH_A_ERASE_VERIFY_READ_MODE FLCTL_A_BANK0_RDCTL_RD_MODE_4 83 #define FLASH_A_LEAKAGE_VERIFY_READ_MODE FLCTL_A_BANK0_RDCTL_RD_MODE_5 84 #define FLASH_A_MARGIN0B_READ_MODE FLCTL_A_BANK0_RDCTL_RD_MODE_9 85 #define FLASH_A_MARGIN1B_READ_MODE FLCTL_A_BANK0_RDCTL_RD_MODE_10 86 87 #define FLASH_A_PRGBRSTCTLSTAT_BURSTSTATUS_COMPLETE FLCTL_A_PRGBRST_CTLSTAT_BURST_STATUS_7 88 89 #define FLASH_A_BANK0 0x00 90 #define FLASH_A_BANK1 0x01 91 #define FLASH_A_DATA_READ 0x00 92 #define FLASH_A_INSTRUCTION_FETCH 0x01 93 94 #define FLASH_A_MAIN_MEMORY_SPACE_BANK0 0x01 95 #define FLASH_A_MAIN_MEMORY_SPACE_BANK1 0x02 96 #define FLASH_A_INFO_MEMORY_SPACE_BANK0 0x03 97 #define FLASH_A_INFO_MEMORY_SPACE_BANK1 0x04 98 99 #define FLASH_A_MAIN_SPACE FLCTL_A_RDBRST_CTLSTAT_MEM_TYPE_0 100 #define FLASH_A_INFO_SPACE FLCTL_A_RDBRST_CTLSTAT_MEM_TYPE_1 101 #define FLASH_A_1_PATTERN FLCTL_A_RDBRST_CTLSTAT_DATA_CMP 102 #define FLASH_A_0_PATTERN 0x00 103 104 #define FLASH_A_SECTOR0 FLCTL_A_BANK0_MAIN_WEPROT_PROT0 105 #define FLASH_A_SECTOR1 FLCTL_A_BANK0_MAIN_WEPROT_PROT1 106 #define FLASH_A_SECTOR2 FLCTL_A_BANK0_MAIN_WEPROT_PROT2 107 #define FLASH_A_SECTOR3 FLCTL_A_BANK0_MAIN_WEPROT_PROT3 108 #define FLASH_A_SECTOR4 FLCTL_A_BANK0_MAIN_WEPROT_PROT4 109 #define FLASH_A_SECTOR5 FLCTL_A_BANK0_MAIN_WEPROT_PROT5 110 #define FLASH_A_SECTOR6 FLCTL_A_BANK0_MAIN_WEPROT_PROT6 111 #define FLASH_A_SECTOR7 FLCTL_A_BANK0_MAIN_WEPROT_PROT7 112 #define FLASH_A_SECTOR8 FLCTL_A_BANK0_MAIN_WEPROT_PROT8 113 #define FLASH_A_SECTOR9 FLCTL_A_BANK0_MAIN_WEPROT_PROT9 114 #define FLASH_A_SECTOR10 FLCTL_A_BANK0_MAIN_WEPROT_PROT10 115 #define FLASH_A_SECTOR11 FLCTL_A_BANK0_MAIN_WEPROT_PROT11 116 #define FLASH_A_SECTOR12 FLCTL_A_BANK0_MAIN_WEPROT_PROT12 117 #define FLASH_A_SECTOR13 FLCTL_A_BANK0_MAIN_WEPROT_PROT13 118 #define FLASH_A_SECTOR14 FLCTL_A_BANK0_MAIN_WEPROT_PROT14 119 #define FLASH_A_SECTOR15 FLCTL_A_BANK0_MAIN_WEPROT_PROT15 120 #define FLASH_A_SECTOR16 FLCTL_A_BANK0_MAIN_WEPROT_PROT16 121 #define FLASH_A_SECTOR17 FLCTL_A_BANK0_MAIN_WEPROT_PROT17 122 #define FLASH_A_SECTOR18 FLCTL_A_BANK0_MAIN_WEPROT_PROT18 123 #define FLASH_A_SECTOR19 FLCTL_A_BANK0_MAIN_WEPROT_PROT19 124 #define FLASH_A_SECTOR20 FLCTL_A_BANK0_MAIN_WEPROT_PROT20 125 #define FLASH_A_SECTOR21 FLCTL_A_BANK0_MAIN_WEPROT_PROT21 126 #define FLASH_A_SECTOR22 FLCTL_A_BANK0_MAIN_WEPROT_PROT22 127 #define FLASH_A_SECTOR23 FLCTL_A_BANK0_MAIN_WEPROT_PROT23 128 #define FLASH_A_SECTOR24 FLCTL_A_BANK0_MAIN_WEPROT_PROT24 129 #define FLASH_A_SECTOR25 FLCTL_A_BANK0_MAIN_WEPROT_PROT25 130 #define FLASH_A_SECTOR26 FLCTL_A_BANK0_MAIN_WEPROT_PROT26 131 #define FLASH_A_SECTOR27 FLCTL_A_BANK0_MAIN_WEPROT_PROT27 132 #define FLASH_A_SECTOR28 FLCTL_A_BANK0_MAIN_WEPROT_PROT28 133 #define FLASH_A_SECTOR29 FLCTL_A_BANK0_MAIN_WEPROT_PROT29 134 #define FLASH_A_SECTOR30 FLCTL_A_BANK0_MAIN_WEPROT_PROT30 135 #define FLASH_A_SECTOR31 FLCTL_A_BANK0_MAIN_WEPROT_PROT31 136 137 #define FLASH_A_NOVER 0 138 #define FLASH_A_BURSTPOST FLCTL_A_PRGBRST_CTLSTAT_AUTO_PST 139 #define FLASH_A_BURSTPRE FLCTL_A_PRGBRST_CTLSTAT_AUTO_PRE 140 #define FLASH_A_REGPRE FLCTL_A_PRG_CTLSTAT_VER_PRE 141 #define FLASH_A_REGPOST FLCTL_A_PRG_CTLSTAT_VER_PST 142 #define FLASH_A_FULLVER (FLCTL_A_PRGBRST_CTLSTAT_AUTO_PST | \ 143 FLCTL_A_PRGBRST_CTLSTAT_AUTO_PRE | FLCTL_A_PRG_CTLSTAT_VER_PRE \ 144 | FLCTL_A_PRG_CTLSTAT_VER_PST) 145 146 #define FLASH_A_COLLATED_WRITE_MODE 0x01 147 #define FLASH_A_IMMEDIATE_WRITE_MODE 0x02 148 149 /* Internal parameters/definitions */ 150 #define __INFO_FLASH_A_TECH_START__ 0x00200000 151 #define __INFO_FLASH_A_TECH_MIDDLE__ 0x00204000 152 153 typedef struct __sFlashCtl_ProtectionRegister 154 { 155 uint32_t B0_MAIN_R0; 156 uint32_t B0_MAIN_R1; 157 uint32_t B0_MAIN_R2; 158 uint32_t B0_MAIN_R3; 159 uint32_t B0_MAIN_R4; 160 uint32_t B0_MAIN_R5; 161 uint32_t B0_MAIN_R6; 162 uint32_t B0_MAIN_R7; 163 uint32_t B1_MAIN_R0; 164 uint32_t B1_MAIN_R1; 165 uint32_t B1_MAIN_R2; 166 uint32_t B1_MAIN_R3; 167 uint32_t B1_MAIN_R4; 168 uint32_t B1_MAIN_R5; 169 uint32_t B1_MAIN_R6; 170 uint32_t B1_MAIN_R7; 171 uint32_t B0_INFO_R0; 172 uint32_t B1_INFO_R0; 173 } __FlashCtl_ProtectionRegister; 174 175 //***************************************************************************** 176 // 177 // Prototypes for the APIs. 178 // 179 //***************************************************************************** 180 181 //***************************************************************************** 182 // 183 //! Calculates the flash bank and sector number given an address. Stores the 184 //! results into the two pointers given as parameters. The user must provide 185 //! a valid memory address (an address in SRAM for example will give an invalid 186 //! result). 187 //! 188 //! \param addr Address to calculate the bank/sector information for 189 //! 190 //! \param bankNum The bank number will be stored in here after the function 191 //! completes. 192 //! 193 //! \param sectorNum The sector number will be stored in here after the function 194 //! completes. 195 //! 196 //! \note For simplicity, this API only works with address in MAIN flash memory. 197 //! For calculating the sector/bank number of an address in info memory, 198 //! please refer to your device datasheet/ 199 //! 200 //! \return None. 201 // 202 //***************************************************************************** 203 extern void FlashCtl_A_getMemoryInfo(uint32_t addr, uint32_t *bankNum, 204 uint32_t *sectorNum); 205 206 //***************************************************************************** 207 // 208 //! Enables read buffering on accesses to a specified bank of flash memory 209 //! 210 //! \param memoryBank is the value of the memory bank to enable read 211 //! buffering. Must be only one of the following values: 212 //! - \b FLASH_A_BANK0, 213 //! - \b FLASH_A_BANK1 214 //! 215 //! \param accessMethod is the value of the access type to enable read 216 //! buffering. Must be only one of the following values: 217 //! - \b FLASH_A_DATA_READ, 218 //! - \b FLASH_A_INSTRUCTION_FETCH 219 //! 220 //! \return None. 221 // 222 //***************************************************************************** 223 extern void FlashCtl_A_enableReadBuffering(uint_fast8_t memoryBank, 224 uint_fast8_t accessMethod); 225 226 //***************************************************************************** 227 // 228 //! Disables read buffering on accesses to a specified bank of flash memory 229 //! 230 //! \param memoryBank is the value of the memory bank to disable read 231 //! buffering. Must be only one of the following values: 232 //! - \b FLASH_A_BANK0, 233 //! - \b FLASH_A_BANK1 234 //! 235 //! \param accessMethod is the value of the access type to disable read 236 //! buffering. Must ne only one of the following values: 237 //! - \b FLASH_A_DATA_READ, 238 //! - \b FLASH_A_INSTRUCTION_FETCH 239 //! 240 //! \return None. 241 // 242 //***************************************************************************** 243 extern void FlashCtl_A_disableReadBuffering(uint_fast8_t memoryBank, 244 uint_fast8_t accessMethod); 245 246 //***************************************************************************** 247 // 248 //! Enables protection on the given flash memory range from writes. Note that 249 //! this function only works on flash memory and giving in an address to ROM 250 //! or SRAM will result in unreliable behavior. 251 //! 252 //! \param startAddr is the start address of the memory to protect 253 //! 254 //! \param endAddr is the end address of the memory to protect 255 //! 256 //! \note Flash memory is organized by protection by sector sizes. This means 257 //! that you will only be able to protect/unprotect memory based off 258 //! 4096 aligned boundaries. 259 //! 260 //! \return true if sector protection enabled false otherwise. 261 // 262 //***************************************************************************** 263 extern bool FlashCtl_A_protectMemory(uint32_t startAddr, uint32_t endAddr); 264 265 //***************************************************************************** 266 // 267 //! Disables protection on the given flash memory range from writes. Note that 268 //! this function only works on flash memory and giving in an address to ROM 269 //! or SRAM will result in unreliable behavior. 270 //! 271 //! \param startAddr is the start address of the memory to unprotect 272 //! 273 //! \param endAddr is the end address of the memory to unprotect 274 //! 275 //! \note Flash memory is organized by protection by sector sizes. This means 276 //! that you will only be able to protect/unprotect memory based off 277 //! 4096 aligned boundaries. 278 //! 279 //! \return true if sector protection enabled false otherwise. 280 // 281 //***************************************************************************** 282 extern bool FlashCtl_A_unprotectMemory(uint32_t startAddr, uint32_t endAddr); 283 284 //***************************************************************************** 285 // 286 //! Scans over the given memory range and returns false if any of the inclusive 287 //! memory addresses is protect from writes. 288 //! 289 //! \param startAddr is the start address to scan 290 //! 291 //! \param endAddr is the end address to scan 292 //! 293 //! \return true if sector protection enabled on any of the incluseive memory 294 //! addresses, false otherwise. 295 // 296 //***************************************************************************** 297 extern bool FlashCtl_A_isMemoryRangeProtected(uint32_t startAddr, 298 uint32_t endAddr); 299 300 //***************************************************************************** 301 // 302 //! Scans over the given memory range and returns false if any of the inclusive 303 //! memory addresses is protect from writes. 304 //! 305 //! \param startAddr is the start address to scan 306 //! 307 //! \param endAddr is the end address to scan 308 //! 309 //! \return true if sector protection enabled on any of the incluseive memory 310 //! addresses, false otherwise. 311 // 312 //***************************************************************************** 313 extern bool FlashCtl_A_isMemoryProtected(uint32_t addr); 314 315 //***************************************************************************** 316 // 317 //! Verifies a given segment of memory based off either a high (1) or low (0) 318 //! state. 319 //! 320 //! \param verifyAddr Start address where verification will begin 321 //! 322 //! \param length Length in bytes to verify based off the pattern 323 //! 324 //! \param pattern The pattern which verification will check versus. This can 325 //! either be a low pattern (each register will be checked versus a pattern 326 //! of 32 zeros, or a high pattern (each register will be checked versus a 327 //! pattern of 32 ones). Valid values are: FLASH_A_0_PATTERN, FLASH_A_1_PATTERN 328 //! 329 //! \note There are no sector/boundary restrictions for this function, 330 //! however it is encouraged to proved a start address aligned on 32-bit 331 //! boundaries. Providing an unaligned address will result in unaligned data 332 //! accesses and detriment efficiency. 333 //! 334 //! \note This function is blocking and will not exit until operation has 335 //! either completed or failed due to an error. Furthermore, given the 336 //! complex verification requirements of the flash controller, master 337 //! interrupts are disabled throughout execution of this function. The original 338 //! interrupt context is saved at the start of execution and restored prior 339 //! to exit of the API. 340 //! 341 //! \note Due to the hardware limitations of the flash controller, this 342 //! function cannot verify a memory adress in the same flash bank that it 343 //! is executing from. If using the ROM version of this API (by using the 344 //! (ROM_ or MAP_ prefixes) this is a don't care, however if this API resides 345 //! in flash then special care needs to be taken to ensure no code execution 346 //! or reads happen in the flash bank being programmed while this API is 347 //! being executed. 348 //! 349 //! \return true if memory verification is successful, false otherwise. 350 // 351 //***************************************************************************** 352 extern bool FlashCtl_A_verifyMemory(void* verifyAddr, uint32_t length, 353 uint_fast8_t pattern); 354 355 //***************************************************************************** 356 // 357 //! Performs a mass erase on all unprotected flash sectors. Protected sectors 358 //! are ignored. 359 //! 360 //! \note This function is blocking and will not exit until operation has 361 //! either completed or failed due to an error. Furthermore, given the 362 //! complex verification requirements of the flash controller, master 363 //! interrupts are disabled throughout execution of this function. The original 364 //! interrupt context is saved at the start of execution and restored prior 365 //! to exit of the API. 366 //! 367 //! \note Due to the hardware limitations of the flash controller, this 368 //! function cannot erase a memory adress in the same flash bank that it 369 //! is executing from. If using the ROM version of this API (by using the 370 //! (ROM_ or MAP_ prefixes) this is a don't care, however if this API resides 371 //! in flash then special care needs to be taken to ensure no code execution 372 //! or reads happen in the flash bank being programmed while this API is 373 //! being executed. 374 //! 375 //! \return true if mass erase completes successfully, false otherwise 376 // 377 //***************************************************************************** 378 extern bool FlashCtl_A_performMassErase(void); 379 380 //***************************************************************************** 381 // 382 //! Initiates a mass erase and returns control back to the program. This is a 383 //! non-blocking function, however it is the user's responsibility to perform 384 //! the necessary verification requirements after the interrupt is set to 385 //! signify completion. 386 //! 387 //! \return None 388 // 389 //***************************************************************************** 390 extern void FlashCtl_A_initiateMassErase(void); 391 392 //***************************************************************************** 393 // 394 //! Erases a sector of MAIN or INFO flash memory. 395 //! 396 //! \param addr The start of the sector to erase. Note that with flash, 397 //! the minimum allowed size that can be erased is a flash sector 398 //! (which is 4KB on the MSP432 family). If an address is provided to 399 //! this function which is not on a 4KB boundary, the entire sector 400 //! will still be erased. 401 //! 402 //! \note This function is blocking and will not exit until operation has 403 //! either completed or failed due to an error. Furthermore, given the 404 //! complex verification requirements of the flash controller, master 405 //! interrupts are disabled throughout execution of this function. The original 406 //! interrupt context is saved at the start of execution and restored prior 407 //! to exit of the API. 408 //! 409 //! \note Due to the hardware limitations of the flash controller, this 410 //! function cannot erase a memory adress in the same flash bank that it 411 //! is executing from. If using the ROM version of this API (by using the 412 //! (ROM_ or MAP_ prefixes) this is a don't care, however if this API resides 413 //! in flash then special care needs to be taken to ensure no code execution 414 //! or reads happen in the flash bank being programmed while this API is 415 //! being executed. 416 //! 417 //! \return true if sector erase is successful, false otherwise. 418 // 419 //***************************************************************************** 420 extern bool FlashCtl_A_eraseSector(uint32_t addr); 421 422 //***************************************************************************** 423 // 424 //! Program a portion of flash memory with the provided data 425 //! 426 //! \param src Pointer to the data source to program into flash 427 //! 428 //! \param dest Pointer to the destination in flash to program 429 //! 430 //! \param length Length in bytes to program 431 //! 432 //! \note There are no sector/boundary restrictions for this function, 433 //! however it is encouraged to proved a start address aligned on 32-bit 434 //! boundaries. Providing an unaligned address will result in unaligned data 435 //! accesses and detriment efficiency. 436 //! 437 //! \note This function is blocking and will not exit until operation has 438 //! either completed or failed due to an error. Furthermore, given the 439 //! complex verification requirements of the flash controller, master 440 //! interrupts are disabled throughout execution of this function. The original 441 //! interrupt context is saved at the start of execution and restored prior 442 //! to exit of the API. 443 //! 444 //! \note Due to the hardware limitations of the flash controller, this 445 //! function cannot program a memory adress in the same flash bank that it 446 //! is executing from. If using the ROM version of this API (by using the 447 //! (ROM_ or MAP_ prefixes) this is a don't care, however if this API resides 448 //! in flash then special care needs to be taken to ensure no code execution 449 //! or reads happen in the flash bank being programmed while this API is 450 //! being executed. 451 //! 452 //! \return Whether or not the program succeeded 453 // 454 //***************************************************************************** 455 extern bool FlashCtl_A_programMemory(void* src, void* dest, 456 uint32_t length); 457 458 //***************************************************************************** 459 // 460 //! Setups pre/post verification of burst and regular flash programming 461 //! instructions. Note that this API is for advanced users that are programming 462 //! their own flash drivers. The program/erase APIs are not affected by this 463 //! setting and take care of the verification requirements. 464 //! 465 //! \param verificationSetting Verification setting to set. This value can 466 //! be a bitwise OR of the following values: 467 //! - \b FLASH_A_BURSTPOST, 468 //! - \b FLASH_A_BURSTPRE, 469 //! - \b FLASH_A_REGPRE, 470 //! - \b FLASH_A_REGPOST 471 //! - \b FLASH_A_NOVER No verification enabled 472 //! - \b FLASH_A_FULLVER Full verification enabled 473 //! 474 //! \return none 475 // 476 //***************************************************************************** 477 extern void FlashCtl_A_setProgramVerification(uint32_t verificationSetting); 478 479 //***************************************************************************** 480 // 481 //! Clears pre/post verification of burst and regular flash programming 482 //! instructions. Note that this API is for advanced users that are programming 483 //! their own flash drivers. The program/erase APIs are not affected by this 484 //! setting and take care of the verification requirements. 485 //! 486 //! \param verificationSetting Verification setting to clear. This value can 487 //! be a bitwise OR of the following values: 488 //! - \b FLASH_A_BURSTPOST, 489 //! - \b FLASH_A_BURSTPRE, 490 //! - \b FLASH_A_REGPRE, 491 //! - \b FLASH_A_REGPOST 492 //! - \b FLASH_A_NOVER No verification enabled 493 //! - \b FLASH_A_FULLVER Full verification enabled 494 //! 495 //! \return none 496 // 497 //***************************************************************************** 498 extern void FlashCtl_A_clearProgramVerification( 499 uint32_t verificationSetting); 500 501 //***************************************************************************** 502 // 503 //! Enables word programming of flash memory. 504 //! 505 //! This function will enable word programming of the flash memory and set the 506 //! mode of behavior when the flash write occurs. 507 //! 508 //! \param mode The mode specifies the behavior of the flash controller when 509 //! programming words to flash. In \b FLASH_A_IMMEDIATE_WRITE_MODE, the 510 //! program operation happens immediately on the write to flash while 511 //! in \b FLASH_A_COLLATED_WRITE_MODE the write will be delayed until a full 512 //! 128-bits have been collated. Possible values include: 513 //! - \b FLASH_A_IMMEDIATE_WRITE_MODE 514 //! - \b FLASH_A_COLLATED_WRITE_MODE 515 //! 516 //! 517 //! Refer to the user's guide for further documentation. 518 //! 519 //! \return none 520 // 521 //***************************************************************************** 522 extern void FlashCtl_A_enableWordProgramming(uint32_t mode); 523 524 //***************************************************************************** 525 // 526 //! Disables word programming of flash memory. 527 //! 528 //! Refer to FlashCtl_A_enableWordProgramming and the user's guide for description 529 //! on the difference between full word and immediate programming 530 //! 531 //! \return None. 532 // 533 //***************************************************************************** 534 extern void FlashCtl_A_disableWordProgramming(void); 535 536 //***************************************************************************** 537 // 538 //! Returns if word programming mode is enabled (and if it is, the specific mode) 539 //! 540 //! Refer to FlashCtl_A_enableWordProgramming and the user's guide for description 541 //! on the difference between full word and immediate programming 542 //! 543 //! \return a zero value if word programming is disabled, 544 //! - \b FLASH_A_IMMEDIATE_WRITE_MODE 545 //! - \b FLASH_A_COLLATED_WRITE_MODE 546 //! 547 // 548 //***************************************************************************** 549 extern uint32_t FlashCtl_A_isWordProgrammingEnabled(void); 550 551 //***************************************************************************** 552 // 553 //! Sets the flash read mode to be used by default flash read operations. 554 //! Note that the proper wait states must be set prior to entering this 555 //! function. 556 //! 557 //! \param flashBank Flash bank to set read mode for. Valid values are: 558 //! - \b FLASH_A_BANK0 559 //! - \b FLASH_A_BANK1 560 //! 561 //! \param readMode The read mode to set. Valid values are: 562 //! - \b FLASH_A_NORMAL_READ_MODE, 563 //! - \b FLASH_A_MARGIN0_READ_MODE, 564 //! - \b FLASH_A_MARGIN1_READ_MODE, 565 //! - \b FLASH_A_PROGRAM_VERIFY_READ_MODE, 566 //! - \b FLASH_A_ERASE_VERIFY_READ_MODE, 567 //! - \b FLASH_A_LEAKAGE_VERIFY_READ_MODE, 568 //! - \b FLASH_A_MARGIN0B_READ_MODE, 569 //! - \b FLASH_A_MARGIN1B_READ_MODE 570 //! 571 //! \return None. 572 // 573 //***************************************************************************** 574 extern bool FlashCtl_A_setReadMode(uint32_t flashBank, uint32_t readMode); 575 576 //***************************************************************************** 577 // 578 //! Gets the flash read mode to be used by default flash read operations. 579 //! 580 //! \param flashBank Flash bank to set read mode for. Valid values are: 581 //! - \b FLASH_A_BANK0 582 //! - \b FLASH_A_BANK1 583 //! 584 //! \return Returns the read mode to set. Valid values are: 585 //! - \b FLASH_A_NORMAL_READ_MODE, 586 //! - \b FLASH_A_MARGIN0_READ_MODE, 587 //! - \b FLASH_A_MARGIN1_READ_MODE, 588 //! - \b FLASH_A_PROGRAM_VERIFY_READ_MODE, 589 //! - \b FLASH_A_ERASE_VERIFY_READ_MODE, 590 //! - \b FLASH_A_LEAKAGE_VERIFY_READ_MODE, 591 //! - \b FLASH_A_MARGIN0B_READ_MODE, 592 //! - \b FLASH_A_MARGIN1B_READ_MODE 593 //! 594 // 595 //***************************************************************************** 596 extern uint32_t FlashCtl_A_getReadMode(uint32_t flashBank); 597 598 //***************************************************************************** 599 // 600 //! Changes the number of wait states that are used by the flash controller 601 //! for read operations. When changing frequency ranges of the clock, this 602 //! functions must be used in order to allow for readable flash memory. 603 //! 604 //! \param waitState The number of wait states to set. Note that only 605 //! bits 0-3 are used. 606 //! 607 //! \param flashBank Flash bank to set wait state for. Valid values are: 608 //! - \b FLASH_A_BANK0 609 //! - \b FLASH_A_BANK1 610 //! 611 // 612 //***************************************************************************** 613 extern void FlashCtl_A_setWaitState(uint32_t bank, uint32_t waitState); 614 615 //***************************************************************************** 616 // 617 //! Returns the set number of flash wait states for the given flash bank. 618 //! 619 //! \param flashBank Flash bank to set wait state for. Valid values are: 620 //! - \b FLASH_A_BANK0 621 //! - \b FLASH_A_BANK1 622 //! 623 //! \return The wait state setting for the specified flash bank 624 // 625 //***************************************************************************** 626 extern uint32_t FlashCtl_A_getWaitState(uint32_t bank); 627 628 //***************************************************************************** 629 // 630 //! Enables individual flash control interrupt sources. 631 //! 632 //! \param flags is a bit mask of the interrupt sources to be enabled. Must 633 //! be a logical OR of: 634 //! - \b FLASH_A_PROGRAM_ERROR, 635 //! - \b FLASH_A_BENCHMARK_INT, 636 //! - \b FLASH_A_ERASE_COMPLETE, 637 //! - \b FLASH_A_BRSTPRGM_COMPLETE, 638 //! - \b FLASH_A_WRDPRGM_COMPLETE, 639 //! - \b FLASH_A_POSTVERIFY_FAILED, 640 //! - \b FLASH_A_PREVERIFY_FAILED, 641 //! - \b FLASH_A_BRSTRDCMP_COMPLETE 642 //! 643 //! This function enables the indicated flash system interrupt sources. Only 644 //! the sources that are enabled can be reflected to the processor interrupt; 645 //! disabled sources have no effect on the processor. 646 //! 647 //! \note The interrupt sources vary based on the part in use. 648 //! Please consult the data sheet for the part you are using to determine 649 //! which interrupt sources are available. 650 //! 651 //! \return None. 652 // 653 //***************************************************************************** 654 extern void FlashCtl_A_enableInterrupt(uint32_t flags); 655 656 //***************************************************************************** 657 // 658 //! Disables individual flash system interrupt sources. 659 //! 660 //! \param flags is a bit mask of the interrupt sources to be disabled. Must 661 //! be a logical OR of: 662 //! - \b FLASH_A_PROGRAM_ERROR, 663 //! - \b FLASH_A_BENCHMARK_INT, 664 //! - \b FLASH_A_ERASE_COMPLETE, 665 //! - \b FLASH_A_BRSTPRGM_COMPLETE, 666 //! - \b FLASH_A_WRDPRGM_COMPLETE, 667 //! - \b FLASH_A_POSTVERIFY_FAILED, 668 //! - \b FLASH_A_PREVERIFY_FAILED, 669 //! - \b FLASH_A_BRSTRDCMP_COMPLETE 670 //! 671 //! This function disables the indicated flash system interrupt sources. 672 //! Only the sources that are enabled can be reflected to the processor 673 //! interrupt; disabled sources have no effect on the processor. 674 //! 675 //! 676 //! \return None. 677 // 678 //***************************************************************************** 679 extern void FlashCtl_A_disableInterrupt(uint32_t flags); 680 681 //***************************************************************************** 682 // 683 //! Gets the current interrupt status masked with the enabled interrupts. 684 //! This function is useful to call in ISRs to get a list 685 //! of pending interrupts that are actually enabled and could have caused the 686 //! ISR. 687 //! 688 //! \return The current interrupt status, enumerated as a bit field of 689 //! - \b FLASH_A_PROGRAM_ERROR, 690 //! - \b FLASH_A_BENCHMARK_INT, 691 //! - \b FLASH_A_ERASE_COMPLETE, 692 //! - \b FLASH_A_BRSTPRGM_COMPLETE, 693 //! - \b FLASH_A_WRDPRGM_COMPLETE, 694 //! - \b FLASH_A_POSTVERIFY_FAILED, 695 //! - \b FLASH_A_PREVERIFY_FAILED, 696 //! - \b FLASH_A_BRSTRDCMP_COMPLETE 697 //! 698 //! \note The interrupt sources vary based on the part in use. 699 //! Please consult the data sheet for the part you are using to determine 700 //! which interrupt sources are available. 701 // 702 //***************************************************************************** 703 extern uint32_t FlashCtl_A_getEnabledInterruptStatus(void); 704 705 //***************************************************************************** 706 // 707 //! Gets the current interrupt status. 708 //! 709 //! \return The current interrupt status, enumerated as a bit field of: 710 //! - \b FLASH_A_PROGRAM_ERROR, 711 //! - \b FLASH_A_BENCHMARK_INT, 712 //! - \b FLASH_A_ERASE_COMPLETE, 713 //! - \b FLASH_A_BRSTPRGM_COMPLETE, 714 //! - \b FLASH_A_WRDPRGM_COMPLETE, 715 //! - \b FLASH_A_POSTVERIFY_FAILED, 716 //! - \b FLASH_A_PREVERIFY_FAILED, 717 //! - \b FLASH_A_BRSTRDCMP_COMPLETE 718 //! 719 //! \note The interrupt sources vary based on the part in use. 720 //! Please consult the data sheet for the part you are using to determine 721 //! which interrupt sources are available. 722 // 723 //***************************************************************************** 724 extern uint32_t FlashCtl_A_getInterruptStatus(void); 725 726 //***************************************************************************** 727 // 728 //! Clears flash system interrupt sources. 729 //! 730 //! \param flags is a bit mask of the interrupt sources to be cleared. Must 731 //! be a logical OR of: 732 //! - \b FLASH_A_PROGRAM_ERROR, 733 //! - \b FLASH_A_BENCHMARK_INT, 734 //! - \b FLASH_A_ERASE_COMPLETE, 735 //! - \b FLASH_A_BRSTPRGM_COMPLETE, 736 //! - \b FLASH_A_WRDPRGM_COMPLETE, 737 //! - \b FLASH_A_POSTVERIFY_FAILED, 738 //! - \b FLASH_A_PREVERIFY_FAILED, 739 //! - \b FLASH_A_BRSTRDCMP_COMPLETE 740 //! 741 //! The specified flash system interrupt sources are cleared, so that they no 742 //! longer assert. This function must be called in the interrupt handler to 743 //! keep it from being called again immediately upon exit. 744 //! 745 //! \note Because there is a write buffer in the Cortex-M processor, it may 746 //! take several clock cycles before the interrupt source is actually cleared. 747 //! Therefore, it is recommended that the interrupt source be cleared early in 748 //! the interrupt handler (as opposed to the very last action) to avoid 749 //! returning from the interrupt handler before the interrupt source is 750 //! actually cleared. Failure to do so may result in the interrupt handler 751 //! being immediately reentered (because the interrupt controller still sees 752 //! the interrupt source asserted). 753 //! 754 //! \note The interrupt sources vary based on the part in use. 755 //! Please consult the data sheet for the part you are using to determine 756 //! which interrupt sources are available. 757 //! 758 //! \return None. 759 // 760 //***************************************************************************** 761 extern void FlashCtl_A_clearInterruptFlag(uint32_t flags); 762 763 //***************************************************************************** 764 // 765 //! Registers an interrupt handler for flash clock system interrupt. 766 //! 767 //! \param intHandler is a pointer to the function to be called when the clock 768 //! system interrupt occurs. 769 //! 770 //! This function registers the handler to be called when a clock system 771 //! interrupt occurs. This function enables the global interrupt in the 772 //! interrupt controller; specific flash controller interrupts must be enabled 773 //! via FlashCtl_A_enableInterrupt(). It is the interrupt handler's 774 //! responsibility to clear the interrupt source via 775 //! FlashCtl_A_clearInterruptFlag(). 776 //! 777 //! \sa Interrupt_registerInterrupt() for important information about 778 //! registering interrupt handlers. 779 //! 780 //! \return None. 781 // 782 //***************************************************************************** 783 extern void FlashCtl_A_registerInterrupt(void (*intHandler)(void)); 784 785 //***************************************************************************** 786 // 787 //! Unregisters the interrupt handler for the flash system. 788 //! 789 //! This function unregisters the handler to be called when a clock system 790 //! interrupt occurs. This function also masks off the interrupt in the 791 //! interrupt controller so that the interrupt handler no longer is called. 792 //! 793 //! \sa Interrupt_registerInterrupt() for important information about 794 //! registering interrupt handlers. 795 //! 796 //! \return None. 797 // 798 //***************************************************************************** 799 extern void FlashCtl_A_unregisterInterrupt(void); 800 801 //***************************************************************************** 802 // 803 //! Initiates a sector erase of MAIN or INFO flash memory. Note that this 804 //! function simply initaites the sector erase, but does no verification 805 //! which is required by the flash controller. The user must manually set 806 //! and enable interrupts on the flash controller to fire on erase completion 807 //! and then use the FlashCtl_A_verifyMemory function to verify that the sector 808 //! was actually erased 809 //! 810 //! \param addr The start of the sector to erase. Note that with flash, 811 //! the minimum allowed size that can be erased is a flash sector 812 //! (which is 4KB on the MSP432 family). If an address is provided to 813 //! this function which is not on a 4KB boundary, the entire sector 814 //! will still be erased. 815 //! 816 //! \return None 817 // 818 //***************************************************************************** 819 extern void FlashCtl_A_initiateSectorErase(uint32_t addr); 820 821 /* The following functions are advanced functions that are used by the flash 822 * driver to remask a failed bit in the event of a post or pre verification 823 * failure. They are meant to be advanced functions and should not be used 824 * by the majority of users (unless you are writing your own flash driver). 825 */ 826 extern uint8_t __FlashCtl_A_remaskData8Post(uint8_t data, uint32_t addr); 827 extern uint8_t __FlashCtl_A_remaskData8Pre(uint8_t data, uint32_t addr); 828 extern uint32_t __FlashCtl_A_remaskData32Post(uint32_t data, uint32_t addr); 829 extern uint32_t __FlashCtl_A_remaskData32Pre(uint32_t data, uint32_t addr); 830 extern void __FlashCtl_A_remaskBurstDataPost(uint32_t addr, uint32_t size); 831 extern void __FlashCtl_A_remaskBurstDataPre(uint32_t addr, uint32_t size); 832 833 //***************************************************************************** 834 // 835 // Mark the end of the C bindings section for C++ compilers. 836 // 837 //***************************************************************************** 838 #ifdef __cplusplus 839 } 840 #endif 841 842 //***************************************************************************** 843 // 844 // Close the Doxygen group. 845 //! @} 846 // 847 //***************************************************************************** 848 849 #endif /* __MCU_HAS_FLCTL_A__ */ 850 851 #endif // __FLASH_A_H__ 852