When I tried to QSPI Write first byte is missing on my Array using STM32H7
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?


