cancel
Showing results for 
Search instead for 
Did you mean: 

FLASH_WaitLastOperation and FLASH_SR_PGSERR

M4R10
Associate III

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:

  • STM32L496RGTX
  • STM32L452RETX
  • STM32L432KCUX
  • STM32L496ZGTX

Can this problem related with the new MCU?

What could I try to do in order to fix it?

Thanks in advance

--

Mario

1 ACCEPTED SOLUTION

Accepted Solutions
M4R10
Associate III

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

View solution in original post

4 REPLIES 4
M4R10
Associate III

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;

}

M4R10
Associate III

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

M4R10
Associate III

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

Piranha
Chief II
FLASH->SR |= ...

Again the broken read-modify-write. You only have to write/assign the bits!