I've noticed that the driver library does not properly unprotect sectors of flash when the base address is greater than 0x7FFF. I've tracked the issue to the dl_flashctl.c file in the latest sdk.
I'm pretty sure this is a typo, but can someone confirm whether the math in the unprotectSector function is correct or not?
An earlier version of the code was "sectorMask = (uint32_t) 1 << ((sectorNumber - (uint32_t) 32) / (uint32_t) 8);" and was replaced by sectorMask = ((uint32_t) 1 << ((sectorInBank - (uint32_t) 32 / (uint32_t) 8)));
The parenthesis do not appear to be correct. Earlier the math evaluated to (sector - 32) / 8 and is now (sector - 4).
Here's the entire function for additional context:
void DL_FlashCTL_unprotectSector(FLASHCTL_Regs *flashctl, uint32_t addr,
DL_FLASHCTL_REGION_SELECT regionSelect)
{
uint32_t sectorNumber = DL_FlashCTL_getFlashSectorNumber(flashctl, addr);
uint32_t sectorInBank =
DL_FlashCTL_getFlashSectorNumberInBank(flashctl, addr);
uint32_t sectorMask;
if ((uint32_t) regionSelect == FLASHCTL_CMDCTL_REGIONSEL_MAIN) {
if (sectorNumber < (uint32_t) 32) {
sectorMask = (uint32_t) 1 << sectorNumber;
flashctl->GEN.CMDWEPROTA &= ~sectorMask;
} else {
/* Use CMDWEPROTB */
if (sectorInBank < (uint32_t) 256) {
/* Single bank system */
if (DL_FactoryRegion_getNumBanks() == (uint32_t) 1) {
sectorMask =
((uint32_t) 1 << ((
sectorInBank - (uint32_t) 32 / (uint32_t) 8)));
flashctl->GEN.CMDWEPROTB &= ~sectorMask;
} else { /* Multi bank system */
sectorMask = (uint32_t) 1 << (sectorInBank / (uint32_t) 8);
flashctl->GEN.CMDWEPROTB &= ~sectorMask;
}
}
/* Use CMDWEPROTC */
else if (sectorInBank < (uint32_t) 511) {
sectorMask =
((uint32_t) 1
<< ((sectorInBank - (uint32_t) 256) / (uint32_t) 8));
flashctl->GEN.CMDWEPROTC &= ~sectorMask;
} else {
; /* Not expected to reach this else statement */
}
}
} else if ((uint32_t) regionSelect == FLASHCTL_CMDCTL_REGIONSEL_NONMAIN) {
sectorMask = (uint32_t) 1 << (sectorNumber % (uint32_t) 32);
flashctl->GEN.CMDWEPROTNM &= ~sectorMask;
} else {
; /* Not expected to reach this else statement */
}
}