Skip to main content
dodonny
Associate III
January 12, 2021
Question

Error handled when using flash_emulation when compiling in c++, not present in c

  • January 12, 2021
  • 3 replies
  • 949 views

Hi,

I'm facing to a strange behaviors when I'm compiling my project in cpp but the issue disappear when compiling in c only.

The problem is on initialization of eeprom_emulation library on a STM32L476RG @ 80mhz

(line 657 of stm32l4xx_hal_flash.c) :

/**
 * @brief Wait for a FLASH operation to complete.
 * @param Timeout maximum flash operation timeout
 * @retval HAL_StatusTypeDef HAL Status
 */
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
{
 /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
 Even if the FLASH operation fails, the BUSY flag will be reset and an error
 flag will be set */
 
 uint32_t tickstart = HAL_GetTick();
 uint32_t error;
 
 while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY))
 {
 if(Timeout != HAL_MAX_DELAY)
 {
 if((HAL_GetTick() - tickstart) >= Timeout)
 {
 return HAL_TIMEOUT;
 }
 }
 }
 
 error = (FLASH->SR & FLASH_FLAG_SR_ERRORS);

The while statement is never executed and error raised is decimal 128.

As you may know it's not relatively easy to use stm32cube configuration tools when project is cpp. But it's not the subject here.

So to be clear : This error appear only when project is compiled with a main.cpp extension. The while statement is well executed when main get .c extension.

Do you have any idea how to reach out of this ?

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
January 12, 2021

Review a code disassembly to understand how the compiler generated the code differently.

Try it with a different compiler (IAR or Keil), and at different optimization levels. Could be a bug.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
dodonny
dodonnyAuthor
Associate III
January 13, 2021

Thanks,

for the moment i'm trying to deal without cpp compilation. This seems to not been completely supported by STM32CubeIDE. And I prefer to stay in the IDE rather have to deal with MakeFile.

I only need object oriented for encapsulation but with only one object... so it's manageable for the moment.

doddonny
Associate
February 16, 2021

flag