STM32F3 RTC help

An area to discuss ARM specific problems and examples

Moderator: Benj

Post Reply
User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

STM32F3 RTC help

Post by fotios »

Hi... again :D
Is there any help or tutorial of how I could set up the RTC of STM32F303RE within FC?
Using the STM32CubeMX is quite easy as I can also set the current day of the week, month, year.
Unfortunately, I haven't the possibility to also include in CubeIDE the FC generated code of the 4X20 LCD that I use in my hardware.
I also don't know how to transfer the RTC code generated by CubeIDE into FC in which the LCD is working flawlessly.
I have been confused so many days reading the HAL driver manual, the STM32F3 manual, C/C++ manual, FC CAL, FC FCD, FC compilers, etc.
I like very much the reading and learning of new things, but I haven't so much time to dedicate on that.
I need a more helpful way, I'm not an expert in C compilers which of the file system is very complex.
On the other hand, these ARM micros include a lot of useful peripherals that aren't covered by the FC current version.
However, I'm very happy using FC with PIC micros.
The use of STM32CubeIDE is only for experienced users, is very complex for beginners.
What to do next?
Maybe to buy a well-documented and compact compiler/debugger suite (like Keil MDK, or Altium Tasking) to use in combination with FC and CubeIDE?

Thanks
Last edited by fotios on Mon Jan 20, 2020 1:10 pm, edited 3 times in total.
Best Regards FOTIS ANAGNOSTOU

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F3 RTC help

Post by LeighM »

I will have a look and see what’s involved in creating an RTC component for F3

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F3 RTC help

Post by LeighM »

Hi,
Try the attached using the RTC component (set property to Internal)
drop the .c files into Flowcode 7\CAL\STARM
and the .fcdx files into Flowcode 7\FCD\ARM
Attachments
STARM_CAL_RTC.c
(6.46 KiB) Downloaded 254 times
STARM_CAL_I2C.c
(16.44 KiB) Downloaded 229 times
32F303Nucleo64.fcdx
(29.11 KiB) Downloaded 211 times
32F303RE.fcdx
(36.07 KiB) Downloaded 213 times

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: STM32F3 RTC help

Post by fotios »

Hi Leigh
Thanks a lot for your help.
I appreciate it very much.
However, there are 2 issues occurring from the fact that on my hardware I use an external XTAL of 32.768KHz:
1) If the LSE is selected the compiler returns the following error:

Code: Select all

RTC_STM.o: In function `FC_CAL_RTC_Init_1':
RTC_STM.c:(.text.FC_CAL_RTC_Init_1+0x2): undefined reference to `__HAL_RCC_LSE_ENABLE'
collect2.exe: error: ld returned 1 exit status
Error(s) in build
I tried a lot of searching within the C and HEX FC7 root files if I could locate the error without success. As I told you the file system is very complex.
Here is a picture from the RTC component settings:
RTC_settings.jpg
RTC_settings.jpg (62.61 KiB) Viewed 7887 times
2) If the LSI is selected the FCF is compiled successfully. No errors. But on my actual hardware, the LCD prints nothing.
Attached is the FCF file that I created just for the RTC.
I haven't used the FCF RTC component so far but I think the FCF is correct.
I have placed an LCD component macro to print the string "No time" within the main loop, just to check if the LCD is working.
I have noticed that if all of the "SET" macros of RTC are bypassed (with "Jump") then the LCD prints correctly the two "GET" macros and the "No time".
I also checked my hardware to verify that the VBAT pin of STM32F303 is supplied normally.
I think we have a few steps more to debug completely the STM32F3 RTC compo!

A million thanks for your kindness :D


RTC_STM.fcfx
(13.07 KiB) Downloaded 239 times
Best Regards FOTIS ANAGNOSTOU

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F3 RTC help

Post by LeighM »

OK, thanks for the feedback.
I must admit that I only tested it on internal 40kHz setting
I will dig a bit deeper
Thanks
Leigh
Last edited by LeighM on Thu Jan 23, 2020 11:04 am, edited 1 time in total.

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: STM32F3 RTC help

Post by fotios »

Hi Leigh
If that could help you, here is a picture that shows what I meant saying: If all "SET" RTC component macros are bypassed just for a test, then the LCD prints normally.
RTC_SET_Bypass.jpg
RTC_SET_Bypass.jpg (24.65 KiB) Viewed 7882 times
Thanks
Best Regards FOTIS ANAGNOSTOU

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F3 RTC help

