How do I access STM32 HAL headers in Simulink S-Function-Builder?

18 visualizaciones (últimos 30 días)
Lorenz Handschack
Lorenz Handschack el 24 de Mzo. de 2022
Respondida: Mark McBroom el 30 de Mzo. de 2022
I'm using an STM32 Nucleo L476RG working on a controller for an inverted pendulum.
In order to collect RPM readings from the motor's encoder I tried to create an S-Function with the S-Function-Builder block in order to initialize registers and obtain RPM readings. However, when I try to include STM32 HAL header files I get errors like 'fatal error C1083' with messages like '"stm32l4xx_hal_tim.h": No such file or directory'.
I was under the assumption I'd be able to use HAL headers when using the 'Simulink Coder Support Package for STMicroelectronics Nucleo Boards' add-on. Is there anything else I need in order to use them?

Respuestas (1)

Mark McBroom
Mark McBroom el 30 de Mzo. de 2022
What is the purpose of the C Coder you are trying to integrate with S-Function Builder? The purpose of S-Function builder is to bring algorithmic code into Simulink, not code that access STM32-specific peripherals. S-Function builder compiles and links C/C++ code into a Windows mex functionn ( DLL ) . STM32 specific code/headers will not compile. There are a couple of ways to work around this.
  1. If the C code is mostly algorithmic, you can use preprocessing macros to ignore the STM32-specific code when compiling the code for S-Function builder.
2. If the code is for a device driver, you can create a "stub" version of the C function that provides a simulation of the device... for example if it is a function to read A2D, for simulation the function could just return a number between 0 and 255. And then when compiling code for the target processor, replace the stub C function with the STM32 version of the C function.

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by