Skip to main content
vlal
Associate II
September 16, 2019
Solved

LED blinking using Simulink and STM32-MAT/TARGET not working

  • September 16, 2019
  • 13 replies
  • 3156 views

I have installed STM32-MAT/TARGET , generated configuration with CubeMx, made simulink model, generated c code for keil, and compiled with out errors but the port is not toggling. I have been trying for last two weeks to get it work. I have attached cubemx file and simulink model with this message, kindly someone help me

Matlab2019a

STMcubeMx 5.3

I have tried with the simpleGPIO example supplied also, but that too didn't worked, is there any compatibility issue between the cubeMX and Matlab2019 version?

The examples supplied are made with earlier version of cubeMX and Matlab

This topic has been closed for replies.
Best answer by Cyril FENARD

Hi @vlal​ ,

Your main.c is not correct, stm32xxxx_it.c is missing.

It seems as if STM32\script\customRoutineProcess.tlc is not the correct one.

This file was strongly changed with the 5.1.0 version of STM32-MAT/TARGET (to fit with STM32CubeMX V5.1.0 and later).

Regards.

Cyril

13 replies

Cyril FENARD
ST Employee
September 17, 2019

Hi @vlal​ 

Thank you for giving feedback on our delivery of version 5.1.0 of July 2019.

We will analyze the problem and come back with a solution the next day.

Regards.

Cyril

Cyril FENARD
ST Employee
September 17, 2019

Hi @vlal​ 

In your use-case MATLAB 2019a and STM32CubeMX 5.3.0 are in use, and it is not a problem.

The PIN0 of GPIOA is selected to be toggled and corresponding code is generated correctly:

/* Model step function */
void untitled_step(void)
{
 /* S-Function Block: <Root>/GPIO_Write */
 HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_0);
}

All the GPIOs are used in your STM32CubeMX project.

I simply modified the GPIO settings for pins used for debug (enabling SYS Debug with Trace Asynchronous Sw).

I checked that LED2 can be toggled by PA5 GPIO.

I selected this pin in the GPIO_Write block of the Simulink model, I adjusted solver step size to 0.5s, then regenerated and compiled the project.

The LED is now blinking at the rate of 0.5 time per second.

Hoping it clarified.

Regards

Cyril

vlal
vlalAuthor
Associate II
September 17, 2019

So its working in your set up, It may be a problem in my setup

By the way, I am using Proteus to simulate, I didn't ran on hardware yet

vlal
vlalAuthor
Associate II
September 18, 2019

I accidently flashed a stm32f103C8 with hex file generated with CubeMX HAL libraries for stm32f103C6. Now target cannot be detected from the flashing software, Did the mcu got damaged, can I recover the mcu?

Cyril FENARD
ST Employee
September 19, 2019

​Hi @vlal​ 

I'm not sure posting this last issue here is the right place.

The STM32 ST-LINK Utility (STSW-LINK004) can be found on the ST website and can help you.

You should be able to connect your target (knowing that your ST LINK subsystem is still operational).

Regards.

Cyril

vlal
vlalAuthor
Associate II
September 19, 2019

OK, now its flashing, it was due to wrong GPIO setting, I am working on it

vlal
vlalAuthor
Associate II
September 20, 2019

I tried many times, but I didn't get the LED blink,

I have attached the whole project with this message

Cyril FENARD
ST Employee
September 23, 2019

​Hi @vlal​ ,

You changed board for your project.

I took a look at your C files.

In the current situation, this can not work, calls to step () can not be made because the interrupt is not implemented correctly (remains AutoReloadTimerLoopVal_S not incremented).

I generated my side and got:

void SysTick_Handler(void)
{
 /* USER CODE BEGIN SysTick_IRQn 0 */
{
 extern volatile uint32_t remainAutoReloadTimerLoopVal_S;
 
 /* Manage number of loop before interrupt has to be processed. */
 if (remainAutoReloadTimerLoopVal_S) {
 remainAutoReloadTimerLoopVal_S--;
 }
}
 
 /* USER CODE END SysTick_IRQn 0 */
 HAL_IncTick();
 /* USER CODE BEGIN SysTick_IRQn 1 */
 
 /* USER CODE END SysTick_IRQn 1 */
}

May you cleanup your Matlab session (remove generated folders of Simulink build, cleanup also path to avoid side effects).

Regards.

Cyril

vlal
vlalAuthor
Associate II
September 23, 2019

I have cleaned the path and removed the generated folders of Simulink build and build again

I have attached the resultant project with this message, still the LED is not blinking..

Cyril FENARD
ST Employee
September 24, 2019

Hi @vlal​ ,

Did you also cleanup slprj folder from where your started the Simulink build?

Did you check in the generated folders if Stm32F103C8_stm32/stm32xxxx_it.c is present?

1/ Before launching Simulink Build, set the current working directory as follows:

>> cd 'C:\MATLAB\STM32-MAT'

2/ May you empty the folder of Simulink project, must remain slx and ioc files.

In this way, you will avoid mixing the elements generated by Simulink and the source files generated at the end by STM32CubeMX.

3/ Restart the Simulink build, check main.c and st32f1xx_it.c.

You can also follow the documentation: STM32\STM32_MAT-TARGET_HandsOn.pdf

I cannot bring more. Hoping you will succeed by your side.

Regards

Cyril

vlal
vlalAuthor
Associate II
September 24, 2019

Each time, I delete all contents in the project folder, leaving only ioc and slx.

Last time I set the current working directory as 'C:\MATLAB\STM32-MAT'

"stm32f1xx_it.c" is present in Src folder not in "Stm32F103C8_stm32" folder(Stm32F103C8_stm32/stm32xxxx_it.c not present )

I followed the documentation on: STM32\STM32_MAT-TARGET_HandsOn.pdf