Skip to main content
Pavel A.
January 2, 2018
Solved

Why RTC backup register write fails? (STM32F446)

  • January 2, 2018
  • 3 replies
  • 1300 views
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
This topic has been closed for replies.
Best answer by waclawek.jan
Posted on January 02, 2018 at 22:14

Can you write to other RTC registers?

Is tamper set/active?

JW

3 replies

waclawek.jan
waclawek.janBest answer
Super User
January 2, 2018
Posted on January 02, 2018 at 22:14

Can you write to other RTC registers?

Is tamper set/active?

JW

Amel NASRI
ST Technical Moderator
January 3, 2018
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 "Best Answer" on the reply which solved your issue or answered your question.
Pavel A.
Pavel A.Author
January 3, 2018
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