Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches

Core functions for reading, writing, and erasing the flash memory. More...

Collaboration diagram for Memory Access Functions:

Functions

HAL_StatusTypeDef QFlash_Read (uint32_t address, uint8_t *buffer, uint32_t dataSize)
 
HAL_StatusTypeDef QFlash_Write (uint32_t addr, uint8_t *data, uint32_t dataSize)
 
HAL_StatusTypeDef QFlash_SErase4k (uint32_t addr)
 
HAL_StatusTypeDef QFlash_BErase32k (uint32_t addr)
 
HAL_StatusTypeDef QFlash_BErase64k (uint32_t addr)
 
HAL_StatusTypeDef QFlash_ChipErase (void)
 

Detailed Description

Core functions for reading, writing, and erasing the flash memory.

Function Documentation

◆ QFlash_BErase32k()

HAL_StatusTypeDef QFlash_BErase32k ( uint32_t  addr)

Definition at line 968 of file z_qflash_W25QXXX.c.

968 {
969 QSPI_CommandTypeDef sCommand = {0};
970
971 QFlash_DefaultCmd(&sCommand);
973 return HAL_ERROR;
974 if (QFlash_WriteEnable())
975 return HAL_ERROR;
976 sCommand.Instruction = W25_B_ERASE32K;
977 sCommand.DataMode = QSPI_DATA_NONE;
978 sCommand.AddressMode = QSPI_ADDRESS_1_LINE;
979 sCommand.NbData = 0;
980 sCommand.Address = addr;
981
982#ifdef EXT_FLASH_QSPI_DMA_MODE
983 while (!QSpiAvailable) {}; // waiting for a free QSPI port.
984#endif //EXT_FLASH_QSPI_DMA_MODE
985
986 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK) { //Send command
987 return HAL_ERROR;
988 }
989
991 return HAL_ERROR;
992 return HAL_OK;
993}
HAL_StatusTypeDef QFlash_WaitForWritingComplete()
#define QFLASH_DEF_TIMEOUT
#define W25_B_ERASE32K
void QFlash_DefaultCmd(QSPI_CommandTypeDef *sCommand)
HAL_StatusTypeDef QFlash_WriteEnable()
enables writes
static volatile uint8_t QSpiAvailable
QSPI_HandleTypeDef FLASH_QSPI_PORT
@ HAL_ERROR
@ HAL_OK

References FLASH_QSPI_PORT, HAL_ERROR, HAL_OK, QFLASH_DEF_TIMEOUT, QFlash_DefaultCmd(), QFlash_WaitForWritingComplete(), QFlash_WriteEnable(), QSpiAvailable, and W25_B_ERASE32K.

Here is the call graph for this function:

◆ QFlash_BErase64k()

HAL_StatusTypeDef QFlash_BErase64k ( uint32_t  addr)

Definition at line 1008 of file z_qflash_W25QXXX.c.

1008 {
1009 QSPI_CommandTypeDef sCommand = {0};
1010
1011 QFlash_DefaultCmd(&sCommand);
1013 return HAL_ERROR;
1014 if (QFlash_WriteEnable())
1015 return HAL_ERROR;
1016 sCommand.Instruction = W25_B_ERASE64K_4B;
1017 sCommand.DataMode = QSPI_DATA_NONE;
1018 sCommand.AddressMode = QSPI_ADDRESS_1_LINE;
1019 sCommand.NbData = 0;
1020 sCommand.Address = addr;
1021
1022#ifdef EXT_FLASH_QSPI_DMA_MODE
1023 while (!QSpiAvailable) {}; // waiting for a free QSPI port.
1024#endif //EXT_FLASH_QSPI_DMA_MODE
1025
1026 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK) { //Send command
1027 return HAL_ERROR;
1028 }
1029
1031 return HAL_ERROR;
1032 return HAL_OK;
1033}
#define W25_B_ERASE64K_4B

References FLASH_QSPI_PORT, HAL_ERROR, HAL_OK, QFLASH_DEF_TIMEOUT, QFlash_DefaultCmd(), QFlash_WaitForWritingComplete(), QFlash_WriteEnable(), QSpiAvailable, and W25_B_ERASE64K_4B.

