Tutorial: Adding library header in uVision

Tutorial: Adding library header in uVision

This tutorial explains how to include header files in uVision project.

Preparation

1. Download header files

Here, we assume that necessary header files are stored in your workspace ..\..\repos\EC\include\

Download tutorial source files

Include header files, located in a specific folder

  • save the downloaded header files in your workspace: ..\..\repos\EC\include\

image

2. Create a New Project in uVision

You can refer to Tutorial: Create a Project with uVision

You can skip this if you already have the project opened.

3. Create a new source main file.

Create a new program file as TU_CreateProject_main.c. This is the same file used in Tutorial: Create a Project with uVision

We will modify the main program code as

#include "ecSTM32_simple.h"


#define LED_PIN PA_5
#define BUTTON_PIN PC_13

void setup(void);

int main(void) { 
 	setup();
	int buttonState=0;
	
	while(1){
		// check if the pushbutton is pressed. Turn LED on/off accordingly:
		buttonState = 	GPIO_read(BUTTON_PIN);
		if(buttonState)	GPIO_write(LED_PIN, LOW);
		else 		GPIO_write(LED_PIN, HIGH);
	}
}


// Initialiization 
void setup(void) {
	RCC_HSI_init();
	// initialize the pushbutton pin as an input:
	GPIO_init(BUTTON_PIN, INPUT);  
	// initialize the LED pin as an output:
	GPIO_init(LED_PIN, OUTPUT);    
}

Include Library Path

We will learn how to include Library Path in your project

1. Specify 'Include Path' for your Project Target

Open Options for Target (press ALT+F7) > C/C++ tab > Include Paths

Add the path location for the include files.

image

2. Create a New Group folder and rename

  1. Right-click on the Project>Target1. Then, select Add Group

  2. Rename the New Group by going to Manage Project Items.

  3. Change the name such as "Include"

image

3. Specify 'Include Path' for your Include

  1. Right-Click on Project> Include> Options for Group 'New Group'

  2. Options for Group 'Include' > C/C++ Tab> Include Paths> choose where the header files are located

Options for Group, NOT Target1

image

4. **Add Existing Header files **

Project> Include > Add Existing Files to Group

Add your libraries, such ecSTM32_simple.h, ecSTM32_simple.c

Also, you can add more files

image

5. Run the project and see results

Last updated

Was this helpful?