Using CubeMX V4.7.1 I get garbage initialization code for RTC.c when I request initialization be generated as .c.h file pairs.
Simple demo case:
Select STMf103C8Tx as target
Under Pins Select RTC-> Activate Clock Source.
Under Project settings:
Project Name: Test
Under Code Generator Tab:
Check Generate peripheral initialization as pair of .c/.h files
Leave everything else at defaults.
Generate the code and look at rtc.c. It's not C source code. Eg.
/* RTC init function */
#t#t/**Initialize RTC Only #n#t#t*/
#thrtc.Instance = RTC;
#thrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
#thrtc.Init.OutPut = RTC_OUTPUTSOURCE_ALARM;
#tif (HAL_RTC_Init(&hrtc) != HAL_OK)
Followed by what looks like a lot of Java error messages.
Looks like a CubeMX bug to me. If I leave the init stuff in main, it works OK.