0% found this document useful (0 votes)
25 views10 pages

Led Blink

The document outlines a procedure to blink the onboard LEDs of the STM32F407G-DISC1 discovery board. It includes details on the required components, pin configurations, and step-by-step instructions for setting up the code and running the project. Additionally, it provides alternative methods for blinking the LEDs using a main loop without delay and utilizing a timer for more efficient operation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views10 pages

Led Blink

The document outlines a procedure to blink the onboard LEDs of the STM32F407G-DISC1 discovery board. It includes details on the required components, pin configurations, and step-by-step instructions for setting up the code and running the project. Additionally, it provides alternative methods for blinking the LEDs using a main loop without delay and utilizing a timer for more efficient operation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

1.

STM_32 Blinking On-Board LEDS

Aim:
To blink the onboard LEDS of board STM32f407G-DISC1

Components Required:
1.Discovery Board - STM32F407G-DISC1

Pin details:

There are 4 on-board LEDS:


 User LD3: orange LED is a user LED connected to the I/O PD13 of the
STM32F407VGT6.
 User LD4: green LED is a user LED connected to the I/O PD12 of the
STM32F407VGT6.
 User LD5: red LED is a user LED connected to the I/O PD14 of the
STM32F407VGT6.
 User LD6: blue LED is a user LED connected to the I/O PD15 of the
STM32F407VGT6.
Procedure:
1. RCC Settings
2.SYS Settings
3.GPIO

4. Clock Configuration:
4.Closethe ioc file. It will ask whether to Generate Code.
Click OK

5. Include the code in main’s While loop


HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|
GPIO_PIN_15, GPIO_PIN_RESET);
HAL_Delay(200);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|
GPIO_PIN_15, GPIO_PIN_SET);
HAL_Delay(200);

6.Build the Project to check for errors


7. Run the project
8.Output:
You can see the 4 LEDs blinking

Note: for Code refer the folder Program.

II Program - II
Main Loop Without Delay

uint32_t then = 0, now = 0;

while (1)
{

// Check the current tick


now = HAL_GetTick();
if (now - then >= 500) { // Only if the current tick is 500 ms
after the last

HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);

then = now; // Reset then = now


}

// Other stuff can be done here without affecting the blink


frequency as long as
// whatever is being done take less than 500 ms.

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */


}
/* USER CODE END 3 */
}

III using Timer


1. Clock Source – Internal Clock
2. Add User Constants:
T4_PRE
T4_CNT
/* Private define
------------------------------------------------------------*/
/* USER CODE BEGIN PD */

#define T4_PRE 7199


#define T4_CNT 4999
/* USER CODE END PD */

/* USER CODE BEGIN 0 */

// Override the weak call back function


void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
if (htim->Instance == TIM4) {
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
}
}

/* USER CODE END 0 */

/* USER CODE BEGIN 2 */

// Fire up the timer


HAL_TIM_Base_Start_IT(&htim4);
/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
// Not doing anything here

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */


}
/* USER CODE END 3 */

You might also like