A couple of bugfixes

This commit is contained in:
dario 2024-06-14 16:39:42 +02:00
parent e2adee029e
commit 789fa4cd3e
5 changed files with 42 additions and 46 deletions

View File

@ -209,7 +209,7 @@ namespace sta
* @remarks Afterwards, the device won't accept any instructions for a duration T_SE. This can be checked * @remarks Afterwards, the device won't accept any instructions for a duration T_SE. This can be checked
* by reading the busy bit. * by reading the busy bit.
* *
* @param address The address of the sector to erase. * @param address The number of the sector to erase. Here, 0 is the first sector, 1 the second and so on.
* @return bool Returns 1 if the operation was successful, 0 otherwise. * @return bool Returns 1 if the operation was successful, 0 otherwise.
*/ */
uint8_t sectorErase(uint32_t address); uint8_t sectorErase(uint32_t address);

View File

@ -39,12 +39,14 @@
#define W25QXX_PAGE_PROGAM 0x02 #define W25QXX_PAGE_PROGAM 0x02
#define W25QXX_QUAD_PAGE_PROGAM 0x32 #define W25QXX_QUAD_PAGE_PROGAM 0x32
#define W25QXX_SECTOR_ERASE 0x21 #define W25QXX_SECTOR_ERASE 0x20
#define W25QXX_BLOCK_ERASE_32_KB 0x52 #define W25QXX_BLOCK_ERASE_32_KB 0x52
#define W25QXX_BLOCK_ERASE_64_KB 0xD8 #define W25QXX_BLOCK_ERASE_64_KB 0xD8
#define W25QXX_READ 0x03 #define W25QXX_READ 0x03
#define W25QXX_READ_32_BIT 0x13
#define W25QXX_FAST_READ 0x0B #define W25QXX_FAST_READ 0x0B
#define W25QXX_FAST_READ_32_BIT 0x0C
#define W25QXX_FAST_READ_DUAL_OUT 0x3B #define W25QXX_FAST_READ_DUAL_OUT 0x3B
#define W25QXX_FAST_READ_QUAD_OUT 0x6B #define W25QXX_FAST_READ_QUAD_OUT 0x6B
#define W25QXX_SFDP_REG 0x5A #define W25QXX_SFDP_REG 0x5A

View File

@ -81,10 +81,10 @@ namespace sta
uint32_t address_; uint32_t address_;
uint8_t buffer_[W25QXX_PAGE_SIZE]; uint8_t buffer_[W25QXX_PAGE_SIZE];
uint8_t ptr_; uint32_t ptr_;
}; };
} // namespace sta } // namespace sta
#include <sta/utils/logger.tpp> #include <sta/utils/logger.tpp>
#endif // STA_UTILS_LOGGER_HPP #endif // STA_UTILS_LOGGER_HPP

View File

@ -49,7 +49,7 @@ namespace sta
// Convert the data to a byte array. // Convert the data to a byte array.
uint8_t * bytes = reinterpret_cast<uint8_t*>(&data); uint8_t * bytes = reinterpret_cast<uint8_t*>(&data);
uint8_t length = sizeof(T); uint32_t length = sizeof(T);
// Bytes remaining until the page is full. // Bytes remaining until the page is full.
uint8_t remaining = W25QXX_PAGE_SIZE - ptr_; uint8_t remaining = W25QXX_PAGE_SIZE - ptr_;
@ -89,14 +89,6 @@ namespace sta
ptr_ = 0; ptr_ = 0;
flash_->sectorErase(address_); flash_->sectorErase(address_);
/*
for (uint32_t i = start_; i < end_; i++)
{
flash_->sectorErase(i * W25QXX_SECTOR_SIZE);
}
*/
} }
template <typename T> template <typename T>

View File

@ -101,13 +101,6 @@ namespace sta
} }
middle = (left + right) / 2; middle = (left + right) / 2;
readData(middle * bytes, buffer, bytes);
if (criterion(buffer))
{
middle += 1;
}
delete[] buffer; delete[] buffer;
return middle * bytes; return middle * bytes;
@ -190,25 +183,34 @@ namespace sta
uint8_t instruction = fast ? W25QXX_FAST_READ : W25QXX_READ; uint8_t instruction = fast ? W25QXX_FAST_READ : W25QXX_READ;
// In fast mode we have to send a 8 dummy clock cycles first.
if (fast)
{
// TODO
}
while (isBusy()) {} while (isBusy()) {}
// Depending on address mode, send 3 bytes or 4 bytes. // Depending on address mode, send 3 bytes or 4 bytes.
if (addrMode_ == AddressMode::_32BIT) if (addrMode_ == AddressMode::_32BIT)
{ {
uint8_t addrBuffer[4] = { if (fast)
(uint8_t) (address >> 24), {
(uint8_t) (address >> 16), uint8_t addrBuffer[5] = {
(uint8_t) (address >> 8), (uint8_t) (address >> 24),
(uint8_t) (address) (uint8_t) (address >> 16),
}; (uint8_t) (address >> 8),
(uint8_t) (address),
0x00 // Dummy byte for fast mode
};
return busRead(instruction, buffer, length, addrBuffer, 4); return busRead(instruction, buffer, length, addrBuffer, 5);
}
else
{
uint8_t addrBuffer[5] = {
(uint8_t) (address >> 24),
(uint8_t) (address >> 16),
(uint8_t) (address >> 8),
(uint8_t) (address)
};
return busRead(instruction, buffer, length, addrBuffer, 4);
}
} }
else else
{ {
@ -433,24 +435,24 @@ namespace sta
if (addrMode_ == AddressMode::_32BIT) if (addrMode_ == AddressMode::_32BIT)
{ {
uint8_t addrBuffer[4] = { uint8_t addrBuffer[4] = {
(uint8_t) (address >> 24), (uint8_t) (address >> 24),
(uint8_t) (address >> 16), (uint8_t) (address >> 16),
(uint8_t) (address >> 8), (uint8_t) (address >> 8),
(uint8_t) (address) (uint8_t) (address)
}; };
return busWrite(W25QXX_SECTOR_ERASE, addrBuffer, 4); return busWrite(W25QXX_SECTOR_ERASE, addrBuffer, 4);
} }
else else
{ {
uint8_t addrBuffer[3] = { uint8_t addrBuffer[3] = {
(uint8_t) (address >> 16), (uint8_t) (address >> 16),
(uint8_t) (address >> 8), (uint8_t) (address >> 8),
(uint8_t) (address) (uint8_t) (address)
}; };
return busWrite(W25QXX_SECTOR_ERASE, addrBuffer, 3); return busWrite(W25QXX_SECTOR_ERASE, addrBuffer, 3);
} }
return 1; return 1;