EEPROM only works in BDM mode

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

EEPROM only works in BDM mode

1,947 Views
puce_log
Contributor I
Dear group,
 
I am trying to use the internal EEPROM of a S12XDP512 chip and my driver is working perfectly in BDM mode. However, as soon as I restart the board in normal mode, the EEPROM write is not performed any more. I have check PVIOL and ACCERR flags, they are not set.
 
I have a 16 Mhz oscillator and  the PLL is configured at 40 Mhz. My setup code is as follows:
 
      #define EEP_PRDCLK   (0x01u)
      #define EEP_ECLKDIV  (0x0Au)
      vtEepromReg.ECLKDIV = (EEP_PRDCLK<<6u) + EEP_ECLKDIV;
 
      /* Pas de protection */
      vtEepromReg.EPROT=0xFF;
 
      /* attend que l'e2prom soit prete */
      while(TEST_BIT(vtEepromReg.ESTAT, ESTAT_CCIF)==0) {
        ;
      }
    
      EEP_DEVPT_ERROR_CHECK(TEST_BIT(vtEepromReg.ECLKDIV, ECLKDIV_EDIVLD)!=0, EEP_E_HW_UNINIT, tRet)
Did you already encounter a similar situation? Thank you in advance for your replies.

Best regards,
 
Puce_log
Labels (1)
0 Kudos
2 Replies

414 Views
puce_log
Contributor I
Dear group,
 
I'm sorry for the long silence. We have finally managed to solve this issue that was related to EEPROM protection.
 
We wanted to encapsulate the access to the EEPROM in a variable vtEeprom that we mapped at the right place in the memory map, as shown below. The problem is the compiler is initializing the variable at 0, which clears all EEPROM protection bits.
 
#pragma DATA_SEG EEPROM_REG
static volatile tEEPROM_DATA vtEeprom; /**< EEPROM memory area */
#pragma DATA_SEG DEFAULT
PRM file:
SEGMENTS
      EEPROM      = READ_ONLY  0x0C00 TO 0x0FFF;
PLACEMENT
     EEPROM_DATA           INTO  EEPROM;
 
In the corrected code below we have simply removed the EEP protection register from the data section considered:
#pragma DATA_SEG EEPROM_REG
static volatile tEEPROM_DATA vtEeprom; /**< EEPROM memory area */
#pragma DATA_SEG DEFAULT
const uint8 eep_prot_byte @ 0x0FFD = 0xF8 ;
 
PRM file:
SEGMENTS
      EEPROM      = READ_ONLY  0x0C00 TO 0x0FFC;
PLACEMENT
     EEPROM_DATA           INTO  EEPROM;
 
Thanks for your help, hope it works for you.
 
puce_log
0 Kudos

414 Views
Lundin
Senior Contributor IV
I have encountered such a situation where I was accidently writing to the write-once register ECLKDIV several times during setup. This doesn't work in normal single chip mode, but it will in special single chip mode (BDM attached). Check the disassembled code and make sure that the register is written to only once.

If that's not the problem, it is most likely related to the clock and prescaler settings.
0 Kudos