Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches
Initialization and ID Functions
Collaboration diagram for Initialization and ID Functions:

Functions

HAL_StatusTypeDef QFlash_ReadManufactutrerAndDevID (uint16_t *dataptr)
 read id of the winbond
 
HAL_StatusTypeDef QFlash_Init (void)
 
HAL_StatusTypeDef QFlash_ReadJedecID (uint8_t *dataptr)
 
HAL_StatusTypeDef QFlash_ReadSFDP (uint8_t *dataptr)
 
HAL_StatusTypeDef QFlash_ReadDevID (uint8_t *dataptr)
 

Detailed Description

Function Documentation

◆ QFlash_Init()

HAL_StatusTypeDef QFlash_Init ( void  )

Definition at line 269 of file z_qflash_W25QXXX.c.

269 {
270uint8_t data[256];
271
272 HAL_Delay(6); // supposing init is called on system startup: 5 ms (tPUW) required after power-up to be fully available
273
274// reset the device (supposing it is a W25Q)
275 if (QFlash_Reset()!=HAL_OK)
276 return HAL_ERROR;
277
278// testing if an SFPD device is connected and working
279 for (uint8_t k=0;k!=3;k++)
280 data[k]=0xFF;
281 if (QFlash_ReadSFDP(data))
282 return HAL_ERROR;
283 if (!((data[0]=='S') && (data[1]=='F') && (data[2]=='D') && (data[3]=='P')))
284 if (!((data[0]=='S') && (data[2]=='F') && (data[5]=='D') && (data[7]=='P'))) //this is in case of dual flash configuration
285 return HAL_ERROR;
286
287//testing if it is a Winbond memory
288 if (QFlash_ReadJedecID(data)) //select the memSize byte
289 return HAL_ERROR;;
290 if (data[0] != 0xEF) // if ManufacturerID is not Winbond (0xEF)
291 return HAL_ERROR;
292
293 QSPI_CommandTypeDef sCmd_4byte = {0};
294 QFlash_DefaultCmd(&sCmd_4byte); // To get default instruction mode, etc.
295 sCmd_4byte.Instruction = W25_ENTER_4B_ADDR; // This is 0xB7
296 sCmd_4byte.AddressMode = QSPI_ADDRESS_NONE; // Correct, 0xB7 takes no address
297 sCmd_4byte.DataMode = QSPI_DATA_NONE; // Correct, 0xB7 has no data
298 sCmd_4byte.InstructionMode= QSPI_INSTRUCTION_1_LINE; // Correct, 0xB7 is a 1-line command
299 // DummyCycles, NbData, etc., default to 0 or are not relevant
300
301 // Handle QSpiAvailable if using DMA for this command
302 #ifdef EXT_FLASH_QSPI_DMA_MODE
304 // QSpiAvailable = 0; // Not strictly needed for a single HAL_QSPI_Command if it's blocking
305 // and not followed by DMA transmit/receive in THIS sequence.
306 // But good practice if other parts of the system rely on it.
307 #endif
308
309 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCmd_4byte, QFLASH_DEF_TIMEOUT) != HAL_OK) {
310 // #ifdef EXT_FLASH_QSPI_DMA_MODE
311 // QSpiAvailable = 1;
312 // #endif
313 return HAL_ERROR;
314 }
315
316
317#ifdef FLASH_QSPI_MEMORY_MAPPED
318// reset and tests are OK: enable memory mapped mode
319 if (QFlash_EnableMemoryMappedMode()==HAL_ERROR)
320 return HAL_ERROR;
321#endif //FLASH_QSPI_MEMORY_MAPPED
322
323 return HAL_OK; //return memSize as per table in Flash_ReadJedecID() definition
324}
HAL_StatusTypeDef QFlash_Reset()
HAL_StatusTypeDef QFlash_ReadJedecID(uint8_t *dataptr)
HAL_StatusTypeDef QFlash_ReadSFDP(uint8_t *dataptr)
#define QFLASH_DEF_TIMEOUT
#define W25_ENTER_4B_ADDR
HAL_StatusTypeDef QFlash_WaitForQSPIAvailable(uint32_t timeout)
void QFlash_DefaultCmd(QSPI_CommandTypeDef *sCommand)
QSPI_HandleTypeDef FLASH_QSPI_PORT
@ HAL_ERROR
@ HAL_OK

