cancel
Showing results for 
Search instead for 
Did you mean: 

how to erase stm32f030k6t6 ? after I have program ic PA13 and PA14 set as input pin. now I can't erase or debug with stlink swd . please help thanks

Mrohi
Associate III

how to erase or program using by st cube ide stm32f030k6t6 ? after I have program ic PA13 and PA14 set as input pin. now I can't erase or debug with stlink swd . please help thanks

21 REPLIES 21

32 KB Flash, 32x 1 KB pages

Shrink the memory described to the linker from 32 KB to 31 KB

The sector will be at 0x08007C00 .. 0x08007FFF

uint32_t Address = 0x08007C00;
uint32_t Data;
 
/* Variable used for Erase procedure*/
FLASH_EraseInitTypeDef EraseInitStruct;
 
// Erase
 
  /* Unlock the Flash to enable the flash control register access *************/
  HAL_FLASH_Unlock();
 
  /* Erase the user Flash area ***********/
 
  /* Fill EraseInit structure*/
  EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
  EraseInitStruct.PageAddress = Address;
  EraseInitStruct.NbPages = 1;
 
  if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)
  {
    /*
      Error occurred while page erase.
      User can add here some code to deal with this error.
      PageError will contain the faulty page and then to know the code error on this page,
      user can call function 'HAL_FLASH_GetError()'
    */
    Error_Handler();
  }
 
 
  /* Lock the Flash to disable the flash control register access (recommended
     to protect the FLASH memory against possible unwanted operation) *********/
  HAL_FLASH_Lock();
 
 
 
// Write
 
  /* Unlock the Flash to enable the flash control register access *************/
  HAL_FLASH_Unlock();
 
  if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, Data) != HAL_OK)
  {
    /* Error occurred while writing data in Flash memory.
       User can add here some code to deal with this error */
    Error_Handler();
  }
 
  /* Lock the Flash to disable the flash control register access (recommended
     to protect the FLASH memory against possible unwanted operation) *********/
  HAL_FLASH_Lock();
 
 
 
 
// Reading
 
  Data = *((uint32_t *)Address; 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Mrohi
Associate III

many thanks

my dear Clive =)

Mrohi
Associate III

dear Clive

I got 2 error

error (1).

error on line (if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)

error (PageError' undeclared (first use in this function); did you mean 'perror'?)

error (2).line Data = *((uint32_t *)Address; Syntax error

uint32_t PageError = 0;

Data = *((uint32_t *)Address);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
many thanks
Clive
Mrohi
Associate III

dear Clive

firstly many thanks your help.

  1. now I want to know how I can erase and program only Address1 = 0x08007C00;
  2. and then how I can erase and program only Address2 = 0x08007D00;
  3. it mean I don't want to erase pages just I want to erase specific address line
  4. because I need to store different 8 to 12 variable it mean I have to use 8 to 12 pages and every page is 1k bytes .so please help me.
  5. thanking you

Collect ALL your configuration information into a structure, including a sequence number, manage the data in a RAM copy and then journal that across the flash pages, selecting the last one as being valid on the read side, and then writing to the next available slot. When you've consumed the whole page, then you can erase and recover one of them.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Mrohi
Associate III

dear Clive

is there any erase function to erase specific address line ? or some easy way ?

Minimum erase size is a 1KB page.

Journalling a structure isn't unduly complicated.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Mrohi
Associate III

dear clive

I am very new just in this mcu programing field .start working with this just few month ago. so i don't know many .have to learn many thing .

now very small thing is complicated for some time.

if you will guid me how to start some code in ram. like last time very easy for me to understand everything erase function and program and read.

thanks