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
1 ACCEPTED SOLUTION

Accepted Solutions
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

View solution in original post

14 REPLIES 14
Posted on January 19, 2017 at 20:22

I would imagine the process of integrating CubeMX and BSP as follow:

1. Generate the app skeleton (drivers) using CubeMX (e.g. enable protocols like I2C or SPI required by BSP)

2. Add BSP drivers to be able to use BSP API - I amean easy way of adding BSP drivers without spending hours on solving linker dependencies issues.

===

Perfectly there should be an installer app to install BSP like we do when want to add another nucleo board support to the CubeMX.

Bogdan

Posted on January 19, 2017 at 21:46

I solved the problem with replacing MCU (I simple need to define different MCU in C/C++ tab of the Keil IDE).

The question related to adding BSP driver to the Cubex project is still open.

Posted on January 20, 2017 at 11:49

Hello

Golab.Bogdan

‌,

Thanks for sharing you further suggestions.

I forward your request to our CubeMx team for moreinvestigation.

All your comments and suggestions are welcome to improve our solutions.

Best Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Jeanne Joly
Senior III
Posted on January 26, 2017 at 09:34

Hello

Golab.Bogdan

,

The automatic BSP code generation is under study for the moment, it will be integrated in CubeMX for sure but I can't give you any delivery date for the moment.

So, for the moment, we need to integrate the BSP manually. In the following link ,

doe.john.016

gave a detailed method to add BSP in generated code (

https://community.st.com/0D50X00009XkYXySAN

).

I hope it will help you.

BR. Eric

Posted on January 26, 2017 at 09:55

Hi,

Thank you for the information about BSP & CubeMX integration plans.

I looked quickly into the manual method you pointed out:

-simple stuff (file copying, adding include path search) is easy - that's correct

-the more challenging stuff is related to library dependencies - this is what I am really looking for.

Let me give you an example - an yesterday project.

Let's say that you want to add BSP drivers to the STM32L-Discovery module to easely handle the LCD.

1. Run CubeMX, select LCD, set the mode, etc

2. Generate project skeleton for Keil, copy BSP libs, add BSP include paths - easy stuff

3. Try do add BSP-based LCD function calls to the project

4. Compile - all looks fine but nothing happens.

5. Debugging: you see that LCD init fails (error handler is called and the code stops in while loop)

6. Reason: BSP drivers conflict with CubexMX generated LCD Drivers. The same applies to BSP button or LED drivers.

One would expect that layering model should be in place: BSP drivers should call CubeMX-generated HAL drivers...

Yes, this example is easy but shows what I am talking about.

The

/external-link.jspa?url=http%3A%2F%2Fwww.st.com%2Fen%2Fecosystems%2Fx-nucleo-iks01a1.html

is more complex - or I am not skilled enough to do it following the simplest process: run CubeMX, copy BSP drivers, etc.

I am not an expert in this matter, maybe I am totally wrong and doing something stupid...

Thanks,

Bogdan

Posted on January 26, 2017 at 23:08

If someone from the ST team could describe the process of adding BSP drivers to the CubeMX generated project for more complex case: take NUCLE_F411, generate HAL drivers using CubeMX and add BSP library of the

/external-link.jspa?url=http%3A%2F%2Fwww.st.com%2Fen%2Fecosystems%2Fx-nucleo-iks01a1.html

.

The goal is to successfully compile/link the project with BSP driver added.

I do not need any explanation of how to use BSP drivers - the only thing which is interesting is to establish the procure of resolving compilation / linking errors.

Where the problem is: HAL drivers and BSP drivers parallelly use low level resources. In this particular case errors are related to I2C drivers. This is very similar to the case of STM32L-Diescovery where the conflict of drivers was related to the LCD handlers - both BSP and Cubes generated HAL drivers were in conflict (easy to discover and fix as this case is really simple).

I looked into the HAL and BSP drivers architecture - on the picture attached to the

/external-link.jspa?url=http%3A%2F%2Fwww.st.com%2Fen%2Fecosystems%2Fx-nucleo-iks01a1.html

.manual we can see the BSP and HAL layer overlaping.

I would expect the BSP driver to simply call HAL drivers - the BSP should be a layer up, not parallell layer to avoid conflicts.

Thanks,

Bogdan

Jeanne Joly
Senior III
Posted on January 30, 2017 at 09:36

Hello

Golab.Bogdan

,

I will try to answer your pending questions.

First of all, you said that you encountered an issue : '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 tried specifically your use case and it works on my side. You should do as follow :

  1. open an example of F401,

  2. do the modification you need.

  3. Save it.

  4. Open a new F411 project without doing any modification.

  5. Go to File/Import Project and select the project F401 you just saved. It will import all all your modifications you did for F401 in F4

For your second point, “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.�?

Indeed, a work is ongoing inside STMicroelectronics, to port the examples into CubeMX in order to simplify the merge of examples in the CubeMX code generated.

For the moment, we need to merge the examples manually on top of the CubeMX code generated and I faced, as you, some compilation/linking issues.

I took the examples of L476G Discovery board on which I integrate the BSP. I can give you some tips for this particular use casein order to suppress compilation and linking issues :

  1. Import BSP/Components and BSP/STM32L476G-Discovery directories.

  2. In CubeMX, activate DFSDM1, I activated Channel 0 to parallel input mode.

  3. In Drivers/STM32L4xx_HAL_Driver, copy/paste stm32l4xx_hal_dfsdm.c and stm32l4xx_hal_dfsdm.h files.

  4. In Drivers/BSP/STM32L476G-Discovery/stm32l476_discovery_audio.c, delete the definition of the functions HAL_DFSDM_ChannelMspInit, HAL_DFSDM_ChannelMspDeInit,

    HAL_DFSDM_FilterMspInit and HAL_DFSDM_FilterMspDeInit. Or else, it will be defined two times (in stm32l476g_discovery_audio.c and in stm32l4xx_hal_msp.c)

  5. There is a mistake on our side (that will be corrected in the next CubeMX release - CubeMX4.20), you need to correct it manually. Two extra accolades are in stm32l4xx_hal_msp.c in the definition of HAL_DFSDM_FilterMspInit and HAL_DFSDM_ChannelMspInit, just after

    if(DFSDM1_Init ==0) { /* USER CODE BEGIN DFSDM1_MspInit 0 */ ……..

    DFSDM1_Init++;

    } } ==>

    this accolade needs to be deleted.

After those modifcations, I was able to compile and link the project.

Furthermore, you have an example with BSP and LCD working in STM32Cube\Repository\STM32Cube_FW_L4_V1.6.0\Projects\STM32L476G-Discovery\Examples\BSP\EWARM.

Hope this information will help you.

BR. Eric

Posted on January 30, 2017 at 10:10

Hi Eric,

Thank you very much for your help.

The first problem I also solved myself (I mentioned it just after publishing the original question in this post):

-opened the example for F401 (the one with Terminal Logging) in Keil

-replaced the F401 device with F411 in Options->Device tab

-In Options->C/C++ tab I replaced the STM32F401xE with STM32F411xE

====

The second problem - I will check the solution for sure.

Thanks for great support!

Bogdan

Posted on January 30, 2017 at 12:44

Hi Eric,

If it is not a problem, could you please do the same excecise for CubeMX generated default project for nucleo-F411 board and show how to add BSP drivers for

/external-link.jspa?url=http%3A%2F%2Fwww.st.com%2Fen%2Fecosystems%2Fx-nucleo-iks01a1.html

module?

I was not able to capture the idea behind the example with discovery board and its on-board resources.

Thanks,

Bogdan