Here is the call graph for this function:

◆ QFlash_ChipErase()

HAL_StatusTypeDef QFlash_ChipErase ( void  )

Definition at line 1045 of file z_qflash_W25QXXX.c.

1045 {
1046 QSPI_CommandTypeDef sCommand = {0};
1047
1048 QFlash_DefaultCmd(&sCommand);
1050 return HAL_ERROR;
1051
1052 if (QFlash_WriteEnable())
1053 return HAL_ERROR;
1054 sCommand.Instruction = W25_CH_ERASE;
1055 sCommand.DataMode = QSPI_DATA_NONE;
1056 sCommand.AddressMode = QSPI_ADDRESS_NONE;
1057
1058#ifdef EXT_FLASH_QSPI_DMA_MODE
1059 while (!QSpiAvailable) {}; // waiting for a free QSPI port.
1060#endif //EXT_FLASH_QSPI_DMA_MODE
1061
1062 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK) { //Send command
1063 return HAL_ERROR;
1064 }
1065
1067 return HAL_ERROR;
1068 return HAL_OK;
1069}
#define W25_CH_ERASE

References FLASH_QSPI_PORT, HAL_ERROR, HAL_OK, QFLASH_DEF_TIMEOUT, QFlash_DefaultCmd(), QFlash_WaitForWritingComplete(), QFlash_WriteEnable(), QSpiAvailable, and W25_CH_ERASE.

Referenced by main().

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

◆ QFlash_Read()

HAL_StatusTypeDef QFlash_Read ( uint32_t  address,
uint8_t *  buffer,
uint32_t  dataSize 
)

Definition at line 379 of file z_qflash_W25QXXX.c.

379 {
380QSPI_CommandTypeDef sCommand = {0};
381
382 if (dataSize==0)
383 return HAL_OK;
384
385 QFlash_DefaultCmd(&sCommand);
386 sCommand.Instruction = QFLASH_READ_COMMAND;
387 sCommand.Address = address;
388 sCommand.NbData = dataSize;
389 sCommand.DummyCycles = QFLASH_READ_DUMMYC;
390 sCommand.AlternateBytes = QFLASH_ALT_BYTES;
391 sCommand.AlternateBytesSize = QFLASH_ALT_BYTES_S;
392 sCommand.AlternateByteMode = QFLASH_ALT_BYTES_M;
393
394#ifdef EXT_FLASH_QSPI_DMA_MODE
395 while (!QSpiAvailable) {}; // waiting for a free QSPI port.
396 QSpiAvailable=0; //set QSPI busy
397 QSpiReadDataAvailable=0; //set data read unavailable yet
398 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK) { //Send command
399 return HAL_ERROR;
400 }
401 if (HAL_QSPI_Receive_DMA(&FLASH_QSPI_PORT, buffer) != HAL_OK) { // Receive data
402 return HAL_ERROR;
403 }
404#ifdef FLASH_QSPI_WAIT_FOR_READING_COMPLETE
406#endif //FLASH_QSPI_WAIT_FOR_READING_COMPLETED
407
408#else
409 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK) { //Send command
410 return HAL_ERROR;
411 }
412 if (HAL_QSPI_Receive(&FLASH_QSPI_PORT, buffer, QFLASH_DEF_TIMEOUT) != HAL_OK) { // Receive data
413 return HAL_ERROR;
414 }
415#endif //EXT_FLASH_QSPI_DMA_MODE
416
417 return HAL_OK;
418}
#define QFLASH_READ_DUMMYC
#define QFLASH_READ_COMMAND
#define QFLASH_ALT_BYTES_M
#define QFLASH_ALT_BYTES
#define QFLASH_ALT_BYTES_S
HAL_StatusTypeDef QFlash_WaitForDataAvailable(uint32_t timeout)
static volatile uint8_t QSpiReadDataAvailable

