Search Posts

The simplest guide to setup dev environment for stm32l476rg

The simplest guide to setup dev environment for stm32l476rg:

Step 1: Install eclipse
Step 2: Download STM32 workbench from http://www.openstm32.org/HomePage
Step 3: Create a “c project” in eclipse and choose the board stm32l476rg, all other settings remain defaults, there is a dialog popup and you can download the cube4l in there, which is stm32 library
Step 4: in your main, paste this

/**
 ******************************************************************************
 * @file    main.c
 * @author  Ac6
 * @version V1.0
 * @date    01-December-2013
 * @brief   Default main function.
 ******************************************************************************
 */

#include "stm32l4xx.h"
#include "stm32l4xx_nucleo.h"

#include "stm32l4xx_ll_bus.h"
#include "stm32l4xx_ll_rcc.h"
#include "stm32l4xx_ll_system.h"
#include "stm32l4xx_ll_utils.h"
#include "stm32l4xx_ll_gpio.h"
#include "stm32l4xx_ll_exti.h"

__STATIC_INLINE void Configure_GPIO(void) {
	LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);

	LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_5, LL_GPIO_MODE_OUTPUT);
	LL_GPIO_SetPinOutputType(GPIOA, LL_GPIO_PIN_5, LL_GPIO_OUTPUT_PUSHPULL);
	LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_5, LL_GPIO_SPEED_LOW);
	LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_5, LL_GPIO_PULL_NO);
}

__STATIC_INLINE void SystemClock_Config(void) {
	LL_FLASH_SetLatency(LL_FLASH_LATENCY_4);

	LL_RCC_HSI_Enable();
	while (LL_RCC_HSI_IsReady() != 1) {
	};
	LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 10,
	LL_RCC_PLLR_DIV_2);
	LL_RCC_PLL_Enable();
	LL_RCC_PLL_EnableDomain_SYS();
	while (LL_RCC_PLL_IsReady() != 1)
		;

	LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
	LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
	while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
		;

	LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
	LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);

	LL_Init1msTick(80000000);

	LL_SetSystemCoreClock(80000000);
}

int main(void) {
	Configure_GPIO();
	SystemClock_Config();
	int i = 0;
	while (1) {
		LL_GPIO_TogglePin(GPIOA, LL_GPIO_PIN_5);
		if (i == 0) {
			LL_mDelay(100);
		} else if (i == 1) {
			LL_mDelay(500);
		} else {
			LL_mDelay(1000);
		}
	}
	return 0;
}

Step 5: Click build, you got the bin file, then burn it using the STM32 St-Link utility

Leave a Reply

Your email address will not be published. Required fields are marked *