Make an Eclipse project "Portable"

Document created by romain reicher Moderator on May 30, 2017Last modified by romain reicher Moderator on May 31, 2017
Version 9Show Document
  • View in full screen mode

The CubeMX application is a powerful tool that allows you to generate firmware "from scratch" in less than 5 minutes.

The generation of the final project ensures coherent configuration of the STM32 devices and therefore includes all the dependencies of the HAL library.
Then, we get a local project that contains all user files, CMSIS files and HAL library drivers.

As for HAL_Library, you notice that the CubeMX offers either:

  • By copying with your project the library files necessary to your application.
  • Or by linking these files between your project and the relevant CubeMX Repository on your hard disk.

This set of files constituting our project is copied locally on hard drive. Perfect. We can now add our code and give life to our project !


Purpose

However, if you plan to start with a Discovery-Board or other ecosystem board and to have benefit of the BSP libraries, we need to copy the necessary BSP folders, locally from the CubeMX local repository into our new project and configure the paths of these files in the linker.
But, depending on the complexity of the project, with this method, the file size becomes quickly important and once the compilation step is done, the total size can reach 80Mb and more !
In this tutorial, I propose an alternative method for the management of a project. Make an project portable.
Under the Eclipse environment (SW4STM32 or Atollic) this involves using the notion of path variables and build variables. And in this way we obtain a relative structure and completely independent of the static libraries (such CubeMX HAL library) . Only the user files remain in the project.

But what is the advantage of this method ?

  • The project contains only the users files used and not HAL library files.
  • Project refers to HAl, CMSIS or BSP files by relative links and/or virtual folders. Then the project can be copied to any directory, the links will always be kept.
  • Simplifiy sharing on another computer if the CubeMX is also installed. In this case the second user has only one build variable to modify.
  • In the case of updating the CubeMX repository library, simply modify a couple of path/build variable.

Prerequisites and tools required.

For this tutorial I will use a STM32F746NG-Discovery and Eclipse environment SW4STM32.

You also need to download and install STM32CubeMX  and STM32CubeF7 Firmware Package V1.7.0

Let's get started...

STEP 1. Create a Cube project

  • Open STM32CubeMX (version 4.21.0) and create a new project.
  • Select <Board selector> Tab and choose Type of Board field: Discovery and MCU Series field: STM32F7.
  • Then choose STM32F746NG-DISCO board.
 
  • We don't use initial pinout definitions for onboard components. Hit <Ctrl+P> shortcut and confirm to clear pinout configuration.

  • Into Pinout Peripherals tree, expand RCC and select High Speed Clock (HSE) = BYPASS Clock Source
  • Into Clock Configuration tab configure HCLK 216MHz from  HSE.
  • Select Settings from menu Project, give it a name and a location on your computer.
  • Select SW4STM32 Toolchain / IDE and check Generate Under Root. Then OK to close windows settings.
  •  Now we can generate the project. hit <Ctrl+Shift+G> shortcut.

 

STEP 2. Import the project into Eclipse IDE (SW4STM32)

  • Now our project is generated into the location. It contains folders for user code (Src and Inc) and also a Drivers folder which contains CMSIS and HAL Library.
  • We can delete this folder for now. And keep all the others.

 

  • Now open System Workbench IDE and select a directory workspace in same hard disk location where you generate it in step 1.
  • Import the 32F746NGDisco_template project by this way.
  • Right click into Project explore windows and select Import.
  • In Expand General and select Existing Projects into Workspace.
  • Browse for the project location and click OK. Then click Finish to import it.

 

 

  • The project is now visible into Project Explorer windows (on the left), we can expand it to see the structure.
  • We can observe that some unresolved inclusions. And many files are marked with a red cross. We fix this error in the next step.

 

 

STEP3. Configure the project with relative path

Create a Path variable.

  • Into Project Explorer, select project name and hit <Alt+Enter> to open project properties.
  • Expand Ressource and select Linked Resources and Path Variables tab.
  • By default, Eclipe IDE define some path variable such ECLIPSE_ HOME and point to C:\AC6\SystemWorkbench directory.
  • We need to create here another path variable which define the STM32CubeMX repository located on the hard disk of the computer.
  • Click New and define the path variable CUBEF7_INSTALL below. Browse folder and select the STM32Cube repository for STM32F7 device.

  • Then click Ok to return to project properties. And the new path variable should appears as below.

 

Create a Build variable.

  • Now expand C/C++ Build menu and select Build variables.
  • We need to create a build variable in the same way than path variable.

  • Choose Add... and fill the field below with the same variable name than path variable.
  • Check Apply to all configurations
  • Select Type = Directory
  • And browse for the same folder location into STM32Cube_FW_F7 repository.
  • Then OK.

 

 

  • Now you should see the build variable as below.
  • Click Apply and OK to exit.

 

Create linked folder for HAL Library and BSP.

  • Right click on project name and select New Folder.
  • Expand Advanced option and check Folder is not located in the file system (Virtual Folder)
  • Name it Drivers.
  • Then Finish. 

 

  • Repeat in the same way to create two virtual folders into Drivers (BSP and STM32F7xx_HAL_Driver)
  • And create also two virtual folders into BSP\Component and BSP\STM32746G_Discovery as shown below.

 

 

Add HAL Library and BSP files with relative path.

  • Now we need to link HAL library files into virtual folder.
  • Before that, open file Inc\stm32f7xx_hal_conf.h and uncomment all define below (line 51 to 100)
#define HAL_ADC_MODULE_ENABLED
#define HAL_CRYP_MODULE_ENABLED
.........
.........
#define HAL_GPIO_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED
#define HAL_I2C_MODULE_ENABLED
#define HAL_CORTEX_MODULE_ENABLED

 

  • It's time to link HAL library with the virtual folder.
  • Open the folder C:\users\your_name\STM32Cube\Repository\STM32Cube_FW_F7_V1.7.0\Drivers\STM32F7xx_HAL_Driver\Src
  • Select all stm32f7xx_hal_xxx.c you want to use in your project (for me I select all and exclude templates.c)
  • Drag and drop them into IDE in STM327xx_HAL_Driver virtual folder. A new windows appears.

 

  • Select relative locations to CUBEF7_INSTALL (who is the path variable that we create earlier) then click OK.
  • The virtual folder contains now source files of HAL library linked by the path variable CUBEF7_INSTALL.

 

 

  • Do same drag and drop methods with BSP virtual folder with path variable CUBEF7_INSTALL.
  • From C:\Users\your_name\STM32Cube\Repository\STM32Cube_FW_F7_V1.7.0\Drivers\BSP\STM32746G-Discovery drag and drop all .c files into virtual folder \BSP\STM32746G-Discovery. 
  • And from C:\Users\your_name\STM32Cube\Repository\STM32Cube_FW_F7_V1.7.0\Drivers\BSP\Components\ drag and drop  ft5336.c, ov9655., wm8994.c files into virtual folder \BSP\Components.
  • Finally the structure should be same as below.

 

  • Now the project contains all source files needed. In the next step we will configure the linker and compile the project.

 

STEP4. Configure the linker. Compile the project.

  • Into Project Explorer, select project name and hit <Alt+Enter> to open project properties.
  • Go to C/C++ Build and select Settings
  • Into Tool Settings Tab we now change the include paths for header file and use build variable created in Step 3.
  • Note that the build variable should be invoked with the syntax "${CUBF7_INSTALL}/relative path to include"

 

  • Then we need to enable indexer to etablish link between each files.
  • Go to C/C++ General, and check Enable project specific settings.

 

  • Then click Apply and OK to close the properties windows.
  • It's time to refresh all files. Right click on project name in Project Explorer\Index and select Refresh All files.
  • Now build the indexer. Right click again on project name in Project Explorer\Index and select Rebuild.
  • Normally all warning mark and unresolved inclusions error must disappear and we can try to build the entire project with <Ctrl+B> shortcut.
  • It's taking some time because we included all HAL library.
  • And the results is....

 

  • All is OK. No errors. Great !

 

  • Now we have a portable project with a complete linked HAL library and BSP files.
  • In the next step we will add some code to use LCD of STM32F746NG-Discovery by using BSP Library.

 

STEP5. Add some user code.

We just implement some code to display string on the LCD and blink the LED1.

 

In main.c file insert:

/* USER CODE BEGIN Includes */
#include "stm32746g_discovery.h"
#include "stm32746g_discovery_lcd.h"
/* USER CODE END Includes */

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
uint8_t lcd_status = LCD_OK;

/* USER CODE END PV */

 

And the in the main function:

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();

  /* USER CODE BEGIN 2 */
  BSP_LED_Init(LED1);

  /* Configure the User Button in GPIO Mode */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);

  /* Initialize the LCD */
  lcd_status = BSP_LCD_Init();

  /* Initialize the LCD Layers */
  BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, SDRAM_DEVICE_ADDR);

  /* Set LCD Foreground Layer  */
  BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);

  BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
 
  /* Clear the LCD */
  BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  BSP_LCD_Clear(LCD_COLOR_WHITE);

  /* Set the LCD Text Color */
  BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);

  /* Display LCD messages */
  BSP_LCD_DisplayStringAt(0, 10, (uint8_t *)"STM32F746G DISCOVERY", CENTER_MODE);

  BSP_LCD_SetFont(&Font16);
  BSP_LCD_DisplayStringAt(0, 35, (uint8_t *)"Build an Eclipse Project Portable", CENTER_MODE);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
       BSP_LED_Toggle(LED1);
       HAL_Delay(800);
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}

 

  • Now re-build project with <Ctrl+B> and run it on the STM32F746NG-Discovery board (size is bigger !!!)

 

  • In case of HAL Library revision update, you just need to modify the value for path and build variable.
  • If you need to make another project, simply copy and paste it into Project Explorer. The files structure and the Linker settings will be kept.
  • This is the end of the tutorial. 

 

Enjoy.

 

Attachments

    Outcomes