AnsweredAssumed Answered

STM32-MAT/Target Code Generation Issue using Matlab Simulink

Question asked by Florian on Apr 28, 2015
Latest reply on Oct 6, 2015 by 68516
Hi all, 
I am trying to generate a working C code using the Matlab/Simulink package STM32-MAT provided by ST. 

I am using Matlab R2014a v8.3 on Windows 7
I am using TrueSTUDIO v5.3.0 as toolchain
I am using the STM3CubeMx v4.7.0, with the Firmware Package Name and version "STM32Cube FW_F4 V1.5.0

I built the model called TestUSART_Rcv_Send_SIT in "normal" mode (No PIL) in the folder STM32demos/USART. 
It opens the associated.ioc file  and in the Project Settings I selected the Toolchain / IDE TrueSTUDIO. 
I generated the code, opened the TrueSTUDIO project, and tried to build it. 

However, I have a plethora of compilation errors as illustrated on the enclosed screenshot
In addition, when I looked at the main.c file generated by the Cube, the code seems obsolete with lines like while(1) loop from the copy paste code above.  And I don't know why. 

int main(void)
{
 
  /* USER CODE BEGIN 1 */
  /* Data initialization */
  int_T i;
 
  /* USER CODE END 1 */
 
  /* MCU Configuration----------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();
  MX_USART1_UART_Init();
 
  /* USER CODE BEGIN 2 */
  /* 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
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */
 
  /* USER CODE BEGIN 3 */
    OverrunFlags[i] = 0;
  }
 
  /* Model initialization call */
  TestUSART_Rcv_Send_SIT_initialize();
 
  /* Real time from systickHandler */
    /*Process tasks every solver time*/
      remainAutoReloadTimerLoopVal_S = autoReloadTimerLoopVal_S;
 
      /* Check base rate for overrun */
        rtmSetErrorStatus(TestUSART_Rcv_Send_SIT_M, "Overrun");
      }
 
      OverrunFlags[0] = true;
 
      /* Step the model for base rate */
      TestUSART_Rcv_Send_SIT_step();
 
      /* Get model outputs here */
 
      /* Indicate task for base rate complete */
      OverrunFlags[0] = false;
    }
  }
 
  /* USER CODE END 3 */
 
}


The building process from Matlab provides a report where the C codes are generated. I copied the code inside the "USER CODE 3" of the main.c generated by Matlab and replace it in the main.c generated by the Cube. Now the compilation is fine, but it doesn't seem that this main.c has a real meaning or has something to do with the functionality described in the Simulink Model; in that case "Wait for 10 char on USART Rx and send char back to USART Tx" . 
The same problem occurs for the models entitled SimpleGPIO.slx in STM32demos/GPIO and the generated main function is nearly the same. 

Do you have any ideas about 
Why Do I have this issue and how can i resolve it?

Thanks for your help




Outcomes