cancel
Showing results for 
Search instead for 
Did you mean: 

Timer-Matlab-codegenration

OAlsh
Associate

Dear ST community,

I'm using MATLAB Simulink to implement a BLDC-motor control. Therefore I use the Target Support Package-STM32 Adapter (STM32-MAT/TARGET).

I have problems with the Timer block of this block set.

For a simple test, I designed a control for the built-in LED to blink using the Timer block.

I have done the needed configurations using STM32CubeMX, and Simulink according to the Hands On document (STM32-MAT/TARGET Hands On Rev 2.2).

After building the model and opening the MDK-version 5 from Keil, the generated code is not correctly built. 

In the main.c the ‘Infinite loop’ ‘Real time from systickHandler’ is running the function LED_Timer_step(); but this function in LED_Timer.c is empty. (See Figure 1)

So the function LED_Timer_step(void) is doing nothing, and therefore the executed code in the ‘Infinite loop’ is doing nothing and the LED is not blinking. 

The LED is just turning on because of the function LED_Timer_initialize(); which runs before the ‘Infinite loop’ . The initialization function is shown in Figure 3.

The main function is shown in figure 2 

The Matlab is not generating the code correctly, it should build a code for the function LED_Timer_step(). 

Another point; according to (STM32-MAT/TARGET Hands On Rev 2.2) three files are generated:

  1. .mlproject: Generated from MATLAB®. Contains information about .c/.h files to add to project from MATLAB®.
  2. .mxproject: Generated from STM32 CubeMX. Contains information about .c/.h files generated from STM32 CubeMX.
  3. .script: Generated from MATLAB®. Contains STM32CubeMX command to generate project.

In my case .mlproject is replaced by .extSettings, see figure 4

Does this have any effect?

P.S. While working on other blocks from Target Support Package-STM32 Adapter (except TIMERS) the simulation works with no errors.

Do you recommend using a certain version of MATLAB?

Why is the code not generating correctly?

Best Regards 

 Omar Alshishani

5 REPLIES 5

​Hello Omar,

.mlproject has been replaced with .extSettings and it doesn't change anything regarding your issue.

Can you please put a snapshot of Simulink model?

Your Simulink model should manage Led (GPIO output) or you must connect Timer output to the Led.

Best regards

Pascal

FGira
Associate

Dear all,

I have a similar issue.

I had a code working so well (Win7 + 2016b ) but I moved to Win10+2017b and the new version of cubeMX and STM32-MAT.

What happens is that the timer are not working (Code is OK for USART and GPIO). Only timers have problem now. This happens to Nucleo401RE and disco401.

Do you have idea about my issue?

if needed, I can send additionnal files.

Best regards

Frédéric.

​Hello Omar,

it is normal that Led_timer_Step function is empty in your generated code.

It meens that it is not manage in pooling mode or synchronous mode but from interrupts.

I can see that update interrupt function is initialized correctly to TIM1_ItUpFcn.

But I suppose that TIM1_itUpFcn (in ***_TIM.c file) is empty too.

To generate code in the interrupt functions, you must validate interrupt outputs, connect a Simulink Function-call Subsystem (ports & subsystems) to this output and put your Simulink model into this function model. Like in attached document.

Then, here for example, HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); is generated and led toggle every second.

Best regards

Pascal

BMOHA.7
Associate

Hi0690X000006Cv6xQAC.png,

Although I used the right configuration, i have the same issue with TIM1 & TIM6 (refer to the attached figure). Did you find a solution ?

Best regards

OOleg
Associate II

Hi to all!

Solve problem with the timer endless loop.

The solution is to setting the timer parameter "Counter Period ..." to 1 or higher when making the setup in STM32CubeMx.

Otherwise code just stuck in "if (remainAutoReloadTimerLoopVal_S == 0) {" line.

Best regards,

Siegurd.