0

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 and why there is no shifiting if the array contian similar data?

Bosz
  • 359
  • 6
  • 15
  • 1
    Can you clarify what you mean by "shifting"? Because when I worked with QSPI, shifting usually meant half a cycle data vs clock line delay, physically on the lines. Here you mean something else. Let's make sure we are all talking about the same thing. – Ilya Jul 01 '23 at 07:06
  • i figured out the when i write on the address 0x90000000 on my winbond 25q256 external flash the data of the first byte dosn't get written at all so if i write 0x00010203 at the first 4 byte the data that get written at the first four byte is 0x01020304 so i start writing from 0x90000001 then i found data is written on the 0x90000000 don't know why but that solved the problem . – Ahmed Elsayed Jul 01 '23 at 15:47
  • 1
    Add some dummy cycles, it probably ignores the first data byte mistaking it for the last 2 dummy cycles. Add 2, see if anything happens – Ilya Jul 01 '23 at 18:31

0 Answers0