Skip to main content
Mrohi
Associate III
September 20, 2019
Question

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

  • September 20, 2019
  • 21 replies
  • 3903 views

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

This topic has been closed for replies.

21 replies

Tesla DeLorean
Guru
September 20, 2019

Pull BOOT0 HIGH so *your* code doesn't run

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
September 21, 2019
Mrohi
MrohiAuthor
Associate III
September 21, 2019
Thanks Clive
Now I can program and erase very easily last week problem with my stlink debugger .
Many thanks
Mrohi
MrohiAuthor
Associate III
September 21, 2019

first many thanks you are 100% right. I have finally i erase and new program fallow your instruction . last week problem with my stlink debugger pin lose contact . that's why error device not found. finally thanks now I can use this two pin as output.

Mrohi
MrohiAuthor
Associate III
September 27, 2019

dear Clive

I need your help for store int data to flash memory . I am working on stm32f030k6t6.

please help me.

thanks.

Tesla DeLorean
Guru
September 27, 2019

What like static const int array[] = { 1, 2, 3, 4, 5 }; ??

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Mrohi
MrohiAuthor
Associate III
September 28, 2019

yes dear Clive this my code and SETV is global veriable uint16_t. uint16_t SETV = 0 ;

I need to store this value in SETV after setting by user key up and dn.

in my circuit have 3 input key (1) UP (2) DN (3) SET.

UP key AND DN key is setting up and down and SET key is for store data in flash.

I don't know the sectors number in stm32f030k6t6.where to store and I don't know erase ,read write HAL instruction function

please help me thanks a lot.

I need to store value 0000 to 9999 .

/////-----------------------INTERUPT FUNCTION FOR SET KEY UP +1 AND -1 DN --------------------------

  void KEY (void)

  {

  if (HAL_GPIO_ReadPin(UP_GPIO_Port,UP_Pin)) /// press. up key +1

   {

  SETV = SETV +1;

   LD2ON;

       DT10;

            }

   else

  {

       LD2OFF;

   //INV = ADV1 ;

  }

  if (HAL_GPIO_ReadPin(DN_GPIO_Port,DN_Pin)). /// press down key for -1

    {

    SETV = SETV -1;

     LD2ON;

     DT10;

    }

     else

    {

     //INV = ADV1 ;

    LD2OFF;

           }

  }

///--------------------------------------- END INTRUPT KEY FUNCTION ---------------------------------------------------------------

Tesla DeLorean
Guru
September 28, 2019

I'd imagine much of the specifics for the part are covered in the Data Sheet or Reference Manual. I'd probably use the last sector at the end of memory, and shrink the size available to the linker. You'll need to fetch the value from memory rather that use a static definition for the value in the code.

STM32Cube_FW_F0_V1.10.1\Projects\STM32F030R8-Nucleo\Examples\FLASH\FLASH_EraseProgram     

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Mrohi
MrohiAuthor
Associate III
September 28, 2019

dear Clive first thank you very much for help.

I try to understand erase and read in reference manual near 2 hour but I can't understand .

specially erase syntax line.please can you tell me where is clear I can understand .

if you tell me 2 or 3 line example I will be oblige .

thank you very much

Tesla DeLorean
Guru
September 29, 2019

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Mrohi
MrohiAuthor
Associate III
September 29, 2019

many thanks

my dear Clive =)

Mrohi
MrohiAuthor
Associate III
September 30, 2019

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

Tesla DeLorean
Guru
September 30, 2019

uint32_t PageError = 0;

Data = *((uint32_t *)Address);

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Mrohi
MrohiAuthor
Associate III
October 1, 2019
many thanks
Clive
Mrohi
MrohiAuthor
Associate III
October 14, 2019

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

Tesla DeLorean
Guru
October 14, 2019

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Mrohi
MrohiAuthor
Associate III
October 14, 2019

dear Clive

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

Tesla DeLorean
Guru
October 14, 2019

Minimum erase size is a 1KB page.

Journalling a structure isn't unduly complicated.

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