cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to erase flash using bootloader via UART command

Anilkumar1011
Associate

Hi All,

Part number: STM32G0B0

Flash : 512KBytes

This chip supporting only extended erase (0x44) command. Its working perfectly fine for Full chip erase(0xFFFF) , Bank-1(0xFFFE) and Bank-2(0xFFFD). But facing issue when try to erase specific memory/number of page.

Logs as following:

I (3137) : stm_pro_mode (resetSTM_to_enter_boot_mode:104) Enter boot mode
 I (3137) : stm_pro_mode (cmdSync:144) SYNC
  I (3137) : stm_pro_mode (sendBytes:267) 0x79
I (3147) : stm_pro_mode (sendBytes:271) Sync Success
I (3147) : stm_pro_mode (cmdGet:153) GET
I (3157) : stm_pro_mode (sendBytes:267) 0x79
I (3167) : stm_pro_mode (sendBytes:271) GET Success
I (3167) : stm_pro_mode (cmdVersion:162) GET VERSION 
I (3177) : stm_pro_mode (sendBytes:267) 0x79
I (3187) : stm_pro_mode (sendBytes:271) GET VERSION read command success
I (3187) : stm_pro_mode (cmdId:171) CHECK ID
I (3197) : stm_pro_mode (sendBytes:267) 0x79
I (3207) : stm_pro_mode (sendBytes:271) CHECK ID command Success

I (3227) : stm_pro_mode (cmdExtErase:196) EXTENDED ERASE MEMORY
I (3247) : stm_pro_mode (sendBytes:267) 0x79

Here Extended erase failed when send customize erase 

Page number to be erase : 10 pages

start address of page        : page -0 (0x8000000)

code :

int cmdExtErase(void)
{
     int i =0;
    char checksum = 0;
    uint8_t pg_byte  = 0;
    uint8_t pg_num = 0;
    char buf[23];   // 2+2*(pages)+1
    int resp = 1;
   int pages = 10;
  uint8_t spage = 0;
  char bytes[] = {0x44, 0xBB};
 
  logI(TAG_STM_PRO, "%s", "EXTENDED ERASE MEMORY");
  int status = sendBytes(bytes, sizeof(bytes), resp);
  if (status == 1)
 {
      // Specific range of memory erase
     logI(TAG_STM_PRO, "%d", pages);
 
      //MSB of page number
     pg_byte  = (pages -1 ) >> 8;
     buf[i++] = pg_byte;
    checksum ^= pg_byte;
    pg_byte = (pages - 1) & 0xFF;
   
   //LSB of page number
   buf[i++] = pg_byte;
   checksum ^= pg_byte;
  
   // page numbers (0 to 10)
   // page start from 0 
   for (pg_num = spage; pg_num <( spage + pages); pg_num++)
  {
      pg_byte = pg_num >> 8;
      checksum ^= pg_byte;
      buf[i++] = pg_byte;
      pg_byte = pg_num & 0xFF;
      checksum ^= pg_byte;
      buf[i++] = pg_byte;
  }
    buf[i++] = checksum;
    return sendBytes(buf, sizeof(buf), resp);
 }
return 0;
}
 
Kindly review and suggest.
 
Thanks,
Anil

 

 

 

 

2 REPLIES 2
TDK
Guru

Can you output the bytes you're sending and receiving? That's going to be a lot easier than interpreting code.

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

Hi Guru,

For extended erase sending following data

Send part 1:

0x44 0xBB

output : 0x79   (Received  ACK)

Send part 2:

|total page count- to be erase | pages | checksum

00 04 00 00 00 01 00 02 00 04 00 05 06

output : time out 

for timeout error, tried different timeout 3/5/10 seconds but other command working perfectly fine.

Thanks,

Anil