References FLASH_QSPI_PORT, HAL_ERROR, HAL_OK, QFLASH_ALT_BYTES, QFLASH_ALT_BYTES_M, QFLASH_ALT_BYTES_S, QFLASH_DEF_TIMEOUT, QFlash_DefaultCmd(), QFLASH_READ_COMMAND, QFLASH_READ_DUMMYC, QFlash_WaitForDataAvailable(), QSpiAvailable, and QSpiReadDataAvailable.

Referenced by DataReader_ReadData(), DataReader_StartDMAReadData(), and main().

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

◆ QFlash_SErase4k()

HAL_StatusTypeDef QFlash_SErase4k ( uint32_t  addr)

Definition at line 930 of file z_qflash_W25QXXX.c.

930 {
931 QSPI_CommandTypeDef sCommand = {0};
932
933 QFlash_DefaultCmd(&sCommand);
935 return HAL_ERROR;
936 if (QFlash_WriteEnable())
937 return HAL_ERROR;
938 sCommand.Instruction = W25_S_ERASE4K_4B;
939 sCommand.DataMode = QSPI_DATA_NONE;
940 sCommand.AddressMode = QSPI_ADDRESS_1_LINE;
941 sCommand.NbData = 0;
942 sCommand.Address = addr;
943
944#ifdef EXT_FLASH_QSPI_DMA_MODE
945 while (!QSpiAvailable) {}; // waiting for a free QSPI port.
946#endif //EXT_FLASH_QSPI_DMA_MODE
947 if (HAL_QSPI_Command(&FLASH_QSPI_PORT, &sCommand, QFLASH_DEF_TIMEOUT) != HAL_OK) { //Send command
948 return HAL_ERROR;
949 }
950
952 return HAL_ERROR;
953 return HAL_OK;
954}
#define W25_S_ERASE4K_4B

References FLASH_QSPI_PORT, HAL_ERROR, HAL_OK, QFLASH_DEF_TIMEOUT, QFlash_DefaultCmd(), QFlash_WaitForWritingComplete(), QFlash_WriteEnable(), QSpiAvailable, and W25_S_ERASE4K_4B.

Here is the call graph for this function:

◆ QFlash_Write()

HAL_StatusTypeDef QFlash_Write ( uint32_t  addr,
uint8_t *  data,
uint32_t  dataSize 
)

Definition at line 875 of file z_qflash_W25QXXX.c.

875 {
876uint32_t quota;
877uint32_t inpage_addr;
878
879 if (dataSize==0)
880 return HAL_OK;
881
882 // quota is the data size transferred until now
883 quota=0;
884
885 // define the starting write position inside the first Flash page to write...
886 inpage_addr=addr & (EXT_FLASH_PAGE_SIZE-1);
887
888 // ... so I can detect if more than 1 Flash page has still to be written
889 while ((dataSize-quota+inpage_addr)>EXT_FLASH_PAGE_SIZE){
890 //loop here, writing separate flash pages...
891
892 if (QFlash_WriteEnable())
893 return HAL_ERROR;
894 if (QFlash_WriteASinglePage(addr+quota,data+quota,EXT_FLASH_PAGE_SIZE-inpage_addr))
895 return HAL_ERROR;
896
897 quota+=(EXT_FLASH_PAGE_SIZE-inpage_addr);
898 if(quota>=67108864 - 211200){
899 __asm("nop");
900 }
901 // having aligned data to page border on the first writing
902 // next writings start from 0 position inside a page
903 inpage_addr=0;
905 }
906 // now just write the last Flash page...
907 if (dataSize-quota) { // ... if any
908
909 if (QFlash_WriteEnable())
910 return HAL_ERROR;
911 if (QFlash_WriteASinglePage(addr+quota,data+quota,dataSize-quota))
912 return HAL_ERROR;
914 }
915 return HAL_OK;
916}
#define EXT_FLASH_PAGE_SIZE
256 bytes per programmable page.
HAL_StatusTypeDef QFlash_WriteASinglePage(uint32_t addr, uint8_t *dataptr, uint32_t dataSize)

References EXT_FLASH_PAGE_SIZE, HAL_ERROR, HAL_OK, QFlash_WaitForWritingComplete(), QFlash_WriteASinglePage(), and QFlash_WriteEnable().

Referenced by check_Calibrating_phase(), and StartKalman_mkf().

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