FlashWFF3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024-2025 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1) Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2) Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * 3) Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from this
16  * software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  */
31 
32 /*
33  * ========== FlashWFF3.h ==========
34  */
35 
36 #ifndef ti_drivers_nvs_flash_FlashWFF3__include
37 #define ti_drivers_nvs_flash_FlashWFF3__include
38 
39 #include <stdint.h>
40 #include <string.h>
41 #include <ti/devices/DeviceFamily.h>
42 #include DeviceFamily_constructPath(driverlib/xip.h)
43 #include DeviceFamily_constructPath(driverlib/ospi.h)
44 #include DeviceFamily_constructPath(driverlib/debug.h)
45 
46 //*****************************************************************************
47 //
48 // If building with a C++ compiler, make all of the definitions in this header
49 // have a C binding.
50 //
51 //*****************************************************************************
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 /*
57  * Values that can be returned from the API functions
58  */
59 #define FLASH_STATUS_SUCCESS 0x00000000
60 #define FLASH_TIMEOUT_REACHED_ERROR (-1300)
61 #define PSRAM_XIP_OFFSET (0x100)
62 #define DEVICE_SWITCH_ERROR (-1)
63 /*
64  * Configuration values that should be passed to #XIPStartUDMATransaction()
65  * as the directionMode parameter.
66  */
68 #define FLASH_WR_BOUND_SIZE_IN_BYTES 64U
69 
70 #define FLASH_RD_BOUND_SIZE_IN_BYTES 256U
71 
72 /* Defines supports bit manipulation macros #BITMASK_x_0() & #BITMASK_x_y() */
73 #define __IF__(x) (x)
74 #define __THEN__(x) ? (x)
75 #define __ELSE__(x) : (x)
76 #define __ELSE_IF__(x) : (x)
77 
78 #define OSPI_IDLE_XSPI_COUNTER_BEFORE_TIMEOUT 100
79 
88 #define BITMASK_x_0(x) \
89  (__IF__((x) == 31) /* For x==31, we immediately return 0xFFFFFFFF */ \
90  __THEN__(0xFFFFFFFF) /* For other x, we return 2^(x+1) - 1. */ \
91  __ELSE__((1 << ((x) + 1)) - 1)) // MACRO BITMASK_x_0() //
92 
105 #define BITMASK_x_y(x, y) \
106  (__IF__((y) == 0) /* For y==0, we return Bits[x:0] */ \
107  __THEN__(BITMASK_x_0(x)) /* For y> 0, we return Bits[x:0] - Bits[y-1:0] */ \
108  __ELSE__(BITMASK_x_0(x) - BITMASK_x_0((y)-1))) // MACRO BITMASK_x_y(). //
109 
110 typedef enum
111 {
115 
116 typedef enum
117 {
121 
122 /* STIG status */
123 typedef enum
124 {
129 
130 /* STIG configuration operation types */
131 #define FLASH_STIG_CONFIG_ENTER 0
132 #define FLASH_STIG_CONFIG_EXIT 1
133 #define FLASH_STIG_CONFIG_PRE_READ 2
134 #define FLASH_STIG_CONFIG_EXECUTE_READ 3
135 #define FLASH_STIG_CONFIG_POST_READ 4
136 #define FLASH_STIG_CONFIG_PRE_WRITE 5
137 #define FLASH_STIG_CONFIG_EXECUTE_WRITE 6
138 #define FLASH_STIG_CONFIG_POST_WRITE 7
139 #define FLASH_STIG_CONFIG_PRE_ERASE 8
140 #define FLASH_STIG_CONFIG_EXECUTE_ERASE 9
141 #define FLASH_STIG_CONFIG_POST_ERASE 10
142 
143 /*
144  *Functions
145  */
146 
159 void FlashRead(uint32_t *readFromAddr, uint32_t *writeToAddr, uint32_t length);
160 
176 FlashStigStatus FlashReadSTIG(uint32_t readStartAddr, uint32_t *writeToAddr, uint8_t DeviceNum);
177 
191 FlashStigStatus FlashExecuteReadSTIGCommand(uint32_t srcReadAddr, uint32_t *writeToAddr);
192 
206 void FlashWrite(uint32_t *readFromAddr, uint32_t *writeToAddr, uint32_t length);
207 
225 FlashStigStatus FlashWriteSTIG(uint32_t *readFromAddr, uint32_t *writeToAddr, uint8_t DeviceNum);
226 
240 FlashStigStatus FlashExecuteWriteSTIGCommand(uint32_t srcWriteData, uint32_t srcWriteAddrPhy);
241 
247 void FlashSetOTFDE(uint8_t setState);
248 
260 uint32_t FlashExecutePolling(void);
261 
275 FlashStigStatus FlashExecuteEraseSTIGCommand(uint32_t EraseAddr_en, uint32_t srcEraseAddr);
276 
290 FlashStigStatus FlashSectorErase(uint32_t eraseStartAddr, uint8_t DeviceNum);
291 
298 void FlashSetTickPeriod(uint32_t TickPeriod);
299 
303 uint32_t FlashIsXspiIdle();
307 #ifdef __cplusplus
308 }
309 #endif
310 
311 #endif /* ti_drivers_nvs_flash_FlashWFF3__include */
FlashOtfdeStateSet
Definition: FlashWFF3.h:110
FlashStigStatus FlashSectorErase(uint32_t eraseStartAddr, uint8_t DeviceNum)
Execute erase Flash based on STIG command.
FlashStigStatus
Definition: FlashWFF3.h:123
Definition: FlashWFF3.h:112
Definition: FlashWFF3.h:118
FlashStigStatus FlashReadSTIG(uint32_t readStartAddr, uint32_t *writeToAddr, uint8_t DeviceNum)
Read from external memory using STIG command.
Definition: FlashWFF3.h:126
FlashStigStatus FlashWriteSTIG(uint32_t *readFromAddr, uint32_t *writeToAddr, uint8_t DeviceNum)
Write to external memory using STIG command.
Definition: FlashWFF3.h:113
Definition: FlashWFF3.h:125
uint32_t FlashExecutePolling(void)
read flash status register until WIP (write in process) indication is free.
uint32_t FlashIsXspiIdle()
xSPI (accessible) idle check before STIG execution.
FlashStigStatus FlashExecuteWriteSTIGCommand(uint32_t srcWriteData, uint32_t srcWriteAddrPhy)
Execute write to Flash based on STIG write command.
void FlashWrite(uint32_t *readFromAddr, uint32_t *writeToAddr, uint32_t length)
Write to external memory.
FlashStigStatus FlashExecuteEraseSTIGCommand(uint32_t EraseAddr_en, uint32_t srcEraseAddr)
Execute erase Flash based on STIG command.
FlashUdmaJobStatus
Definition: FlashWFF3.h:116
FlashStigStatus FlashExecuteReadSTIGCommand(uint32_t srcReadAddr, uint32_t *writeToAddr)
Execute read of one word from Flash based on STIG write command.
void FlashRead(uint32_t *readFromAddr, uint32_t *writeToAddr, uint32_t length)
Read from external memory.
Definition: FlashWFF3.h:119
Definition: FlashWFF3.h:127
void FlashSetOTFDE(uint8_t setState)
Enable/Disable the OTFDE.
void FlashSetTickPeriod(uint32_t TickPeriod)
Store the ClockP period internally.
© Copyright 1995-2026, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale