Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


Custom Library Compilation Error

Hi All,

I am pretty to new to all of this and I am in the process of learning to create my own library. I am using the STM32F446 Nucleo board with a BNO055 IMU. I am very familiar with the BNO055 and I have successfully used it with Arduino, but now the time is to move on. I am using a Windows 10 machine with the latest version of SW4STM32. So, to my problem:

I want to setup a header and a source file to deal with the I2C communication functions, so I have called them I2C.h and I2C.c. They are in the respective Inc and Src folders in the project, they are not in the their own folders. I have attached the header and the source file because there is no code formating functionality on the forum, or none that I can find. If there is please let me know how to code format, for direct me with a link.

When I compile this it gives me the following error: “‘hi2c1’ undeclared (first use in this function) | I2C.c | C/C++ Problem”

I could understand if it were one of the variable that I have declared incorrectly, but it is a TypeDef defined by CubeMX! Another anomoly is that if I declare there function prototypes and I define them in main.c, they run perfectly! Can any body help shed some light on this please, is this perhaps a linking issue rather than a coding error? I hope the post is not too detailed and if you need more info, please let me know.

Thanks,

Dylan

Hi

Where is this piece of memory called hi2c1 implemented?

Dieter


Hi Dieter,

It is declared under private variables that is generated by CubeMX as I2C_HandleTypeDef in main.c and then the I2C_HandleTypeDef declaration is in the stm32f4xx_hal_i2c.h.

I have tried to include stm32f4xx_hal_i2c.h and stm32f4xx_hal.h in I2C.c and I2c.h but to no avail.

Thanks for your help!

Kind regards,

Dylan

Hi

You can not use a variable of whatever type in a .c file if it’s not known there.
Tell CubeMX to generate separate pairs of .c .h files for every peripheral.

Then the the variable is declared extern in the .h file and defined and used within the .c file.
Thereafter you can access the variable whereever the .h file is included.

Or use main.h.

Dieter


Dieter, you are the man! Thank you! That has solved it! I really appreciate the help, thank you! :-)

 

Newest Forum Posts

  1. Монтаж камина с грилем в Москве - установка и барбекю by KpddomErorb, 2025-05-10 18:28
  2. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  3. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  4. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  5. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  6. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  7. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  9. Build a project in "release" mode by tang, 2025-02-20 10:36
  10. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35

Last-Modified Blogs