References FLASH_QSPI_PORT, HAL_ERROR, HAL_OK, QFLASH_DEF_TIMEOUT, QFlash_DefaultCmd(), QFlash_ReadJedecID(), QFlash_ReadSFDP(), QFlash_Reset(), QFlash_WaitForQSPIAvailable(), and W25_ENTER_4B_ADDR.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ QFlash_ReadDevID()

HAL_StatusTypeDef QFlash_ReadDevID ( uint8_t *  dataptr)

Definition at line 1141 of file z_qflash_W25QXXX.c.

1141 {
1142QSPI_CommandTypeDef sCommand = {0};
1143
1144 QFlash_DefaultCmd(&sCommand);
1145 sCommand.Instruction = W25_POWERUP_ID;
1146 sCommand.DataMode = QSPI_DATA_1_LINE;
1147 sCommand.AddressMode = QSPI_ADDRESS_1_LINE;
1148 sCommand.AddressSize = QSPI_ADDRESS_24_BITS; // I need to send 3 dummy bytes avter command
1149 sCommand.Address = 0;
1150 sCommand.NbData = 1; //after 3 dummy bytes I can read the Device ID
1151 sCommand.DummyCycles = 0;
1152
1153#ifdef EXT_FLASH_QSPI_DMA_MODE
1154 while (!QSpiAvailable) {}; // waiting for a free QSPI port.
1155 QSpiAvailable=0; //set QSPI busy
1156 QSpiReadDataAvailable=0; //set data read unavailable yet
1157 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK) { //Send command
1158 return HAL_ERROR;
1159 }
1160 if (HAL_QSPI_Receive_DMA(&FLASH_QSPI_PORT, dataptr) != HAL_OK) { // Receive data
1161 return HAL_ERROR;
1162 }
1164#else
1165 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK) { //Send command
1166 return HAL_ERROR;
1167 }
1168 if (HAL_QSPI_Receive(&FLASH_QSPI_PORT, dataptr, QFLASH_DEF_TIMEOUT) != HAL_OK) { // Receive data
1169 return HAL_ERROR;
1170 }
1171#endif //EXT_FLASH_QSPI_DMA_MODE
1172
1173 return HAL_OK;
1174}
#define W25_POWERUP_ID
HAL_StatusTypeDef QFlash_WaitForDataAvailable(uint32_t timeout)
static volatile uint8_t QSpiAvailable
static volatile uint8_t QSpiReadDataAvailable

References FLASH_QSPI_PORT, HAL_ERROR, HAL_OK, QFLASH_DEF_TIMEOUT, QFlash_DefaultCmd(), QFlash_WaitForDataAvailable(), QSpiAvailable, QSpiReadDataAvailable, and W25_POWERUP_ID.

Here is the call graph for this function:

◆ QFlash_ReadJedecID()

HAL_StatusTypeDef QFlash_ReadJedecID ( uint8_t *  dataptr)

Definition at line 183 of file z_qflash_W25QXXX.c.

183 {
184QSPI_CommandTypeDef sCommand = {0};
185
186 QFlash_DefaultCmd(&sCommand);
187 sCommand.Instruction = W25_JEDEC_ID;
188 sCommand.DataMode = QSPI_DATA_1_LINE;
189 sCommand.AddressMode = QSPI_ADDRESS_NONE;
190 sCommand.Address = 0;
191 sCommand.NbData = 3;
192 sCommand.DummyCycles = 0;
193
194#ifdef EXT_FLASH_QSPI_DMA_MODE
195 while (!QSpiAvailable) {}; // waiting for a free QSPI port.
196 QSpiAvailable=0; //set QSPI busy
197 QSpiReadDataAvailable=0; //set data read unavailable yet
198 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK) { //Send command
199 return HAL_ERROR;
200 }
201 if (HAL_QSPI_Receive_DMA(&FLASH_QSPI_PORT, dataptr) != HAL_OK) { // Receive data
202 return HAL_ERROR;
203 }
205#else
206 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK) { //Send command
207 return HAL_ERROR;
208 }
209 if (HAL_QSPI_Receive(&FLASH_QSPI_PORT, dataptr, QFLASH_DEF_TIMEOUT) != HAL_OK) { // Receive data
210 return HAL_ERROR;
211 }
212#endif //EXT_FLASH_QSPI_DMA_MODE
213
214 return HAL_OK;
215}
#define W25_JEDEC_ID

References FLASH_QSPI_PORT, HAL_ERROR, HAL_OK, QFLASH_DEF_TIMEOUT, QFlash_DefaultCmd(), QFlash_WaitForDataAvailable(), QSpiAvailable, QSpiReadDataAvailable, and W25_JEDEC_ID.

