Announcements

Webinar: Integrated solutions for smaller, simpler low-voltage motor control design.
Join the webinar to experience!

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Mario_Gt
Level 1
Level 1
5 questions asked First like given 10 sign-ins

Hi 

I am currently working on a project involving the TLE9879 MCU, and I am facing an issue with erasing a page of the code flash in my code. Strangely, I am able to program it successfully, but encounter a failure when attempting to erase it.

I would greatly appreciate any insights or suggestions regarding the potential reasons for this discrepancy. Your expertise and guidance in this matter would be immensely valuable.

Thanks
Mario

This is my main

int main(void)
{
  int i;
  uint8 *p;
  static uint16 checksum, data;
 
  /* Initialization of hardware modules based on Config Wizard configuration */
  TLE_Init();
  checksum = 0;
 
/********************************************************************/
     WDT1_SOW_Service(1u);
  
       if ( USER_CFLASH_WR_PROT_DIS(0) == 0)
       {
           //code flash no longer write protected
PORT_ChangePin(LED4, PORT_ACTION_SET);
       }
       else
       {
           //code flash still write protected, password did not match
PORT_ChangePin(LED5, PORT_ACTION_SET);
}
  /********************************************************************/
     uint8 res;
  
       WDT1_SOW_Service(1u);
  
       res = USER_ERASEPG((uint32*)ProgFlashStart + 0x8000, 0);
  
       (void)WDT1_Service();
  
       if ( ( res & 1 ) == 1 )
       {
           //erase failed
PORT_ChangePin(LED1, PORT_ACTION_SET);
       }
 
/********************************************************************/
/*     uint8 page_data[128];
  
       for ( i = 0; i < FlashPageSize; i++)
       {
           page_data[i] = i;
       }
  
       WDT1_SOW_Service(1u);
  
       if ( ProgramPage(ProgFlashStart + 0x8000, &page_data, 0, 0, 0) == 1)
       {
          USER_ERASEPG((uint32*)ProgFlashStart + 0x8000, 0);
       }
  
       (void)WDT1_Service();*/
/********************************************************************/
 
       TUser_OpenAB openab_res;
  
  
       openab_res.reg = USER_OPENAB(ProgFlashStart + 0x20000);
  
       (void)WDT1_Service();
  
       if ( openab_res.bit.ExecFail == 1 )
       {
PORT_ChangePin(LED2, PORT_ACTION_SET);
           //Assembly buffer is already open, or
           //nested NVM operation
       }
       if ( openab_res.bit.ABFail == 1 )
       {
PORT_ChangePin(LED3, PORT_ACTION_SET);
           //data flash write protected, or
           //wrong NVMPAGEAddr address, not within flash range
      }
 
/********************************************************************/
  /* Erase Data Flash sector */
  NVM_Error = USER_ERASEPG((uint32*)DataFlashStart, 0);
  
  (void)WDT1_Service();
 
  /* Check if Sector Erase passed */
  if (NVM_Error == 0u)
  {
    /* An error happened during Erase Sector */
    PORT_ChangePin(LED1, PORT_ACTION_SET);
  }
  else
  {
    /* An error happened during Erase Sector */
    PORT_ChangePin(LED8, PORT_ACTION_SET);
  }
 
  for (;;)
  {
    (void)WDT1_Service();
  }
}



0 Likes
1 Solution
LinGuohui
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 solutions authored

Hi @Mario_Gt 

It should be the code flash protection is enable.

You can disable it in config tool like this:

LinGuohui_0-1694659972442.png

 

 

View solution in original post

1 Reply
LinGuohui
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 solutions authored

Hi @Mario_Gt 

It should be the code flash protection is enable.

You can disable it in config tool like this:

LinGuohui_0-1694659972442.png