Skip to main content

Create a Luos project with PlatformIO

Beginner

What you will learn:

You just heard about Luos, or you have already finished the Luos Get started and Trainings and you want to go further with Luos: this tutorial is for you! We will accompany you from scratch and step by step with your first project creation and Luos integration!

Project
Creation
ST
Arduino

Part 1: Project creation

1. Introduction

Beginning with a project can be painful and a long process! New environment, new tools, ... You may sometimes want to give up before starting.

But don't worry, we will guide you through the process! You will learn how to set up a PlatformIO environment and how to make a good project structure.

This tutorial uses VSCode as an IDE. Before jumping into the code, let's set up your project with PlatformIO.

caution

If PlatformIO is not already installed on your computer, please follow our Get started tutorial.

In this tutorial, we will use a ST NUCLEO F072RB board for a project creation with ST board, and an Arduino MKRZero board for project creation with Arduino board.

2. Create a new project

1- Create a new project

luos_imgluos_img
luos_imgluos_img
luos_imgluos_img
info

Choose the default location of your projet on your computer.

At this step, PlatformIO creates for you a complete project:

  • Folder include: where you put the project's header files.
  • Folder src: where you put the put project's source files.
  • Folder lib: where you put the Luos services.
  • plateformio.ini: the PlatformIO project entry point.

2- Click on finish

luos_imgluos_img

3- Click on Yes accept

3. Node's config files creation

Luos project uses a file, placed at the root of the folder, called node_config.h. This file allows you to configure the Luos library and match your hardware's configuration with Luos's default configuration.

  1. Right click on "Project name".
  2. New Filesnode_config.h.
  3. Copy the code below and save.
/******************************************************************************
* @file node_config.h
* @brief This file allow you to use standard preprocessor definitions to
* configure your project, Luos and Luos HAL libraries
* @author Yourself
* @version 0.0.0
******************************************************************************/
#ifndef _NODE_CONFIG_H_
#define _NODE_CONFIG_H_

#endif /* _NODE_CONFIG_H_ */
info

If you don't know what node_config.h is, please read the Luos documentation.

info

In this example, we will use the default configuration of Luos HAL for ST and Arduino, so nothing to change right now 😅.

4. Configure platformio.ini to use your project

platformio.ini is the project configuration file. You must fill in the file with the information relative to your project. See the file definition in the table below, according to the board you have:

build_unflags = -Os
build_flags =
-O1
-include node_config.h
debug_tool = stlink
upload_protocol = stlink

Defined for STM32 Frameworks:

  • USE_HAL_DRIVER → possibility to use HAL file of STM32 Framworks.
  • USE_FULL_LL_DRIVER → possibility to use low Level file of STM32 Framworks.
luos_imgluos_img

5. Create the main file

The main file of your project is your entry point! Let's fill in this file with our basic needs:

  1. In srcNew Filesmain.c
  2. Fill in the file main.c with the following code:
/******************************************************************************
* @file main
* @brief main file of the project
* @author Yourself
* @version 0.0.0
******************************************************************************/

#include "stm32f0xx_hal.h"

/*******************************************************************************
* Definitions
******************************************************************************/

/*******************************************************************************
* Variables
******************************************************************************/

/*******************************************************************************
* Function
******************************************************************************/

/******************************************************************************
* @brief main function
* @param None
* @return None
******************************************************************************/
int main(void)
{
// Init
HAL_Init();


// Loop
while (1)
{

}
}
  1. The include of stm32f0xx_hal.h must be adapted to the STM familly MCU you chose. In our case, ST NUCLEO STM32F072RB corresponds to the F0 family.
tip

You can modify the clock frequency of you MCU. We recommand to do it with CubeMx.

6. Create interruption files handler

For many MCUs, you have acces to an IRQ handler fonction. These functions are called when an interruption happens (exception and peripherial interruption). You have to declare these functions depending on the frameworks you use.

  1. In srcNew Filesstm32f0xx_it.c, add this code:
/******************************************************************************
* @file stm32f0xx_it
* @brief Interrupt Service Routines.
* @author Yourself
* @version 0.0.0
******************************************************************************/
#include "stm32f0xx_hal.h"
#include "stm32f0xx_it.h"

/*******************************************************************************
* Definitions
******************************************************************************/

/*******************************************************************************
* Variables
******************************************************************************/

/*******************************************************************************
* Function
******************************************************************************/

/******************************************************************************/
/* Cortex-M0 Processor Interruption and Exception Handlers */
/******************************************************************************/
void NMI_Handler(void)
{
}

void HardFault_Handler(void)
{
while (1)
{
}
}

void SVC_Handler(void)
{
}

void PendSV_Handler(void)
{
}

void SysTick_Handler(void)
{
HAL_IncTick();
}

/******************************************************************************/
/* STM32F0xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32f0xx.s). */
/******************************************************************************/
  1. In IncludeNew Filestm32f0xx_it.h, add this code:
/******************************************************************************
* @file stm32f0xx_it
* @brief Interrupt Service Routines.
* @author Yourself
* @version 0.0.0
******************************************************************************/
#ifndef __STM32F0XX_IT_H
#define __STM32F0XX_IT_H

#ifdef __cplusplus
extern "C" {
#endif

/*******************************************************************************
* Definitions
******************************************************************************/

/*******************************************************************************
* Variables
******************************************************************************/

/*******************************************************************************
* Function
******************************************************************************/
void NMI_Handler(void);
void HardFault_Handler(void);
void SVC_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);

#ifdef __cplusplus
}
#endif

#endif /* __STM32F0XX_IT_H*/

7. Compile your first project

luos_imgluos_img

You now have a complete functional environment, but what about Luos? Let's find out in the next steps.