Skip to main content
Visitor II
November 23, 2021
Question

Cannot erase memory

  • November 23, 2021
  • 7 replies
  • 3107 views

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.

    This topic has been closed for replies.

    7 replies

    Super User
    November 23, 2021

    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?

    dv.13Author
    Visitor II
    November 23, 2021

    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.

    Visitor II
    November 23, 2021

    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.13Author
    Visitor II
    November 24, 2021

    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);​

    Visitor II
    November 24, 2021

    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

    Visitor II
    November 24, 2021

    FLASH_WaitForLastOperation is executed directly into HAL_FLASH_Program

    dv.13Author
    Visitor II
    November 25, 2021

    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.

    Visitor II
    November 25, 2021
    dv.13Author
    Visitor II
    November 29, 2021

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