cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX integration with BSP drivers

Posted on January 19, 2017 at 19:52

I have been using the CubexMX for a few years and have no problems with programming nucleo and discovery boards.

I am using Keil IDE.

I recently bough the

http://www.st.com/en/ecosystems/x-nucleo-iks01a1.html

and have some problems with integration it with nucleo-F411.

===

Starting with the library description and trying to understand all the dependencies seems to be daunting task.

I tried it but I found it difficult to solve library dependencies issues. I am not talking about what function to call - it's rather inter library dependencies issues.

===

Opening already existing example project for F401 and replacing the MCU with F411  gives so many compilation errors so I rejected the idea for now.

===

I wonder if someone have some experience how to quickly integrate the CubeMX-generated program skeleton with BSP drivers. The goal is to have compilation/linking error free application skeleton.

The Getting started document for x-nucleo boards is focused on general ideas of the HAL and BSP layers.

I am looking for more practical approach of integrating BSP with Cubex.

Thanks for any suggestion,

Bogdan

#bsp #cube-mx
14 REPLIES 14
Posted on February 01, 2017 at 19:12

Hi Sirma,

Thank you for your effort.

What you have prepared always works as you do not call any MEMs API in your project. It's pure app skeleton - no api is called. No issues then.

===

The fun begins when you try to call any API e.g. BSP_TEMPERATURE_Init( HTS221_T_0, &HTS221_T_0_handle )

