mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/driver-w25qxxx.git
synced 2025-08-02 12:31:54 +00:00
Added block lock and unlock implementation
This commit is contained in:
parent
b28e15daff
commit
28f1f1ecce
@ -58,12 +58,32 @@ namespace sta
|
|||||||
*/
|
*/
|
||||||
uint8_t setAddressMode(AddressMode addrMode);
|
uint8_t setAddressMode(AddressMode addrMode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the Address Mode object
|
||||||
|
*
|
||||||
|
* @return AddressMode
|
||||||
|
*/
|
||||||
AddressMode getAddressMode();
|
AddressMode getAddressMode();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the Chip I D object
|
||||||
|
*
|
||||||
|
* @return uint8_t
|
||||||
|
*/
|
||||||
uint8_t getChipID();
|
uint8_t getChipID();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the Manufacturer I D object
|
||||||
|
*
|
||||||
|
* @return uint8_t
|
||||||
|
*/
|
||||||
uint8_t getManufacturerID();
|
uint8_t getManufacturerID();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the Unique I D object
|
||||||
|
*
|
||||||
|
* @return uint64_t
|
||||||
|
*/
|
||||||
uint64_t getUniqueID();
|
uint64_t getUniqueID();
|
||||||
|
|
||||||
// TODO: SFDP register?
|
// TODO: SFDP register?
|
||||||
@ -210,8 +230,10 @@ namespace sta
|
|||||||
// Read security registers
|
// Read security registers
|
||||||
|
|
||||||
// Indiv Block / Sector lock
|
// Indiv Block / Sector lock
|
||||||
|
uint8_t lockBlock(uint32_t address);
|
||||||
|
|
||||||
// Indiv Block / Sector unlock
|
// Indiv Block / Sector unlock
|
||||||
|
uint8_t unlockBlock(uint32_t address);
|
||||||
|
|
||||||
// Indiv Block / Sector lock read
|
// Indiv Block / Sector lock read
|
||||||
|
|
||||||
|
@ -146,6 +146,8 @@ namespace sta
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (!isWriteEnabled()) {}
|
||||||
|
|
||||||
if (addrMode_ == AddressMode::_32BIT)
|
if (addrMode_ == AddressMode::_32BIT)
|
||||||
{
|
{
|
||||||
uint8_t addrBuffer[4] = {
|
uint8_t addrBuffer[4] = {
|
||||||
@ -256,6 +258,8 @@ namespace sta
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (!isWriteEnabled()) {}
|
||||||
|
|
||||||
if (!nonvolatile)
|
if (!nonvolatile)
|
||||||
{
|
{
|
||||||
uint8_t rslt = writeVolatileEnable();
|
uint8_t rslt = writeVolatileEnable();
|
||||||
@ -286,7 +290,10 @@ namespace sta
|
|||||||
|
|
||||||
bool W25Qxx::isWriteEnabled()
|
bool W25Qxx::isWriteEnabled()
|
||||||
{
|
{
|
||||||
return true; // TODO
|
uint8_t status = 0;
|
||||||
|
readStatusRegister(1, &status);
|
||||||
|
|
||||||
|
return (0x02 && status) == 0x02;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t W25Qxx::sectorErase(uint32_t address)
|
uint8_t W25Qxx::sectorErase(uint32_t address)
|
||||||
@ -296,6 +303,8 @@ namespace sta
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (!isWriteEnabled()) {}
|
||||||
|
|
||||||
if (addrMode_ == AddressMode::_32BIT)
|
if (addrMode_ == AddressMode::_32BIT)
|
||||||
{
|
{
|
||||||
uint8_t addrBuffer[4] = {
|
uint8_t addrBuffer[4] = {
|
||||||
@ -328,6 +337,8 @@ namespace sta
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (!isWriteEnabled()) {}
|
||||||
|
|
||||||
uint8_t instruction = blockSize == BlockSize::_32KB ? W25QXX_BLOCK_ERASE_32_KB : W25QXX_BLOCK_ERASE_64_KB;
|
uint8_t instruction = blockSize == BlockSize::_32KB ? W25QXX_BLOCK_ERASE_32_KB : W25QXX_BLOCK_ERASE_64_KB;
|
||||||
|
|
||||||
if (addrMode_ == AddressMode::_32BIT)
|
if (addrMode_ == AddressMode::_32BIT)
|
||||||
@ -389,4 +400,40 @@ namespace sta
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t W25Qxx::lockBlock(uint32_t address)
|
||||||
|
{
|
||||||
|
if (!writeEnable())
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!isWriteEnabled()) {}
|
||||||
|
|
||||||
|
uint8_t addrBuffer[3] = {
|
||||||
|
(uint8_t) (address << 16),
|
||||||
|
(uint8_t) (address << 8),
|
||||||
|
(uint8_t) (address)
|
||||||
|
};
|
||||||
|
|
||||||
|
return busWrite(W25QXX_INDIV_BLOCK_LOCK, addrBuffer, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t W25Qxx::unlockBlock(uint32_t address)
|
||||||
|
{
|
||||||
|
if (!writeEnable())
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!isWriteEnabled()) {}
|
||||||
|
|
||||||
|
uint8_t addrBuffer[3] = {
|
||||||
|
(uint8_t) (address << 16),
|
||||||
|
(uint8_t) (address << 8),
|
||||||
|
(uint8_t) (address)
|
||||||
|
};
|
||||||
|
|
||||||
|
return busWrite(W25QXX_INDIV_BLOCK_UNLOCK, addrBuffer, 3);
|
||||||
|
}
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
Loading…
x
Reference in New Issue
Block a user