summaryrefslogtreecommitdiffstats
path: root/bsps/shared
diff options
context:
space:
mode:
authorKinsey Moore <kinsey.moore@oarcorp.com>2023-05-24 13:56:41 -0500
committerJoel Sherrill <joel@rtems.org>2023-06-08 09:48:44 -0500
commit7a14c3df8bdeee722022b3353723bde2973f445e (patch)
tree42d5bac9f7629edaec74ba2d77e0247ee050d305 /bsps/shared
parentbsps/xqspipsu: Correct s25fl512s flash definition (diff)
downloadrtems-7a14c3df8bdeee722022b3353723bde2973f445e.tar.bz2
bsps/xqspipsu: Calculate erase sectors correctly
When given the exact bounds of a sector, the current algorithm calculates that 3 sectors need to be erased. This corrects the calculation such that only 1 sector needs to be erased for erasures that exactly match sector boundaries.
Diffstat (limited to 'bsps/shared')
-rw-r--r--bsps/shared/dev/spi/xqspipsu-flash-helper.c19
1 files changed, 3 insertions, 16 deletions
diff --git a/bsps/shared/dev/spi/xqspipsu-flash-helper.c b/bsps/shared/dev/spi/xqspipsu-flash-helper.c
index 0c1a9ffd2a..cb705ab505 100644
--- a/bsps/shared/dev/spi/xqspipsu-flash-helper.c
+++ b/bsps/shared/dev/spi/xqspipsu-flash-helper.c
@@ -534,22 +534,18 @@ int QspiPsu_NOR_Erase(
u32 NumSect;
int Status;
u32 SectSize;
- u32 SectMask;
WriteEnableCmd = WRITE_ENABLE_CMD;
if(QspiPsuPtr->Config.ConnectionMode == XQSPIPSU_CONNECTION_MODE_PARALLEL) {
- SectMask = (Flash_Config_Table[FCTIndex]).SectMask - (Flash_Config_Table[FCTIndex]).SectSize;
SectSize = (Flash_Config_Table[FCTIndex]).SectSize * 2;
NumSect = (Flash_Config_Table[FCTIndex]).NumSect;
} else if (QspiPsuPtr->Config.ConnectionMode == XQSPIPSU_CONNECTION_MODE_STACKED) {
NumSect = (Flash_Config_Table[FCTIndex]).NumSect * 2;
- SectMask = (Flash_Config_Table[FCTIndex]).SectMask;
SectSize = (Flash_Config_Table[FCTIndex]).SectSize;
} else {
SectSize = (Flash_Config_Table[FCTIndex]).SectSize;
NumSect = (Flash_Config_Table[FCTIndex]).NumSect;
- SectMask = (Flash_Config_Table[FCTIndex]).SectMask;
}
/*
@@ -614,18 +610,9 @@ int QspiPsu_NOR_Erase(
/*
* Calculate no. of sectors to erase based on byte count
*/
- NumSect = (ByteCount / SectSize) + 1;
-
- /*
- * If ByteCount to k sectors,
- * but the address range spans from N to N+k+1 sectors, then
- * increment no. of sectors to be erased
- */
-
- if (((Address + ByteCount) & SectMask) ==
- ((Address + (NumSect * SectSize)) & SectMask)) {
- NumSect++;
- }
+ u32 SectorStartBase = RTEMS_ALIGN_DOWN(Address, SectSize);
+ u32 SectorEndTop = RTEMS_ALIGN_UP(Address + ByteCount, SectSize);
+ NumSect = (SectorEndTop - SectorStartBase)/SectSize;
for (Sector = 0; Sector < NumSect; Sector++) {