1.3k views
in System Integration by
Hello,

I'm trying to integrate a CubeMX code with my GUI and there is an error occurring (gccbuildenviroment):

Compiling ../../Source/DeviceDriver.c
../../Source/DeviceDriver.c: In function 'DeviceDriver_SetLedStatus':
../../Source/DeviceDriver.c:330:13: error: storage class specified for parameter 'MX_GPIO_Init'
 static void MX_GPIO_Init(void);
             ^~~~~~~~~~~~
../../Source/DeviceDriver.c:331:1: error: expected declaration specifiers before 'HAL_Init'
 HAL_Init();
 ^~~~~~~~
../../Source/DeviceDriver.c:329:6: error: old-style parameter declarations in prototyped function definition
 void DeviceDriver_SetLedStatus( XInt32 aValue )
      ^~~~~~~~~~~~~~~~~~~~~~~~~
../../Source/DeviceDriver.c:348:24: error: 'LED_0_GPIO_Port' undeclared (first use in this function); did you mean 'LED1_GPIO_PORT'?
     HAL_GPIO_WritePin( LED_0_GPIO_Port, LED_0_Pin, GPIO_PIN_SET);
                        ^~~~~~~~~~~~~~~
                        LED1_GPIO_PORT
../../Source/DeviceDriver.c:348:24: note: each undeclared identifier is reported only once for each function it appears in
../../Source/DeviceDriver.c:348:41: error: 'LED_0_Pin' undeclared (first use in this function); did you mean 'LED1_PIN'?
     HAL_GPIO_WritePin( LED_0_GPIO_Port, LED_0_Pin, GPIO_PIN_SET);
                                         ^~~~~~~~~
                                         LED1_PIN
make: *** [Obj/DeviceDriver.o] Error 1

I'm trying to flash a LED when a button on the display is pressed, I did it editing the DeviceIntegration example. I changed the DeviceDriver trying to include HAL library and using a configuration made on cubemx/keil:

/*
   Include all necessary files to access the real device and/or to get access
   to the required operating system calls.
*/
#include "stm32746g_discovery.h"
#include "ewrte.h"
#include "ew_bsp_inout.h"
#include "stm32f7xx_hal.h"

.

.

.

/*******************************************************************************
* FUNCTION:
*   DeviceDriver_SetLedStatus
*
* DESCRIPTION:
*   This is a sample for a function called from the device class, when a
*   property has changed. As a result, the corresponding value of the real
*   device should be changed.
*   In this implementation simply the LED is switched on or off.
*
*******************************************************************************/
void DeviceDriver_SetLedStatus( XInt32 aValue )
static void MX_GPIO_Init(void);
HAL_Init();

{
  /*
     In case you are using an operating system to communicate with your
     device driver that is running within its own thread/task/process,
     send a message to the device driver and transmit the new value.
     Please note, that this function is called within the context of the main
     GUI thread.
  */

  /*
     Here we are accessing directly the device driver by calling a certain
     BSP / driver function.
  */

  if ( aValue )
    HAL_GPIO_WritePin( LED_0_GPIO_Port, LED_0_Pin, GPIO_PIN_SET);
  else
    HAL_GPIO_WritePin( LED_0_GPIO_Port, LED_0_Pin, GPIO_PIN_RESET);
}