When you add required include files (#include 'x_nucleo_iks01a1.h', #include 'x_nucleo_iks01a1_temperature.h', etc).

At some point you get:

*** Using Compiler 'V5.06 update 4 (build 422)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'

Build target 'F401-MEMs'

compiling x_nucleo_iks01a1.c...

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(62): error:  #20: identifier 'I2C_HandleTypeDef' is undefined

  static I2C_HandleTypeDef I2C_EXPBD_Handle;

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(286): warning:  #223-D: function 'HAL_I2C_GetState' declared implicitly

    if(HAL_I2C_GetState( &I2C_EXPBD_Handle) == HAL_I2C_STATE_RESET )

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(286): error:  #20: identifier 'HAL_I2C_STATE_RESET' is undefined

    if(HAL_I2C_GetState( &I2C_EXPBD_Handle) == HAL_I2C_STATE_RESET )

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(293): error:  #20: identifier 'I2C_DUTYCYCLE_2' is undefined

      I2C_EXPBD_Handle.Init.DutyCycle = I2C_DUTYCYCLE_2;

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(304): error:  #20: identifier 'I2C_ADDRESSINGMODE_7BIT' is undefined

      I2C_EXPBD_Handle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(309): warning:  #223-D: function 'HAL_I2C_Init' declared implicitly

      HAL_I2C_Init( &I2C_EXPBD_Handle );

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(312): warning:  #223-D: function 'HAL_I2C_GetState' declared implicitly

    if( HAL_I2C_GetState( &I2C_EXPBD_Handle) == HAL_I2C_STATE_READY )

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(312): error:  #20: identifier 'HAL_I2C_STATE_READY' is undefined

    if( HAL_I2C_GetState( &I2C_EXPBD_Handle) == HAL_I2C_STATE_READY )

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(338): warning:  #223-D: function 'HAL_I2C_Mem_Write' declared implicitly

    status = HAL_I2C_Mem_Write( &I2C_EXPBD_Handle, Addr, ( uint16_t )Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Size,

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(338): error:  #20: identifier 'I2C_MEMADD_SIZE_8BIT' is undefined

    status = HAL_I2C_Mem_Write( &I2C_EXPBD_Handle, Addr, ( uint16_t )Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Size,

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(338): warning:  #188-D: enumerated type mixed with another type

    status = HAL_I2C_Mem_Write( &I2C_EXPBD_Handle, Addr, ( uint16_t )Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Size,

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(371): warning:  #223-D: function 'HAL_I2C_Mem_Read' declared implicitly

    status = HAL_I2C_Mem_Read( &I2C_EXPBD_Handle, Addr, ( uint16_t )Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Size,

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(371): error:  #20: identifier 'I2C_MEMADD_SIZE_8BIT' is undefined

    status = HAL_I2C_Mem_Read( &I2C_EXPBD_Handle, Addr, ( uint16_t )Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Size,

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(371): warning:  #188-D: enumerated type mixed with another type

    status = HAL_I2C_Mem_Read( &I2C_EXPBD_Handle, Addr, ( uint16_t )Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Size,

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c(399): warning:  #223-D: function 'HAL_I2C_DeInit' declared implicitly

    HAL_I2C_DeInit( &I2C_EXPBD_Handle );

..\Drivers\BSP\X_NUCLEO_IKS01A1\x_nucleo_iks01a1.c: 8 warnings, 7 errors

compiling main.c...

'F401-MEMs\F401-MEMs.axf' - 7 Error(s), 8 Warning(s).

Target not created.

==================

Anyway, I gave up. I spent too much time on this. It seems too difficult to use MEMs board for me.

Thank you for your effort.

Bogdan

Posted on February 01, 2017 at 18:35

Hello Bogdan,

The main concept is that the BSP corresponding to the extension boards needs to be copied into the drivers directory.

I did the following to make it compilable under Eclipse:

  1. Create a project with CubeMX
  2. Download the IKS01A1 zip from this page:

    https://my.st.com/content/my_st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-expansion-software/x-cube-mems1.license%3d1485961007519.html

  3. expand the zip and copy this BSP directory (en.x-cube-mems1\STM32CubeExpansion_MEMS1_V3.0.0\Drivers\BSP) into the Drivers directory generated by CubeMX
  4. Then I had to add USE_STM32F4XX_NUCLEO in Preprocessor settings (Project->Properties->C/C++ Build->Settings->Tools Settings ->Preprocessor)
  5. I had to add all new includes from BSP : BSP/Components/Common,hts221,lis3mdl,lps22hb,lps25hb, lsm6ds0, lsm6ds3, lsm6dsl, lsm303agr (Project->Properties->C/C++ Build->Settings->Tools Settings ->Includes)
  6. Then clean and build

This built well in my machine.

You have to see the BSP as an HAL upper layer, to help on this IKS01A1 board.

Hope it help.

Kind regards

Sirma

Posted on February 01, 2017 at 23:44

Hi Sirma / Eric,

I tried again and I think I found the final solution:

I. Follow your procedure but point 1) shall be changed to:

Create a project with CubeMX and enable I2C1 because the BSP drivers will use it

This way you will eliminate all I2C related error

II. Include the following files in your main.c

#include 'x_nucleo_iks01a1.h'

#include 'x_nucleo_iks01a1_temperature.h'

#include <string.h>

#include <math.h>

Note :string.h and math.h are required because I reused an example function.

III. Add the pointers required by MEM APIe.g. for temperature sensor:

    static void *HTS221_T_0_handle  = NULL;

IV. Use API for example:

    BSP_TEMPERATURE_Init( HTS221_T_0, &HTS221_T_0_handle );

    BSP_TEMPERATURE_Sensor_Enable( HTS221_T_0_handle );

    Temperature_Sensor_Handler( HTS221_T_0_handle );

    BSP_TEMPERATURE_Sensor_Disable( HTS221_T_0_handle );

I reused Temperature_Sensor_Handler( HTS221_T_0_handle ); for simplicity

V. Copy the example function to main.c:

static void Temperature_Sensor_Handler( void *handle )

{

...

}

VI. Add required *.C files to your project (in this case *.C files from the drivers folders e.g. in my case

              <FileName>x_nucleo_iks01a1_temperature.c</FileName>

              <FileName>HTS221_Driver.c</FileName>

              <FileName>HTS221_Driver_HL.c</FileName>

              <FileName>x_nucleo_iks01a1.c</FileName>

              <FileName>LPS22HB_Driver.c</FileName>

              <FileName>LPS22HB_Driver_HL.c</FileName>

              <FileName>LPS25HB_Driver.c</FileName>

              <FileName>LPS25HB_Driver_HL.c</FileName>

===

Summary: It seems that CubeMX and MEMs BSP can be easly integrated.

The general idea is:

-generate CubeMX and enable required resources. In case of MEMs it's I2C1, In case of L476G (Eric's example) it's

DFSDM1

-add include search paths to your project

-add *.C files from Drivers folders to satisfy linker

-then work with the API

===

Sirma/Eric,

Thank you very much for great support.

Bogdan

victagayun
Senior III

Why cant CudeIDE add the BSP folder anyway? Just a few MBs.

Until there is a better solution, just add the BSP folder when generating projects by CubeIDE together with the include paths and linker paths.

This way we can reduce the problems and confusions.

Copy here, copy there, add paths to this and that.

victagayun
Senior III

Why cant just copy the whole BSP folder and add in the include paths and also symbols.

The folder is just few MBs.

This way it wont create any confusion among newbie like me.