Referenced by QFlash_Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ QFlash_ReadManufactutrerAndDevID()

HAL_StatusTypeDef QFlash_ReadManufactutrerAndDevID ( uint16_t *  dataptr)

read id of the winbond

Definition at line 1183 of file z_qflash_W25QXXX.c.

1183 {
1184QSPI_CommandTypeDef sCommand = {0};
1185
1186 QFlash_DefaultCmd(&sCommand);
1187 sCommand.Instruction = W25_MAN_DEVICE_ID;
1188 sCommand.DataMode = QSPI_DATA_1_LINE;
1189 sCommand.AddressMode = QSPI_ADDRESS_1_LINE;
1190 sCommand.AddressSize = QSPI_ADDRESS_24_BITS; // I need to send 3 dummy bytes avter command
1191 sCommand.Address = 0;
1192 sCommand.NbData = 2; //after 3 dummy bytes I can read the Device ID
1193 sCommand.DummyCycles = 0;
1194
1195#ifdef EXT_FLASH_QSPI_DMA_MODE
1196 while (!QSpiAvailable) {}; // waiting for a free QSPI port.
1197 QSpiAvailable=0; //set QSPI busy
1198 QSpiReadDataAvailable=0; //set data read unavailable yet
1199 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK) { //Send command
1200 return HAL_ERROR;
1201 }
1202 if (HAL_QSPI_Receive_DMA(&FLASH_QSPI_PORT, (uint8_t *) dataptr) != HAL_OK) { // Receive data
1203 return HAL_ERROR;
1204 }
1206#else
1207 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK) { //Send command
1208 return HAL_ERROR;
1209 }
1210 if (HAL_QSPI_Receive(&FLASH_QSPI_PORT, (uint8_t *) dataptr, QFLASH_DEF_TIMEOUT) != HAL_OK) { // Receive data
1211 return HAL_ERROR;
1212 }
1213#endif //EXT_FLASH_QSPI_DMA_MODE
1214
1215 return HAL_OK;
1216}
#define W25_MAN_DEVICE_ID

References FLASH_QSPI_PORT, HAL_ERROR, HAL_OK, QFLASH_DEF_TIMEOUT, QFlash_DefaultCmd(), QFlash_WaitForDataAvailable(), QSpiAvailable, QSpiReadDataAvailable, and W25_MAN_DEVICE_ID.

Here is the call graph for this function:

◆ QFlash_ReadSFDP()

HAL_StatusTypeDef QFlash_ReadSFDP ( uint8_t *  dataptr)

Definition at line 225 of file z_qflash_W25QXXX.c.

225 {
226QSPI_CommandTypeDef sCommand = {0};
227
228 QFlash_DefaultCmd(&sCommand);
229 sCommand.Instruction = W25_R_SFPD_REG;
230 sCommand.DataMode = QSPI_DATA_1_LINE;
231 sCommand.AddressMode = QSPI_ADDRESS_1_LINE;
232 sCommand.AddressSize = QSPI_ADDRESS_24_BITS;
233 sCommand.Address = 0;
234 sCommand.NbData = 256;
235 sCommand.DummyCycles = 8;
236
237#ifdef EXT_FLASH_QSPI_DMA_MODE
238 while (!QSpiAvailable) {}; // waiting for a free QSPI port.
239 QSpiAvailable=0; //set QSPI busy
240 QSpiReadDataAvailable=0; //set data requested unavailable yet
241 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK) { //Send command
242 return HAL_ERROR;
243 }
244 if (HAL_QSPI_Receive_DMA(&FLASH_QSPI_PORT, dataptr) != HAL_OK) { // Receive data
245 return HAL_ERROR;
246 }
248#else
249 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK) { //Send command
250 return HAL_ERROR;
251 }
252 if (HAL_QSPI_Receive(&FLASH_QSPI_PORT, dataptr, QFLASH_DEF_TIMEOUT) != HAL_OK) { // Receive data
253 return HAL_ERROR;
254 }
255#endif //EXT_FLASH_QSPI_DMA_MODE
256
257 return HAL_OK;
258}
#define W25_R_SFPD_REG

References FLASH_QSPI_PORT, HAL_ERROR, HAL_OK, QFLASH_DEF_TIMEOUT, QFlash_DefaultCmd(), QFlash_WaitForDataAvailable(), QSpiAvailable, QSpiReadDataAvailable, and W25_R_SFPD_REG.

Referenced by QFlash_Init().

Here is the call graph for this function:
Here is the caller graph for this function: