nimaltd / spif

W25qxx, N25Qxx and other SPI FLASH driver for stm32 HAL
GNU General Public License v3.0
605 stars 174 forks source link

Sector erase not working #31

Closed YoulDHead closed 3 years ago

YoulDHead commented 3 years ago

Hello!

I have w25q512 and sector erase function does not work for me.

I think we need to use 0x21 (Sector Erase (4KB) - with 4-Byte Address) opcode instead of 0x20 (Sector Erase (4KB)) in the W25qxx_EraseSector function, or provide 3-byte address

W25qxx_Spi(0x20); if(w25qxx.ID>=W25Q256) W25qxx_Spi((SectorAddr & 0xFF000000) >> 24); W25qxx_Spi((SectorAddr & 0xFF0000) >> 16); W25qxx_Spi((SectorAddr & 0xFF00) >> 8); W25qxx_Spi(SectorAddr & 0xFF);

Cheers, Youl

YoulDHead commented 3 years ago

Similar errors in the W25qxx_WritePage and W25qxx_ReadPage functions.

For 3-byte address opcodes 4-byte addresses provided.

nimaltd commented 3 years ago

Hello. Could you solve it please and send to me. i don't have any board to test it yet. thanks

YoulDHead commented 3 years ago

w25qxx.zip

All constructions like

W25qxx_Spi(0x0B); if(w25qxx.ID>=W25Q256) W25qxx_Spi((Page_Address & 0xFF000000) >> 24); W25qxx_Spi((Page_Address & 0xFF0000) >> 16); W25qxx_Spi((Page_Address& 0xFF00) >> 8); W25qxx_Spi(Page_Address & 0xFF);

Changed to

if(w25qxx.ID>=W25Q256){ W25qxx_Spi(0x0C); W25qxx_Spi((Page_Address & 0xFF000000) >> 24); }else{ W25qxx_Spi(0x0B); } W25qxx_Spi((Page_Address & 0xFF0000) >> 16); W25qxx_Spi((Page_Address& 0xFF00) >> 8); W25qxx_Spi(Page_Address & 0xFF);

i.e. for IC that have more than 256 Mbit we use proper opcodes.

nimaltd commented 3 years ago

thanks