cancel
Showing results for 
Search instead for 
Did you mean: 

Why RTC backup register write fails? (STM32F446)

Pavel A.
Evangelist III
Posted on January 02, 2018 at 21:01

(this is re-post because of the 'forums issue')

I have the following function to write a RTC backup register of 446ZCT:

All RTC initialization code is generated by CubeMX.

void put_backup_num(uint8_t num)

{

  __HAL_RTC_WRITEPROTECTION_DISABLE(&hrtc);

  HAL_PWR_EnableBkUpAccess();

  __HAL_RTC_WRITEPROTECTION_DISABLE(&hrtc);

  HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR18, num);

  uint32_t d = HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR18);

  if (num != (d & 0xFF) ) {

      printf('backup write failed!\n');

  }

}

and read-back always fails. Read values are always 0.

What is missing?

Thanks,

Pavel

#stm32f446 #rtc-backup
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on January 02, 2018 at 22:14

Can you write to other RTC registers?

Is tamper set/active?

JW

View solution in original post

3 REPLIES 3
Posted on January 02, 2018 at 22:14

Can you write to other RTC registers?

Is tamper set/active?

JW

Amel NASRI
ST Employee
Posted on January 03, 2018 at 10:27

Hi

pavel_a

‌,

You find a ready to use example with STM32F446 underSTM32Cube_FW_F4_V1.0\Projects\STM32F446ZE-Nucleo\Examples\RTC\RTC_Tamper.

It helps you to review all configuration steps to write/read data to/from RTC Backup data registers.

You find more details about this example in the readme.txt file.

You may test this example. If it works as expected, then compare this implementation with CubeMX generated code. May be some API calls are missing in the code you added.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on January 03, 2018 at 12:32

Thank you Jan and Amel.

It was the tamper thing. Some time ago I played with tamper and it somehow persisted even after several full erases of the chip. In the current init code, only RTC is initialized but not the tamper switch.

So I've added following lines from the example pointed by Amel after the RTC init code generated by cubemx: 

HAL_RTCEx_DeactivateTamper(&hrtc, RTC_TAMPER_1);

__HAL_RTC_TAMPER_CLEAR_FLAG(&hrtc, RTC_FLAG_TAMP1F);

Then backup regs become writable.

Regards,

-- pa