Processor – STM32F103ZE HCLK – 24MHz PCLK2 – 24MHz Serial Flash – AT45DB321D STM32 Standard Peripheral Ver 3.1.2
I am having an unusual issue working with serial flash. I am able to read and write to serial flash buffer at any SPI baud rate (using the prescaler 2 to 256) without any problem. The reading and writing the page flash page at 12 MHz baud (using SPI prescaler 2) also works fine without any problem.
Steps followed to write flash page:
1. Write data to serial flash buffer. (Buffer 1 Write – 0x84) 2. Send command with page number to write data in buffer to flash page. (Buffer 1 To Main memory Page Program Write with builtin Erase – 0x83) 3. Wait while flash is writing page by polling the busy flag in status register. (Status Register Read – 0xD7)
Steps followed to read flash page:
1. Send command with page number to read data from flash page to buffer. (Main Memory Page To Buffer 1 Transfer – 0x53) 2. Wait while flash is reading page by polling the busy flag in status register. (Status Register Read – 0xD7) 3. Read data from serial flash buffer. ( Buffer 1 Read – 0xD4)
The problem starts when the SPI baud rate is lowered (using SPI prescalar greater than 2). The data read back has missing characters or may not read at all. The number of characters missing increases as SPI baudrate decreases.
The problem was narrowed down to issue of polling the status register to check the busy flag while serial flash chip is reading or writing the flash page. The status register can be read while normal operation. But does not return any value while serial flash chip is reading or writing the flash page and corrupt the data. The problem goes away when status flag is not polled while serial flash chip is reading or writing the flash page and enough time delay is given (page write timing as per datasheet) between page write. Now everything works fine at any SPI baud rate.
As per the datasheet it is recommended to poll status register to check if serial flash is busy while the self timed operations like erase and programming. It had worked fine with other version of Atmel serial flash I used before. I don’t know why it’s not the case here. Any info on this issue would be greatly appreciated.