Post by LeighM »

Try this ...
Attachments
STARM_CAL_RTC.c
(5.91 KiB) Downloaded 244 times

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: STM32F3 RTC help

Post by fotios »

Hi Leigh
Yeah! It works :D
LSE RTC is working and LCD prints and updates the time every second.

Simply now I've lost some port interrupts.

The only presented are:
EXTI0
EXT1
EXT2
EXTI3
EXTI4
EXTI8
EXTI13

If you remember, 2 months ago, I had this problem and you resolved it with the new fcdx file in this post:
viewtopic.php?f=72&t=21711#p98333

Thanks!
Best Regards FOTIS ANAGNOSTOU

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F3 RTC help

Post by LeighM »

That's good then :D
Sorry, seems I edited the wrong FCD file,
please use this one ...
Attachments
32F303RE.fcdx
(48.98 KiB) Downloaded 228 times

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: STM32F3 RTC help

Post by fotios »

Hi Leigh
I have great news!
Everything is compiled and works perfectly on my actual hardware :D
Here a picture:
IMG_20200124_102714.jpg
IMG_20200124_102714.jpg (125.26 KiB) Viewed 7850 times
I did a trick within FlowCode to set the time according to the Windows clock.
(Don't scare, UK time = GR time - 2 hours :lol:)
I soldered and the backup battery and the RTC works perfectly supplied either by the VCC or the VBAT (all night yesterday).
It should be noted that the RTC works and retains the time without reset, yet when the micro is flashed again and again.
It is a very-very precise clock.

Thanks a lot again for your offer and your effort.
Last edited by fotios on Fri Jan 24, 2020 6:46 pm, edited 1 time in total.
Best Regards FOTIS ANAGNOSTOU

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F3 RTC help

Post by LeighM »

Thanks for the update, looks very good! :D

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F3 RTC help

Post by LeighM »

Just a note for V8 users, this feature has also been implemented in V8 and will be coming to you via the update system some time soon...
Hit that button Ben :wink:

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: STM32F3 RTC help

Post by fotios »

Hi :D
As no Stopwatch function is provided by the current FC component for the STM32, here is a complete FCF that initializes the RTC and provides an elementary stopwatch that can count up to 60 minutes. I will use it in my future project "Thermostat for central heating" to calculate the oil consumption. In my home, the oil burner is equipped with a nozzle 0.75/60/S at 11 bar, thus (from the burner table) it consumes 3.7lt/h = 0.0616lt/min +/-10%. The FCF is compiled and tested on actual hardware with success. If there is an improvement in the code it will be very welcomed :)
RTC_STM.fcfx
(23.28 KiB) Downloaded 180 times
Best Regards FOTIS ANAGNOSTOU

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: STM32F3 RTC help

Post by fotios »

Tip: this will save you from the need of using several switches to set the actual date and time. Only a user switch, few settings, and 3 times flash of micro are necessary to initialize the RTC calendar and clock. In my hardware, the switch is attached to port PB.11, for that reason the Port interrupt EXTI11. First, within the main function change the interrupt Macro Call to "RTC_SET". Follow the Windows calendar, and write the year and month in the corresponding component macros found into Macro "RTC_SET". Since the Week Day is not user initialized in STM32 (it gets a preset 1 = Monday and then follows the Date, i.e. when is changed from 27 to 28, the Week Day also is changed e.g. from Mon to Tue), and the actual Date is e.g. 28, set Date = 27, Hour = 23, Min = 59, Sec = 59. Flash the code into micro, and let it run. The RTC will be updated to "Mon 28/01/20" "00:00:00". Press the switch to set the RTC in the previous values. Each time is pressed, the RTC is loaded with "23:59:59", within 1 sec is changed to "00:00:00", and the Week Day is also updated. Press until it meets the actual Week Day. The RTC will retain it. Next, within FC set the actual values of the current Date = 28, Hour = xx, and Sec = 0, taken from the Windows calendar and clock. Set the Mins +2 from the value indicated by the Windows clock, e.g. if it is 35 set to 37. Flash again the code into micro, and let it run. The RTC will show the correct Week Day but about 1 min more than the actual time of the Windows clock. Wait and when the Win clock will show 37 mins, press the switch. Now it will initialize the RTC with all correct values. Finally, change the interrupt Macro Call to "START", so that you can use the switch to start the Stopwatch. Flash again the code to micro, and that's all :)
Thanks
Best Regards FOTIS ANAGNOSTOU

Post Reply