2015-04-20 07:49 AM
I'm using the V1.4 version of the STMCube HAL driver to update the RTC backup registers. I can properly read and write to the Date & Time functions of the RTC.
However, when writing to the RTC Backup registers, the data doesn't appear to be saved.In the following example, the data read back after it is written is always 0.int testWriteRTC(void){ unsigned int dataValue; RTC_HandleTypeDef g_RtcHandle; RCC_OscInitTypeDef RCC_OscInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; /*♯♯-1- Configue LSE as RTC clock soucre ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; RCC_OscInitStruct.LSEState = RCC_LSE_ON; RCC_OscInitStruct.LSIState = RCC_LSI_OFF; if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { return(false); } PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { return(false); } /*♯♯-2- Enable RTC peripheral Clocks ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/ /* Enable RTC Clock */ __HAL_RCC_RTC_ENABLE();&sharpdefine RTC_ASYNCH_PREDIV 0x1f&sharpdefine RTC_SYNCH_PREDIV 0x3ff /*♯♯-1- Configure the RTC peripheral ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/ g_RtcHandle.Instance = RTC; /* Configure RTC prescaler and RTC data registers */ /* RTC configured as follow: - Hour Format = Format 24 - Asynch Prediv = Value according to source clock - Synch Prediv = Value according to source clock - OutPut = Output Disable - OutPutPolarity = High Polarity - OutPutType = Open Drain */ g_RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24; g_RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV; g_RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV; g_RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE; g_RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; g_RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; if(HAL_RTC_Init(&g_RtcHandle) != HAL_OK) { return(false); } /* Clear Reset Flag */ __HAL_RCC_CLEAR_RESET_FLAGS(); /* This fails to update the memory location */ HAL_RTCEx_BKUPWrite(&g_RtcHandle, 0x00, 0x123456); // Read data value back (and notice unchanged) DataValue = HAL_RTCEx_BKUPRead(&g_RtcHandle, 0x00); // ASSERT fails as DataValue is always 0 ASSERT(DataValue == 0x123456); return(DataValue == 0x123456);}I found no errata or information on this write failing. Any help is appreciated. #stm32f4-rtc2015-04-20 09:05 AM
I found no errata or information on this write failing. Any help is appreciated.
But it's documented that you have to unlock it? Not a HAL user, perhaps :__PWR_CLK_ENABLE(); // normally in SystemClock_Config()
HAL_PWR_EnableBkUpAccess();
2015-04-21 07:32 AM
Thanks Clive, that worked.
I did see the enable required in the data sheet, but couldn't find the correct API in the HAL library (I searched for backup, not bkup).What library do you use (if any)?Reason I ask is I'm looking for a good working example of SDMMC connections using 4 bit SDIO DMA transfers.Thanks again.2015-04-21 09:28 AM
I shotgunned with Google.. but kind of knew what code constructs I was looking for.
I'm an advocate for the SPL, it has a good speed/size tradeoff, I can do register level stuff if I need to, in either assembler or C. I've posted several working examples of MicroSD cards on F4 platform, using 4-bit, DMA, with read speed of about 10MBps as I recall.[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/SDIO%204Bit%20Mode%2c%20FatFS%2c%20and%20STM32CubeMX%20on%20STM32F401%20Discovery&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21¤tviews=207]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Java%2FSDIO%204Bit%20Mode%2C%20FatFS%2C%20and%20STM32CubeMX%20on%20STM32F401%20Discovery&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21¤tviews=207