2025-09-17 8:26 AM - last edited on 2025-09-17 9:20 AM by mƎALLEm
Hi all!
AGENDA: Need to verify the external QSPI flash (AT25Q128A) all sectors Write, Read and Comparing with STM32L496ZG-P using driver code.
APPROACH: For write, I am have created a buffer which comprises of page size of 256, and I am using two "for" loops one outer "for" loop for incrementing total sectors i.e. 4096 times and inner "for' loop as there are 16 pages for a single sector I am incrementing it to 16 times.
In below case I am trying to write letter O to all sectors and read and compare,
// Fill buffer with character 'O'
for (int i = 0; i < PAGE_SIZE; i++) {
page_buffer[i] = 'O';
}
for (uint32_t sector = 0; sector < TOTAL_SECTORS; sector++) {
uint32_t base_address = sector * SECTOR_SIZE;
for (uint32_t page = 0; page < PAGES_PER_SECTOR; page++) {
uint32_t page_address = base_address + (page * PAGE_SIZE);
//// Write to flash
if (CSP_QSPI_WriteMemory((uint8_t*)page_buffer, page_address, PAGE_SIZE) != HAL_OK) {
// flash_write_success = false; // Error in writing
Error_Handler();
}
//// Read back
if (CSP_QSPI_Read((uint8_t*)read_buffer, page_address, PAGE_SIZE) != HAL_OK) {
// flash_write_success = false; // Error in reading
Error_Handler();
}
// if(read_buffer[7]!='O')
// {
// Error_Handler();
// }
}
}
For reading, I am trying to read the written char from the same location I have stored in the same for loop and comparing using if condition.
BUG: During line by line debugging when verified in live expression, the read buffer is storing the written value 'O'. but if I select run in the debug session, read buffer is not storing any values it is displaying y(two dots above y with , 255). And for verification of reading i have commented the write function and erase chip function, and again i have flashed the code, this time also the read buffer is not reading the written data at the location. Using the same code(with write and read functions present inside the for loops ), when i verified with the cube programmer and on pressing the read icon, the data written data is reading at defined memory locations, even tried powering it off and on, still data is retaining, but main motive of task is to verify the memory sectors using driver not with cube programmer.
Kindly help me out sorting the bug to verify all the sectors of memory with driver code.
Thanks!!
Edited to apply source code formatting - please see How to insert source code for future reference.