/*******************************************************************************

Please help me
by
The thing is, how can I integrate a code made on cubemx/keil with my GUI?
I need to activate the stm32f7 gpio's according to the b uttons that  user gonna press on display

1 Answer

+1 vote
by
Hello Lucas,

well,the first thing is that in your attached code is a general C issue. The function body of your 'DeviceDriver_SetLedStatus' function is not under their function header, see:

void DeviceDriver_SetLedStatus( XInt32 aValue )  //<------------- Function header
static void MX_GPIO_Init(void);  //<---------- Placed at the wrong position!
HAL_Init();   //<---------- Placed at the wrong position!

{ // <------------- Begin of function body

//...

}

By the way, the HAL functions are already available in 'Device Driver.c'. The HAL will be initialized via Main.c with ' #include "stm32746g discovery.h" '.

To integrate a CubeMX Code you should use the target apecific files at the target specific folder, in your case the 'ew_bsp_inout.c' and 'ew_bsp_inout.h'.

Just extract the necessary parts from the initialization functions from your cube generated code, they are beginning with 'MX_...'.

Kind regards

Tim
by
Thank you, I gonna try it!
by
Hey Tim,

Thanks for your help but I couldn't make it work.
What do I have to change in 'ew_bsp_inout.c' and 'ew_bsp_inout.h'.?

And what about the changes in  'Device Driver.c'?

I'm a beginner and I appreciate your help.

 

Lucas
by
Hello Lucas,

if you work with a STM32F746 board, as shown in you code, you can use the example 'DeviceIntegration'. This example includes how to read and write pins of the ST board.

In fact this example already includes to flash a LED with an button on the GUI. You can find this example under 'Example/DeviceIntegration'.

All parts in the file 'DeviceDriver.c' which are excluded by the '#ifdef _ApplicationDeviceClass_' makro are in use with this example.

Have you tried this example?

Kind regards
Tim
by

Tim,

I've read the example and documentation but I couldn't make it work yet.
I tried to modify the example 'DeviceIntegration' to flash a LED connected in a GPIO (PC7 as table 4 from User Manual).

  • Apparently, the problem is that I'm not declaring this GPIO,  I tried in many ways to declare it in  'ew_bsp_inout.c' but couldn't make it. I've called it LED_0 (custom name from cubemx), PC7 (STM32 Pin name from user manual), D0 (Pin name from user manual) and nothing.
  • I added 'static void MX_GPIO_Init(void);' at the beginning of  'ew_bsp_inout.c' and changed the function 'EwBspConfigButton' to:

void EwBspConfigButton ( TButtonCallback aButtonCallback )
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Enable GPIOI clock */
  KEY_BUTTON_GPIO_CLK_ENABLE();

  /* Configure PC7 pin as input floating */
   
 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStructure.Pull = GPIO_NOPULL;
  GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);

  /* Enable and set EXTI Line Interrupt to the lowest priority */
  HAL_NVIC_SetPriority( KEY_BUTTON_EXTI_IRQn, 8, 0 );
  HAL_NVIC_EnableIRQ( KEY_BUTTON_EXTI_IRQn );

  ButtonCallback = aButtonCallback;
}

which I got from the cubemx genereted code.

  • On 'EwBspConfigLed' I wrote:

void EwBspConfigLed( void )
{
  BSP_LED_Init( PC7 );
}

  • On 'EwBspLedOn' I wrote: 

void EwBspLedOn( void )

{
  HAL_GPIO_WritePin( PC7_GPIO_Port, PC7_Pin, GPIO_PIN_SET);
}

  • ' EwBspLedOff':

void EwBspLedOff( void )
{
  HAL_GPIO_WritePin( PC7_GPIO_Port, PC7_Pin, GPIO_PIN_RESET);
}

 

  • I'm getting the following error:

Compiling ../../../TargetSpecific/ew_bsp_inout.c
../../../TargetSpecific/ew_bsp_inout.c: In function 'EwBspConfigLed':
../../../TargetSpecific/ew_bsp_inout.c:144:1: error: too few arguments to function 'BSP_LED_Init'
 BSP_LED_Init( PC7 );
 ^~~~~~~~~~~~
In file included from ../../../TargetSpecific/ew_bsp_inout.c:30:0:
../../../ThirdParty/STM32Cube_FW_F7/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery.h:306:11: note: declared here
 void      BSP_LED_Init(Led_TypeDef Led);
           ^~~~~~~~~~~~
../../../TargetSpecific/ew_bsp_inout.c: In function 'EwBspLedOn':
../../../TargetSpecific/ew_bsp_inout.c:164:22: error: 'PC7_GPIO_Port' undeclared (first use in this function); did you mean 'MX_GPIO_Init'?
   HAL_GPIO_WritePin( PC7_GPIO_Port, PC7_Pin, GPIO_PIN_SET);
                      ^~~~~~~~~~~~~
                      MX_GPIO_Init
