2024-05-31 01:29 AM - edited 2024-05-31 01:40 AM
Hello,
I am trying to use ST's QSPI driver that I found in that github link. https://github.com/STMicroelectronics/stm32-external-loader/tree/contrib/QSPI_Drivers I am using MT25QL512ABB1EW9-0SIT and when I tried to wire memory function that read it with using memorymapped I saw that first byte of my array is missing. When I increment the writing address one the problem is gone but I am trying to understand what can cause this issue.
uint8_t CSP_QSPI_WriteMemory(uint8_t* buffer, uint32_t address, uint32_t buffer_size) {
QSPI_CommandTypeDef sCommand;
uint32_t end_addr, current_size, current_addr;
/* Calculation of the size between the write address and the end of the page */
current_addr = 0;
while (current_addr <= address) {
current_addr += MEMORY_PAGE_SIZE;
}
current_size = current_addr - address;
/* Check if the size of the data is less than the remaining place in the page */
if (current_size > buffer_size) {
current_size = buffer_size;
}
/* Initialize the adress variables */
current_addr = address;
end_addr = address + buffer_size;
sCommand.InstructionMode = QSPI_INSTRUCTION_1_LINE;
sCommand.AddressSize = QSPI_ADDRESS_32_BITS;
sCommand.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
sCommand.DdrMode = QSPI_DDR_MODE_DISABLE;
sCommand.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
sCommand.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
sCommand.Instruction = QUAD_IN_FAST_PROG_CMD;
sCommand.AddressMode = QSPI_ADDRESS_1_LINE;
sCommand.DataMode = QSPI_DATA_4_LINES;
sCommand.NbData = buffer_size;
sCommand.Address = address;
sCommand.DummyCycles = 0;
/* Perform the write page by page */
do {
sCommand.Address = current_addr;
sCommand.NbData = current_size;
if (current_size == 0) {
return HAL_OK;
}
/* Enable write operations */
if (QSPI_WriteEnable() != HAL_OK) {
return HAL_ERROR;
}
/* Configure the command */
if (HAL_QSPI_Command(&hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE)
!= HAL_OK) {
return HAL_ERROR;
}
/* Transmission of the data */
if (HAL_QSPI_Transmit(&hqspi, buffer, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
return HAL_ERROR;
}
/* Configure automatic polling mode to wait for end of program */
if (QSPI_AutoPollingMemReady(HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
return HAL_ERROR;
}
/* Update the address and size variables for next page programming */
current_addr += current_size;
buffer += current_size;
current_size = ((current_addr + MEMORY_PAGE_SIZE) > end_addr) ? (end_addr - current_addr) : MEMORY_PAGE_SIZE;
} while (current_addr <= end_addr);
return HAL_OK;
}
And this is my code main code
uint8_t *writebuf = "Hello world from QSPI1!";
uint8_t readbuf1[100];
uint8_t readbuf2[100];
uint32_t sector = 2;
uint32_t page = 4;
if(CSP_QUADSPI_Init() != HAL_OK){
Error_Handler();
}
if(CSP_QSPI_Erase_Chip() != HAL_OK){
Error_Handler();
}
if(CSP_QSPI_WriteMemory(writebuf, 0, strlen(writebuf)) != HAL_OK){ //It is starting to write from that wanted address -1 please check that
Error_Handler();
}
if(CSP_QSPI_WriteMemoryToSectorPage(writebuf, sector, page, strlen(writebuf)) != HAL_OK){
Error_Handler();
}
if(CSP_QSPI_EnableMemoryMappedMode() != HAL_OK){
Error_Handler();
}
memcpy(readbuf1, (uint8_t *)0x90000000, sizeof(readbuf1));
memcpy(readbuf2, (uint8_t *)0x90020400, sizeof(readbuf2));
I tried to find the problem but I couldn't. Does anyone has an ide that I can work on?
Solved! Go to Solution.
2024-05-31 02:34 AM
Hello @Aurentiaco ,
In the driver code "quadspi.c", specifically in the the function "CSP_QSPI_EnableMemoryMappedMode(void)", the command-address-data is set to 1-1-4 which is for extended SPI, and dummy cycle set for 10, which is intended for Quad SPI mode as mentioned in the memory datasheet. However, according to the datasheet, dummy cycle configuration for extended SPI should be 8. Therefore, I suggest changing the "DUMMY_CLOCK_CYCLES_READ_QUAD" to 8 in the "quadspi.h" and see if the issue persists.
Please let me know if the issue is solved or not?
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-05-31 02:34 AM
Hello @Aurentiaco ,
In the driver code "quadspi.c", specifically in the the function "CSP_QSPI_EnableMemoryMappedMode(void)", the command-address-data is set to 1-1-4 which is for extended SPI, and dummy cycle set for 10, which is intended for Quad SPI mode as mentioned in the memory datasheet. However, according to the datasheet, dummy cycle configuration for extended SPI should be 8. Therefore, I suggest changing the "DUMMY_CLOCK_CYCLES_READ_QUAD" to 8 in the "quadspi.h" and see if the issue persists.
Please let me know if the issue is solved or not?
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-05-31 03:18 AM
I don't see where the instruction is written into sCommand structure. I'd also recommend clearing it on the stack so it doesn't continue any junk values.
Check the dummy cycles match those that are defined or configured in the device.
These cycles are used to prefect content from the array so they can be streamed back to you.
For data arriving late check dummy cycles or 3 or 4 byte address mode settings
2024-05-31 03:42 AM
That works thank you so much for your help.