Skip to main content
anthony239955_st
Associate II
June 8, 2016
Question

HAL_ADC_DeInit sets the WRPERR bit in FLASH->SR register!

  • June 8, 2016
  • 5 replies
  • 1120 views
Posted on June 08, 2016 at 03:49

Hi All,

I encounter some issues with writing to eeprom on a STM32L152RET6. 

I followed the PM0062Programming manual and  if I just run my code to write to eeprom it is working fine. However, I need to run an ADC conversion. I have used cubeMx to generate the code. So In my main I have a function call to MX_ADC_Init(); which will call: 

if (HAL_ADC_DeInit(&hadc) != HAL_OK)

By doing step debugging, I can see that when I call HAL_ADC_DeInit the WRPERR bit is set in FLASH->SR.

This particular line is a problem: __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_AWD | ADC_FLAG_JEOC | ADC_FLAG_EOC |

                                ADC_FLAG_JSTRT | ADC_FLAG_STRT));

I even used the STM32Cube_FW_L1_V1.5.0\Projects\STM32L152RE-Nucleo\Examples\FLASH\FLASH_WriteProtection

project and just added ADC and I can see the same issue there (just wanted to be sure that I did have anything wrong in my code somewhere else).

Anyone already seen this kind of problem? 

I tried to clear the flag by calling: __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_WRPERR);

and it works but not sure if this is a good way of doing things.

Thanks for your help. stm

B.

#eeprom #flash #stm32l152
This topic has been closed for replies.

5 replies

Tesla DeLorean
Guru
June 8, 2016
Posted on June 08, 2016 at 04:16

Could the debugger be clouding your visibility? It is more invasive than you think.

Can you replicate the test, where you report register values to the console, instead of stepping with the debugger?

Suggest you output data via a serial connection.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
anthony239955_st
Associate II
June 8, 2016
Posted on June 08, 2016 at 05:16

Thanks for your reply.

Even if I leave the program running, I can see that eeprom write is not happening.

The FLASH->SR register is not changing. Here is the value I got after reset and after calling the infamous ''HAL_ADC_DeInit()

####################

# FLASH REGISTER #

####################

 010c 

B.

anthony239955_st
Associate II
June 8, 2016
Posted on June 08, 2016 at 10:33

We can see that theWRPERR bit is set to 1. 

I do not have any problem after calling this: 

__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_WRPERR);

any idea?

Amel NASRI
Technical Moderator
June 9, 2016
Posted on June 09, 2016 at 14:53

Hibrushtakopo,

In order to workaround this issue, you should instantiate your ADC before calling HAL_ADC_DeInit:

AdcHandle.Instance = ADC1;
HAL_ADC_DeInit(&AdcHandle);

-Mayla-
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
anthony239955_st
Associate II
June 10, 2016
Posted on June 10, 2016 at 06:41

Thanks a lot, stupid mistake :)