../../../TargetSpecific/ew_bsp_inout.c:164:22: note: each undeclared identifier is reported only once for each function it appears in
../../../TargetSpecific/ew_bsp_inout.c:164:37: error: 'PC7_Pin' undeclared (first use in this function)
   HAL_GPIO_WritePin( PC7_GPIO_Port, PC7_Pin, GPIO_PIN_SET);
                                     ^~~~~~~
../../../TargetSpecific/ew_bsp_inout.c: In function 'EwBspLedOff':
../../../TargetSpecific/ew_bsp_inout.c:184:22: error: 'PC7_GPIO_Port' undeclared (first use in this function); did you mean 'MX_GPIO_Init'?
   HAL_GPIO_WritePin( PC7_GPIO_Port, PC7_Pin, GPIO_PIN_RESET);
                      ^~~~~~~~~~~~~
                      MX_GPIO_Init
../../../TargetSpecific/ew_bsp_inout.c:184:37: error: 'PC7_Pin' undeclared (first use in this function)
   HAL_GPIO_WritePin( PC7_GPIO_Port, PC7_Pin, GPIO_PIN_RESET);
                                     ^~~~~~~
../../../TargetSpecific/ew_bsp_inout.c: At top level:
../../../TargetSpecific/ew_bsp_inout.c:38:13: warning: 'MX_GPIO_Init' declared 'static' but never defined [-Wunused-function]
 static void MX_GPIO_Init(void);
             ^~~~~~~~~~~~
make: *** [Obj/ew_bsp_inout.o] Error 1

 

  • I'm probably doing some huge nonsense, if you can help me I'll be glad.

 

Thanks in advance,

Lucas

by

Hello Lucas,

Are you using the STM32F746G-DISCO Board?

This board has no LED at GPIO port PC7 and all other LEDs, instead of still used LD1, are in use for other functions and not accessible with the GPIO of the microcontroller, see:

LD1 --> Connected to PI1

LD2 --> Connected to the power supply

LD3 -->  Connected to STMPS2151STR

LD4 --> Connected to T1 9013-SOT23

LD5 -->  Connected to T2 9013-SOT23

LD6 -->  Connected to STMPS2141STR

LD7 --> Connected to LED_STLINK

 

As reason of this the BSP doesn't define/support the LD2 LD7 and therefore it is not able to access to this LEDs with just using the BSP functions. Additionally it is not able to use the ‘BSP_LED_Init( PC7 )’ with ‘PC7’ as parameter. ‘PC7’ was never defined as legal macro.

If you want to rewire the signal from LD1 (PI1) to any other port, define a new LED in your BSP or just adapt ‘stm32746g_discovery.h’ at line 106-111 with another port for example wired to your custom LED.

Moreover the way to use a HAL_GPIO_Init() function is to use a predefined macro for the port and pin. Your parameter 'PC7_GPIO_Port' is not a legal macro and not defined in any HAL file. For example to access to the port PC7 you have to use  this:

/* Configure PC7 pin as input floating */
  GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING_FALLING;
  GPIO_InitStructure.Pull = GPIO_NOPULL;
  GPIO_InitStructure.Pin = GPIO_PIN_7;
  HAL_GPIO_Init( GPIOC, &GPIO_InitStructure );

Kind regards

Tim

by
Thank you Tim,

It worked now, I had to adapt 'stm32746g_discovery.h' as you said, also 'stm32746g_discovery.c' and  'ew_bsp_inout.c'.

Following the steps to flash LED1, to flash a external LED connected to a GPIO (PC7).

My objective is to control some contactors, so I'm starting with LED's. Next step is to write the logic of the operations and read some values inserted by the user on the GUI.

Thanks for your attention, it's awesome to have somewhere to ask for help.

You gonna see me here again hahahah

 

Best Regards,

Lucas

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...