💾
EC
  • Introduction
  • EC Course
    • Syllabus
    • Preparation for EC
    • Tutorial
      • Tutorial: arduino-stm32
        • Tutorial: arduino-stm32 Installation
        • Tutorial: arduino-stm32 Part1
        • Tutorial: arduino-stm32 Part2
      • Tutorial: MDK uVision
        • Tutorial: Installing MDK uVision
        • Tutorial: Create a Project with uVision
        • Tutorial: Adding library header in uVision
        • Tutorial: Re-using Project Configuration
        • Debugging in uVision
      • Tutorial: PlatformIO in CLion
      • Tutorial: PlatformIO in VSCode
      • Tutorial: Repository Management
      • Tutorial: Managing library header files
      • Tutorial: PinName Configuration
      • Tutorial: Bitwise Macro
      • Tutorial: Custom initialization
      • Tutorial: Documentation
      • Tutorial: Creating Application API
      • Tutorial: 7-Segment Display
      • Tutorial: DC motor driver connection
      • Tutorial: USART with TeraTerm
      • Tutorial: Finite State Machine programming
      • Tutorial: Bluetooth
      • Tutorial: Zigbee with Nucleo board
    • LAB
      • LAB Report Template
      • LAB: Smart mini-fan with STM32-duino
      • LAB: Portable Fan with mbed
      • LAB: GPIO Digital InOut
      • LAB: GPIO Digital InOut 7-segment
      • LAB: EXTI & SysTick
      • LAB: Timer & PWM
      • LAB: Stepper Motor
      • LAB: Input Capture - Ultrasonic
      • LAB: USART - LED, Bluetooth
      • LAB: ADC - IR reflective sensor
      • LAB: Line Tracing RC Car
    • Sample code
      • Code Templates
    • Hardware
      • Nucleo-F411RE
      • LAB Hardware
        • Electronic Chips
        • HUINS Embedded Kit
    • Projects
      • Line Tracing Car Project
      • Design Project
        • Past Projects
      • Project Grading Criteria
    • Study Resource for MCU
      • Hexa-Decimal Table
      • Bitwise Op for Register
      • System Clock
      • Timer
      • USART
      • ADC
  • STM32 M4 Programming
    • Documentation
      • C++ API Docs
    • Firmware Library
      • PinName Configuration
      • GPIO Digital
      • RCC
      • EXTI_SysTick
      • TIMER
      • USART
    • Troubleshooting
    • mbed for STM32
      • Tutorial: mbed-Part 1
      • Tutorial: mbed - Part 2
      • Tutorial: mbed - Part 3
      • Using mbed API on uVision
    • mbed OS
  • Other Programming
    • Arduino
    • Socket Programming
      • Window Socket Programming
      • Arduino WiFi
    • Cube-MX
    • Github
    • Markdown
      • Example: API documentation
    • MATLAB
  • C Programming
    • C-Programming Lessons
      • Installing Visual Studio Community
        • Visual Studio Community 2022
      • Installing VS Code(Mac/Linux)
      • Creating Header Lib
      • Pointer
      • Array
      • 2D Array
      • Structure
      • Dynamic Alloc
      • Bitwise Operation
  • Numerical Programming
    • Syllabus
    • Preparation for NP
    • Math Review
    • Tutorial
      • TA Session Video
      • Tutorial: NP Library Header Files
      • Tutorial - Sine Taylor
      • Tutorial: Passing a Function, Function callback
      • Tutorial: Nonlinear solver
      • Tutorial: Differentiation
      • Tutorial: Integration
      • Tutorial: Matrix Structure
      • Tutorial: Eigenvalue problem
      • Tutorial: ODE-IVP
      • Tutorial: Curve Fitting
      • Tutorial: Create Github Repos of NP lib
      • Tutorial: Version Control in Github
      • Tutorial: Documentation with Markdown
      • Exercise: Version Control and Documentation
    • Example: MATLAB
    • Example: NP Library
    • Assignment
      • Assignment Factorial and Power
      • Assignment: Version Control and Documentation
    • Problem Bank
Powered by GitBook
On this page
  • 1. Open Keil 𝝁Vision IDE and Create a new Project
  • 2. Project Setting
  • Select Device for Target
  • Manage Run-Time Environment
  • Setup in Options for Target
  • 3. Create main program
  • 4. Build and Run
  • Build Target (F7)
  • Download Target (F8)
  • Tips

Was this helpful?

  1. EC Course
  2. Tutorial
  3. Tutorial: MDK uVision

Tutorial: Create a Project with uVision

