Sunday, February 18, 2024

Reading current date and time using RTC on STM32F407VET6

In STM32F407VET6 board we can calculate current date and time using following steps:

1. Go to Pinout & Configuration> Timers> RTC in RTC mode and Configuration.

2. Activate Clock Source & Activate Calendar should be enabled.

3. Alarm A should be selected as Internal Alarm.

4. Go to parameter configuration of RTC, set date and time to marked configuration below:


5. Enable interrupt in NVIC Settings


6. To read the date and time following code needs to be called in main.c file.

  RTC_TimeTypeDef sTime1;

  RTC_DateTypeDef sDate1;


  uint8_t buffer[20];


/* USER CODE BEGIN WHILE */


while (1)

{

        HAL_RTC_GetTime(&hrtc, &sTime1, RTC_FORMAT_BCD);

HAL_RTC_GetDate(&hrtc, &sDate1, RTC_FORMAT_BCD);


buffer[0] = (sDate1.Date / 16) + 48;

buffer[1] = (sDate1.Date % 16) + 48;

buffer[2] = '.';

buffer[3] = (sDate1.Month / 16) + 48;

buffer[4] = (sDate1.Month % 16) + 48;

buffer[5] = '.';

buffer[6] = '2';

buffer[7] = '0';

buffer[8] = (sDate1.Year / 16) + 48;

buffer[9] = (sDate1.Year % 16) + 48;

buffer[10] ='@';

buffer[11] = (sTime1.Hours / 16) + 48;

buffer[12] = (sTime1.Hours % 16) + 48;

buffer[13] = ':';

buffer[14] = (sTime1.Minutes / 16) + 48;

buffer[15] = (sTime1.Minutes % 16) + 48;

buffer[16] = ':';

buffer[17] = (sTime1.Seconds / 16) + 48;

buffer[18] = (sTime1.Seconds % 16) + 48;


}

/* USER CODE END 3 */


6. After building and flashing the code we will see result as shown below:

Decoded as 18.02.2024@20:20:46

Monday, February 12, 2024

CRC calculation in STM32F407VET6

 In STM32F407VET6 board we can calculate CRC-32/MPEG-2 using following steps:

1. Enable CRC engine at Pinout & Configuration> Computing> CRC mode and Configuration should be activated

2. Save project and generate the project

3. Define data buffer on which we wants to calculate CRC

uint32_t crcArray[4] = {0x00001111, 0x00002222, 0x00003333, 0x00004444};

4. Function call for crc needs to be called in main function as:

crcVal = HAL_CRC_Calculate(&hcrc, crcArray, 4);

Where, uint32 of CRC will be returned.

5. After running the code we will get CRC as shown below:


6. Verify CRC using Online calculator 



CRC value calculated on STM32 and online calculator are matching.

Saturday, February 10, 2024

Blinky project for Arduino UNO Board

Steps to Blink LED present on Arduino UNO board.

1. Open Arduino UNO software.

2. Go to File> Examples> 01.Basic> Blink (It will open new window)

3. Connect Arduino UNO board with PC

4. Select board if not done to Arduino UNO\

5. Verify the Blink Code, in Output window it will show as below:


6. Upload code to board using Right Arrow key button (after upload pop will comes as done uploading)

7. LED present on Arduino UNO board will start blinking with delay of 1 sec specified in code.

Wednesday, January 31, 2024

Enabling RTOS in STM32F407VET6

In STM32CubeIDE we can enable RTOS using following steps:

Configuration

1. In Pinout & Configuration, go to Middleware and Software Packs > FREERTOS

2. Configure Interface Mode as CMSIS_V1 or CMSIS_V2

3. Start adding OS Tasks, change Task name and Entry function.

    Example: 


 Manual Code

1. In main.c file > main() function instead of writing in while 1 loop, we need to write actual code in    Tasks generated. While 1 loop will not be reached as osKernelStart(); will take over.

2. LED Blinking code can be executed from TASK which we added

Example code:

/* USER CODE BEGIN Header_Task2_init */

/**

* @brief Function implementing the Task2 thread.

* @param argument: Not used

* @retval None

*/

/* USER CODE END Header_Task2_init */

void Task2_init(void const * argument)

{

/* USER CODE BEGIN Task2_init */

/* Infinite loop */

for(;;)

{

HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_6);

HAL_Delay(200);

    //osDelay(10);

}

/* USER CODE END Task2_init */

}

Random number generation in STM32F407VET6

 For RNG generation in STM32F407VET6 board follow below steps:

Configuration:

1. In Pinout and configuration, in security > RNG Mode & Configuration, Mode should be activated.

2. With change in point 1, tool will prompt to change clock configuration. Use automatic clock configuration fix given by tool to adjust the clock values.


Manual Code: 

In main.c file, we need to call function to get random number as shown below:

/* USER CODE BEGIN WHILE */


while (1)

{

HAL_RNG_GetRandomNumber(&hrng);

HAL_Delay(200);

/* USER CODE END WHILE */


/* USER CODE BEGIN 3 */

}


Variable hrng is already declared when code was generated. 


RNG result will be as shown in below image:




Saturday, January 27, 2024

Blinky Project for STM32F407VET6 Board - Manual Code

 After Configuration and Project Setup we need to add below code in order to blink the LED.

In main.c file, in main() function we need to add

/* USER CODE BEGIN WHILE */

while (1)

{

HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_6);

HAL_Delay(200);

/* USER CODE END WHILE */


/* USER CODE BEGIN 3 */

}


 Where, 


    HAL_GPIO_TogglePin - Function to Toggle Pin/LED.

HAL_Delay - Delay function, here delay of 200msec is given.


Save, It will prompt for code generation, then Project>Build All. Debug(elf/hex) file will be generated.


For flashing/Debugging, 

1. Connect USB and ST Link V2 Debugger

2. Use option Run>Debug As>1 STM32 C/C++ Application for programming/debugging.


If ST Link connection is not done then following Error will be prompted:




Blinky Project for STM32F407VET6 Board - Configuration/Setup

 Follow below steps to create a basic LED blinking project for STM32F407VET6 board:

1. Create File>New>STM32 Project

2. Select Commercial Part number as STM32F407VET6, select 1st part number in search window.

3. In Next Tab provide project name (e.g. BlinkLED), keep other parameters as it is.

4. In Next Tab keep parameters as default, and Finish the setup. 


Pinout & Configuration:

1. System Core> SYS Select Debug option as Serial Wire

2. System Core> RCC Select High Speed Clock(HSE) & Low Speed Clock(LSE) as Crystal/Ceramic Resonator

3. In Pinout view, select PA6 as GPIO_Output

4. And in  System Core>GPIO Select GPIO output level as High

5. Go to Clock Configuration and make HCLK clock as 168Mhz (Highest clock supported by board).