How do I access STM32 HAL headers in Simulink S-Function-Builder?
35 views (last 30 days)
Show older comments
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?
1 Comment
Elizabeth
on 2 May 2025
Were you abe to figure this out? I am also trying to use STM functions in c code in a simulink model and am finding it difficult.
Answers (1)
Mark McBroom
on 30 Mar 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.
- 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.
1 Comment
Arun
on 25 Oct 2024
Hello Mark
Does it mean we cannot directly access STM32 registers directly from MATLAB/SImulink?
I am also looking to create s-function/ Builder to access DWT CYCCNT of STM32 so I can get CPU utilization time, Is it possible to access register DWT directly from MATLAB/Simulink>?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!