PreviousTutorial: Installing MDK uVisionNextTutorial: Adding library header in uVision

Last updated 7 months ago

Was this helpful?

1. Open Keil 𝝁Vision IDE and Create a new Project

Project > New 𝝁Vision Project

Create this tutorial project under the folder ..\..\repos\EC\tutorial\

Name the project as TU_CreateProject.

  • Check you have a new folder named as ..\..\repos\EC\tutorial\TU_CreateProject\

Do not use 한글경로 (띄어쓰기) for Project Directory path

2. Project Setting

Select Device for Target

Target_1 (Right Click) > Options for Target > Device tab

Device > search for STM32F411RETx

If you use other board, STM32F411 etc, choose the appropriate device.

Manage Run-Time Environment

Select CMSIS>CORE , Device>Setup

This will use necessary library to start the MCU and GPIO drivers.

Check if the following startup codes are included under Device folder

‘startup_stm32f411xe.s’, ‘system_stm32f411xx.c’

Setup in Options for Target

Project> Options for Target (Alt+F7)

  1. Output Tab > check on Create HEX File :

This will create HEX file that contains the machine instruction codes

  1. C/C++ Tab> Version of C and C++ should be <default>

  1. Linker Tab> Use Memory Layout from Target Dialog checked

This will use the memory(register) layout of the specific target board

  1. Debug tab> Use: ST-Link Debugger > Settings

You must connect MCU (internal ST-Link) to PC for this setting.

  • Use: ST-LInk Debugger

  • Debug Adapter> Unit: ST-LINK/V2-1

  • Debug> Connect: under Reset

This will configure USB link to MCU hardware. It will use ST-Link debugger embedded on the target board to debug the program. You will need to connect the target board to your PC for debugging

3. Create main program

Project Tab> Target1> Source Group1 (Right Click) : Add New item to Group

Name the source file as TU_CreateProject_Example_main.c

경로, 폴더명에 한글 경로 사용하면 안됨!!

특히, Window User 이름이 한글이면 문제가 발생

Use sample source codes for test.

Use the same file of TU_CreateProject_Example_main.c.

Just change the source codes

int main(void){
	int num1 = 1;
	int num2 = 2;
	int numout=num1+num2;		
	printf("hello handong");
	return 0;
}
#include "stm32f4xx.h"

#define LED_PIN    5
#define BUTTON_PIN 13

// LED Blink by Button Pin (Button #2)

int main(void) {
		/* Part 1. RCC Register Setting */
		// RCC Control Register (HSI)
		RCC->CR |= ((uint32_t)RCC_CR_HSION); 
		// wait until HSI is ready
		while ( (RCC->CR & (uint32_t) RCC_CR_HSIRDY) == 0 ) {;} 
		// Select HSI as system clock source 
		// RCC Configuration Register 
		RCC->CFGR &= (uint32_t)((uint32_t) ~(RCC_CFGR_SW)); 
		RCC->CFGR |= (uint32_t)RCC_CFGR_SW_HSI;  
		// Wait till HSI is used as system clock source 
		while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != 0 ) {;} 
		// HSI is used as system clock         
		// RCC Peripheral Clock Enable Register 
		RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
		
		/* Part 2. GPIO Register Setting */			
		// GPIO Mode Register
		GPIOA->MODER &= ~(3UL<<(2*LED_PIN)); 
		GPIOA->MODER |=   1UL<<(2*LED_PIN);  
		// GPIO Output Speed Register 
		GPIOA->OSPEEDR &= ~(3UL<<(2*LED_PIN));
		GPIOA->OSPEEDR |=   2UL<<(2*LED_PIN);  
		// GPIO Output Type Register  
		GPIOA->OTYPER &= ~(1UL<<LED_PIN);      
		// GPIO Pull-Up/Pull-Down Register 
		GPIOA->PUPDR  &= ~(3UL<<(2*LED_PIN));
		
			// Dead loop & program hangs here
     while(1){
		// Turn ON LED2
		GPIOA->ODR |= (1UL << LED_PIN);

		// Turn OFF LED2
		//GPIOA->ODR &= ~(1UL << LED_PIN);
    }
}

4. Build and Run

Build Target (F7)

Build the program of Example 2

Press F7 and build the target and check if there is any error message

Download Target (F8)

If the MCU is connected to PC, flash the output program file

Flash>Download (F8)

For Example 2:

  • Check if the LED_2 of MCU (Nucleo-F411RE) board is turned on when the blue button (B2) is pressed

Tips

Instead of starting from a blank project, use example codes and tutorial codes provided by ARM and STM webpage.

image