cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot erase memory

dv.13
Associate II

Hi Team,

We are building a Braille Display for the Blind people, for the device, we are trying to give IAP through SD card on our board.

My problem is whenever we try to erase or program the STM32H753 chip, the program comes out of Debugger at the first occurance of FLASH_WaitForLastOperation in the HAL_FLASHEx_Erasefunction. Keil gives " cannot access target. Shutting down Debug session" error.

I have tried commenting the Erase function and then running the code. but then it gives same error in the programming function.

Instead of using my code, I have also tried the code that comes with your eval board (STM32Cube_FW_H7_V1.5.0) but same thing happens.

I have changed the chip twice but invein.

Please suggest the remedy for this ASAP, as we are running out of time.

9 REPLIES 9
TDK
Guru

Are you erasing flash still in use by the program?

If you run the program without a debugger, does it work? If not, where in the process does it fail?

If you feel a post has answered your question, please click "Accept as Solution".
dv.13
Associate II

Hi,

My bootloader program is at 0x8000000. And I am erasing the memory from 0x8020000​.​

The program does not work even without the debugger. It stucks at the same point, this I can assume because I have toggled the LED before and after the erase function. And the LED does not turn off.

simosilva
Senior

With the following lines it works fine for erase one entire sector with same MCU family:

FLASH_Erase_Sector(FLASH_SECTOR_0, FLASH_BANK_1, FLASH_VOLTAGE_RANGE_3); 
 
FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_1); /* Wait for last operation to be completed */

works with any FLASH_SECTOR_n

dv.13
Associate II

Hi Simosilva,

The erase function worked fine. Do we have a similar function for programming also? Because it gives the same error (flash_waitforlastoperation) for HAL_FLASH_Program(Flash_TYPEPROGRAM_FLASHWORD, address, 32 bit data);​

simosilva
Senior

Sure.

  for (i = 0; (i < BufLen) && (*FlashAddress <= (USER_FLASH_END_ADDRESS-4)); i++)
  {
    HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, *FlashAddress, (uint32_t)(pBuf+i));
    {
     /* Check the written value */
      if (*(uint32_t*)*FlashAddress != *(uint32_t*)(pBuf+i))
      {
        /* Flash content doesn't match SRAM content */
        return(2);
      }
      /* Increment FLASH address */
      *FlashAddress += 4;
    }
  }

Every write must be 32 bit alligned, the pBuf point to a uint32_t array containing the buffer to be written.

Programming without the FLASH_WaitForLastOperation works fine.

Try it and let me know

FLASH_WaitForLastOperation is executed directly into HAL_FLASH_Program

dv.13
Associate II

Hi Simosilva,

Programming worked fine. Thanks for the help.

Now my next code is​

​jumpadd = *(__IO uint 32_t*) (FLASH_USER_START_ADDRESS+4);

Jump = (pFunction) jumped;

__set_MSP(*(__IO uint32_t*) FLASH_USER_START_ADDRESS);

Jump();

Right?

The binary file is having VECT_TAB_OFFSET 0x00020000UL

And

SCB->VTOR = FLASH_BANK1_BASE| | VECT_TAB_OFFSET;

Do we need to define anything else?

Because on Jump(); my code gives hardfault and enters in HardFault_Handler.

simosilva
Senior

No luck... The program still enters in hard fault handler at jump....​