-1
\$\begingroup\$

I'm using the STM32 MAT plugin and embedded coder for Simulink to generate C-Code out of my models to compile them onto an STM32F4. As IDE I use TrueStudio and for my MCU Configuration I use CubeMX.

Because my discrete solver step time in Simulink is set, it seems that the embedded coder tries to make a Software based Interrupt every 0.001 seconds.

 #include "main.h"

void SystemClock_Config(void); static void MX_GPIO_Init(void); #include #include "untitled.h" /* Model's header file / #include "rtwtypes.h" / MathWorks types */

extern RT_MODEL_untitled const untitled_M; extern void untitled_SetEventsForThisBaseStep(boolean_T); static boolean_T OverrunFlags[1]; static volatile uint32_t autoReloadTimerLoopVal_S = 1; static volatile uint32_t remainAutoReloadTimerLoopVal_S = 1;

int main(void) { int_T i; HAL_Init(); SystemClock_Config(); MX_GPIO_Init();

/* Systick configuration and enable SysTickHandler interrupt */ if (SysTick_Config((uint32_t)(SystemCoreClock * 0.001))) { autoReloadTimerLoopVal_S = 1; do { autoReloadTimerLoopVal_S++; } while ((uint32_t)(SystemCoreClock * 0.001)/autoReloadTimerLoopVal_S > SysTick_LOAD_RELOAD_Msk); SysTick_Config((uint32_t)(SystemCoreClock * 0.001)/autoReloadTimerLoopVal_S); } remainAutoReloadTimerLoopVal_S = autoReloadTimerLoopVal_S;//Set nb of loop to do for (i=0;i<1;i++) { OverrunFlags[i] = 0; } untitled_initialize(); while (1) { /*Process tasks every solver time*/ if (remainAutoReloadTimerLoopVal_S == 0) { remainAutoReloadTimerLoopVal_S = autoReloadTimerLoopVal_S; /* Check base rate for overrun */ if (OverrunFlags[0]) { rtmSetErrorStatus(untitled_M, "Overrun"); } OverrunFlags[0] = true; /* Step the model for base rate */ untitled_step(); OverrunFlags[0] = false; } } } /* SysTick_Handler callback function*/ /*This handler is called every tick and schedules tasks*/ void HAL_SYSTICK_Callback(void) { /* For TIME OUT processing */ HAL_IncTick(); /* Manage nb of loop before interrupt has to be processed */ if (remainAutoReloadTimerLoopVal_S) { remainAutoReloadTimerLoopVal_S--; } }

Unfortunately when I try to run the Code, nothing happens. The Compiler always stucks at the if condition in the while (1) Loop. So I see that there's something wrong here with the Interrupt handling, but I don't know how to resolve the issue. Probably you can help

\$\endgroup\$
  • 1
    \$\begingroup\$ Without trying to be a smart aleck, it seems like you need to roll up your sleeves and learn how to use your tools. As somebody who has done things like you're describing quite a few times, just getting up to the point you describe is a 20 to 40 hour process. \$\endgroup\$ – Scott Seidman Apr 24 at 13:16
0
\$\begingroup\$

I think you need to enable the interrupt in your NVIC. Try adding:

NVIC_EnableIRQ(SysTick_IRQn);

before your while loop.

\$\endgroup\$
  • \$\begingroup\$ Hello there, thanks for your answer. unfortunately that doens't make any difference :/ i have to admit that for the clock configuration, i use the pll with and external clock if that helps... \$\endgroup\$ – SiC Apr 24 at 13:11
  • \$\begingroup\$ I did a Workaround by adding HAL_SYSTICK_Callback(); into the SysTick_Handler() function void SysTick_Handler(void) { HAL_IncTick(); HAL_SYSTICK_Callback(); } Don't know if that's the correct way to do it... \$\endgroup\$ – SiC Apr 24 at 14:12
  • \$\begingroup\$ Your startup file creates weak interrupts handlers. You can override this handlers and write your code in the new interrupt handler. What you did now is create a new irqHandler and called your callback function, this is fine. Beware to not call HAL_IncTick twice. \$\endgroup\$ – Wisse Apr 24 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.