2016-06-07 06:49 PM
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_WriteProtectionproject 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. stmB. #eeprom #flash #stm32l1522016-06-07 07:16 PM
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.2016-06-07 08:16 PM
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.2016-06-08 01:33 AM
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?2016-06-09 05:53 AM
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.
2016-06-09 09:41 PM
Thanks a lot, stupid mistake :)