2022-09-30 03:58 AM
Hi all,
I'm trying to write in the internal flash memory of my new MCU (STM32L496VGYXP),
but FLASH_WaitLastOperation fails. The error seems to be FLASH_SR_PGSERR .
I'm sure that my code used to write flash memory is correct because in others projects it works perfectly.
In the others projects I used the following MCU:
Can this problem related with the new MCU?
What could I try to do in order to fix it?
Thanks in advance
--
Mario
Solved! Go to Solution.
2022-10-02 02:32 PM
I found the problem.
Seens that using tim17 as timerbase source and activating timer1 cause problem with internal flash.
Will be nice to know why but in any case I solved my problem
2022-09-30 08:30 AM
here some code to help you understand my problem
HAL_Init();
HAL_FLASH_Unlock();
FLASH->SR = FLASH_SR_EOP | FLASH_SR_PROGERR | FLASH_SR_WRPERR | FLASH_SR_PGAERR | FLASH_SR_SIZERR | FLASH_SR_PGSERR | FLASH_SR_MISERR | FLASH_SR_FASTERR | FLASH_SR_OPTVERR;
HAL_StatusTypeDef status = FLASH_WaitLastOperation(FLASH_ER_PRG_TIMEOUT);
here status is not ok while it should be
HAL_StatusTypeDef FLASH_WaitLastOperation(uint32_t Timeout)
{
while(FLASH->SR & FLASH_SR_BSY)
{
if(--Timeout==0) return HAL_TIMEOUT;
}
if(FLASH->SR&(FLASH_SR_PROGERR|FLASH_SR_WRPERR|FLASH_SR_PGAERR|FLASH_SR_SIZERR|FLASH_SR_PGSERR|FLASH_SR_MISERR|FLASH_SR_FASTERR))
{
FLASH->SR|=FLASH_SR_PROGERR|FLASH_SR_WRPERR|FLASH_SR_PGAERR|FLASH_SR_SIZERR|FLASH_SR_PGSERR|FLASH_SR_MISERR|FLASH_SR_FASTERR;
return HAL_ERROR;
}
if(FLASH->SR & FLASH_FLAG_EOP) FLASH->SR|=FLASH_FLAG_EOP;
return HAL_OK;
}
2022-10-01 01:38 AM
I found what is the cause of the problem but I don't understand why.
In main function, when execute HAL_Init(), I can see FLASH PGSERR flag go up. This happens because I set tim1 channel1 to pwm. If I disable timer in cube it works.
Has this sense?
Can someone said if there is some problem using timer1 and FLASH?
Thanks
2022-10-02 02:32 PM
I found the problem.
Seens that using tim17 as timerbase source and activating timer1 cause problem with internal flash.
Will be nice to know why but in any case I solved my problem
2022-10-05 01:13 PM
FLASH->SR |= ...
Again the broken read-modify-write. You only have to write/assign the bits!