Time to add the clock calendar display part, we need to add the portion of the application that will actually give and display the time and date. Again this part should be implemented using state machines. simple printf using semihosting will do the trick for now

REQ-301

It will mandatory to use the internal microcontroller Real time Clock Calendar peripheral in order to keep track of the time and date values.

REQ-302

If for some reason your stm32 microcontroller does not ship with a RTC peripheral, then you should have to emulate all its functionalities using a TIM timer

REQ-303

The clock part of the application should be implemented in a new files called clock.h and clock.

REQ-304

The interfaces to implement should be

void Clock_Init( void ); 
void Clock_MainFunction( void );

Where Clock_Init the function to initialize all the things required to start working with the RTC and the message received from the Serial Task. And Clock_MainFunctiongoing to implement the state machine in charge of messages processing from the serial task and display the time and date

REQ-305

The header file should only be the place holder for the previous functions, while the source file will have its corresponding implementations plus any other private functions needed

REQ-306

The functions from this piece of code should be called from main.c like this.

#include "bsp.h"
#include "serial.h"
#include "clock.h"
//Add more includes as needed

int main( void )
{
    HAL_Init();
    Serial_Init();
    Clock_Init();
    //Add more initilizations as needed
    
    for(;;)
    {
        Serial_MainFunction();
        Clock_MainFunction();
        //Add another task as needed
    }
}

REQ-307

Time, Date and Alarm shall be displayed every second using Semihosting, SWO redirection or with segger RTT printf in case you are using J-Link.

REQ-308

To establish a periodicity every second it is necessary to use the HAL_GetTick function like in the code blow. You can take a look at the following example NVIC: Systick Timer

...
if( (HAL_GetTick() - tick_second) >= 1000 )
{
    tick_second = HAL_GetTick();
    // time to display time, date and alarm
    ...

REQ-309

Time, date and the current alarm value shall be displayed in the following format

Time hh:mm:ss 
Date: dd/mm/yyyy 
Alarm: hh:mm

REQ-310

The clock task should monitor a message from the serial task in the form of variable APP_MsgTypeDef and must update the RTC with the new Time, Date or Alarm. Data shall arrive previously validated by the Serial Task. Once data is read it somehow shall be clear to catch new information. For instance

...
if( message.msg != SERIAL_MSG_NONE )
{
    // process the message
    ...
    message.msg = SERIAL_MSG_NONE;
    
}

REQ-312

The RTC peripheral shall be configured to run with the external on board LSE crystal, if for some reason your board doesn’t have this crystal use the internal LSI or any other low power timer to feed the RTC 

REQ-313

The state machine design shall follow the next UML State Machine diagram where each state should be represented with a case statement from the switch sentence. The state machine implementation should be made using a single switch statement inside the function Clock_MainFunction

For the moment we are not going to activate the alarm but it should be ready in place in the RTC peripheral with the values received from the Serial Task.