shifting on the written data to external flash using qspi
this is the code in the main that test the drive my stm32h750vb which is connected to the winbond25Q256jv external flash which is connected using qspi :
/* USER CODE BEGIN 2 */
uint8_t buffer_test[MEMORY_SECTOR_SIZE];
uint32_t var = 0;
CSP_QUADSPI_Init();
//CSP_QSPI_Erase_Chip();
for (var = 0; var < MEMORY_SECTOR_SIZE; var++) {
buffer_test[var] = (var & 0xff);
}
for (var = 0; var <= SECTORS_COUNT; var++) {
if (CSP_QSPI_EraseSector(var * MEMORY_SECTOR_SIZE,
((var + 1) * MEMORY_SECTOR_SIZE)) != HAL_OK) {
while (1)
; //breakpoint - error detected
}
HAL_Delay(10);
if (CSP_QSPI_WriteMemory(buffer_test, var * MEMORY_SECTOR_SIZE, sizeof(buffer_test)) != HAL_OK) {
while (1)
; //breakpoint - error detected
}
}
if (CSP_QSPI_EnableMemoryMappedMode() != HAL_OK) {
while (1)
; //breakpoint - error detected
}
uint32_t error_count = 0;
for (var = 0; var < SECTORS_COUNT; var++) {
uint8_t* sector_start = (uint8_t*) (0x90000000 + var * MEMORY_SECTOR_SIZE);
for (uint32_t byte_num = 0; byte_num < MEMORY_SECTOR_SIZE; byte_num++) {
if (buffer_test[byte_num] != sector_start[byte_num]) {
error_count++;
printf("Data corruption detected at sector %lu, byte %lu, memory address 0x%08lx: expected %02X, found %02X\n", var, byte_num, (uint32_t)(sector_start + byte_num), buffer_test[byte_num], sector_start[byte_num]);
}
}
}
printf("Total bytes with corrupted data: %lu\n", error_count);
/* USER CODE END 2 */
and the ouput of the printing is :
Data corruption detected at sector 0, byte 0, memory address 0x90000000: expected 00, found 01
Data corruption detected at sector 0, byte 1, memory address 0x90000001: expected 01, found 02
Data corruption detected at sector 0, byte 2, memory address 0x90000002: expected 02, found 03
Data corruption detected at sector 0, byte 3, memory address 0x90000003: expected 03, found 04
and so on which means there is a shifting by one but when i make the whole array have the same number like this :
for (var = 0; var < MEMORY_SECTOR_SIZE; var++) {
buffer_test[var] = 55;
}
there is no shifting and the data is written correctly which is weird.
here is the code of the writing function:
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_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;
}
what could be the problem ??
