cancel
Showing results for 
Search instead for 
Did you mean: 

Backup register not working on STM32F105RC

vedprakash
Associate
Posted on September 30, 2011 at 08:33

I am using STM32F105RC microcontroller on a custom designed board, the microcontroller runs at 72MHz, no crystal (& its decoupling caps) is connected for RTC, CR2032 3V battery is connected to Vbat directly (no other circuit like diode between Vbat & Vdd is present). I am using IAR embedded workbench.

The code is as follows:

&sharpinclude ''stm32f10x.h''

&sharpinclude <intrinsics.h>

&sharpinclude ''global.h''

&sharpinclude ''stm32f10x_rtc.h''

&sharpinclude ''stm32f10x_bkp.h''

int main()

{

    GPIO_InitTypeDef GPIO_InitStructure;

    SystemInit();

     

&sharpifndef  EMB_FLASH

  /* Set the Vector Table base location at 0x20000000 */

  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);

&sharpelse  /* VECT_TAB_FLASH  */

  /* Set the Vector Table base location at 0x08000000 */

  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x1000);

&sharpendif

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

   

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |        

                         RCC_APB2Periph_GPIOB |

                         RCC_APB2Periph_GPIOC |

                         RCC_APB2Periph_GPIOD,

                         ENABLE);

  RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA |

                         RCC_APB2Periph_GPIOB |

                         RCC_APB2Periph_GPIOC |

                         RCC_APB2Periph_GPIOD,

                         DISABLE);

 

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;        

 

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

   

  GPIO_WriteBit(GPIOA,GPIO_Pin_0 ,Bit_RESET);  

 

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); 

  PWR_BackupAccessCmd(ENABLE); 

/*  if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) 

  {

    BKP_DeInit();

    BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);

  }*/

  while(1)

  {

      if (BKP_ReadBackupRegister(BKP_DR1) == 0xA5A5)

      {

          GPIO_WriteBit(GPIOA,GPIO_Pin_0 ,Bit_SET);   

      }

  }

}

I test it as follows:

When the commented code is uncommented (the code beginning with if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)), then program is compiled & run in debug mode, the LED connected to GPIO_Pin_0 glows. When the board is not powered off, code is commented again (as shown above) & code is run in debug mode, the LED still glows. But if the board is powered off & turned on again, the LED does not glow. It seems the backup registers are not working.

Can you please help me to solve this problem?

Thanks in advance!

#stm32 #backup-register
2 REPLIES 2
domen23
Associate II
Posted on October 03, 2011 at 15:38

Put a RCC_BackupResetCmd(DISABLE); before any BKP routines.

It will bring BKP out of reset.
vedprakash
Associate
Posted on October 14, 2011 at 09:30

Thanks so much, Domen. And please excuse for the long delay.

I tried adding RCC_BackupResetCmd(DISABLE); before

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); but there is no change in observation.

I made one observation. When the controller is reset using IDE (debug mode) the backup registersretains data & the LED glows (as per the sw written above). When i take the power off, they do not retain data (& the LED does not glow). But when i reset the controller using the reset pin (NRSTpin) then the backup registers retain data.

It behaves as if there is no battery.

Could you please see if i missed anything in the software?

Also, i attached the schematic, could there be anything wrong in the hardware? Earlier i had connected a 768KHz crystal for the RTC (with its decoupling caps). And i was using the PC13 pin as GPIO for reading a digital switch. The switch was pulled up to 3V3 and had a 100nF capacitor across it.

Could it be possible that more current was drawn from the internal switch (between Vbat & Vdd) than 3mA which might have resulted in the switch getting damaged? Is there any way of checking it?

Now i have removed the external crystal, its decoupling caps, the switch & its circuit. But the behaviour is same.

________________

Attachments :

sch.JPG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I14Y&d=%2Fa%2F0X0000000blg%2FgH01NSLW2wpPEtfD6BTqzLquifojJFCOa5uE4gUUmhE&asPdf=false