cancel
Showing results for 
Search instead for 
Did you mean: 

STM32Cube and include files

Thomas Carrington
Associate III
Posted on September 02, 2017 at 15:45

Hi Everyone,

I've been using a Nucleo F103RB for a while now, adding onto the default code provided via Atollic's TrueStudio setup. With this, I have been able to initialise and communicate successfully with I2C, SPI and UART.

I now want to see if I can build the project up from scratch using the STM32Cube plug-in (which looks great in terms of getting I/O and interfaces going).

I've had success in getting a LED to flash, so now I want to get the SPI working again.

What I'm trying to do is create a pointer to the SPI interface that I have generated via the cube, this pointer will then be used by my SPI code to communicate. I've put the declaration of this pointer within my code, and when compiling I get the following error:

unknown type name 'SPI_HandleTypeDef''

unknown type name 'GPIO_TypeDef'

.

I managed to fix the GPIO error by adding 'stm32f1xx.h' as included within the code. But this isn't fixing the 'SPI_Handle', which I don't understand as the header which defines this 'stm32f1xx_hal_spi.h' is references (eventually) by 'stm32f1xx.h'.

And if I just straight include 'stm32f1xx_hal_spi', it then starts complaining about unknown type name 'DMA_HandleTypeDef' within 'hal_spi', then about 30+ errors on using the DMA within 'hal_spi'!!

I have a strong feeling that I am missing something, like setting up the project/including something, but for the life of me, I cannot find it. I've configured the project so that it includes the 'Build_Files' which includes the code I'm talking about 'Device.h'.

I've attached a copy of my 'Device.h' code, along with how I've structured the folders for this project.

If anyone can help with fixing this problem I would be grateful.

Cheers - Thomas

9 REPLIES 9
Posted on September 02, 2017 at 15:50

Your project level '

stm32f1xx_hal_conf.h' should have defines indicating the modules to include

The compiler define USE_HAL_DRIVER should also be used.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 02, 2017 at 16:13

Hi Clive,

'USE_HAL_DRIVER' is defined within the project setting, so is there any need to state it within the code?

within stm32f1xx, it references out to the hal, and then down to hal_conf. So is there any need to add the include? - in any way, even with the hal_conf added, I'm still getting the error appear.

Posted on September 02, 2017 at 18:05

You should just need to ♯ include 'stm32f1xx_hal.h', and then uncomment lines in your 'stm32f1xx_hal_conf.h' for the modules you use, along with add the respective .C into the project itself.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 02, 2017 at 18:13

I understand that, the output of the Cube has done that for me already, as the SPI module is already uncommented within 'hal_conf'.

I problem is when I try to call the struct 'SPI_HandleTypeDef', I get an error saying that it doesn't recognise it, even though the SPI module has been enabled...

Thomas Carrington
Associate III
Posted on September 02, 2017 at 21:32

So.....Originally I had the '#include 'Device.h'' call within 'main.h', which appeared to result in these errors appearing.

I tried moving this call to 'main.c'. Lo and behold, no errors are flagged, and it compiles......

Digging into the 'properties' of 'main.h' it appears that it contains no Toolchain, and the 'Paths and Symbols' section is blank (doesn't even state that its a C Compiler like the other files do). So need to update this file so that it contains the correct paths....

Posted on September 02, 2017 at 19:39

I guess you'll need to dive deeper then... In Keil it shows the dependencies, so I can see what gets pulled in, and what is generating code that gets into the final build. Sorry not sufficiently familiar with Atollic or Eclipse to wade into the specifics there. Assume the compiler's telling you the truth, and there is something awry with the defines leading to the inclusion of the prototypes.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 02, 2017 at 21:34

Wait, no header file has the 'Paths and Symbols' section filled....

Posted on September 02, 2017 at 23:37

In Keil most things are relatively pathed, and the tool chain has a search list imparted in the 'Include Paths' dialog that passes those into the compiler command line.

Not sure the main.h does much other than abstract the cpu family and board specific includes

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Mike Veltman
Associate II
Posted on April 27, 2018 at 12:14

I have the same question, how did you solve it (if you did)?