Including custom code

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Including custom code

1,928 次查看
raghurajappa
Contributor IV

I am getting an error when I try to build a model which includes custom code. The custom code I used is from https://community.nxp.com/thread/450048  
Please find attached the error. I think it has to do with Simulink 2017b. But I am unable to solve the error. 

0 项奖励
2 回复数

1,537 次查看
mariuslucianand
NXP Employee
NXP Employee

Hello raghurajappa,

Sorry for our delayed answer.

It looks like when compiles, the mwSize variable type has not been defined, probably a file must also be included. 

For this approach of custom code insertion, we also have an example here How to put S32K MCU into sleep (low power mode)? , but just take the .slx model as example, and do not copy those s32k  files into your toolbox because it handles another toolbox. 

Another easier way of injecting custom code into the model is to use the Custom Code blocks from the Simulink Coder (see the image attached), from the Simulink library. The System Initialize block will inject the code in the generated initialize function and the System Outputs blocks will put your code in the step function.

pastedImage_2.png

Hope this helps, 

Marius

0 项奖励

233 次查看
AlvaroCervantes
Contributor I

Hi Im trying to do a SIL implementation with the s32k144 board, Im trying to add a custom code from the hello_world example from s32 Desing Studio. My model in simulink looks likes this...

 

AlvaroCervantes_0-1711689405162.png

But I dont know in wich block add the code, the code that I am trying to add is the next one...

#define EVB
 
#ifdef EVB
#define PCC_CLOCK PCC_PORTD_CLOCK
#define LED0_PORT PTD
#define LED0_PIN  15
#define LED1_PORT PTD
#define LED1_PIN  16
#else
#define PCC_CLOCK PCC_PORTC_CLOCK
#define LED0_PORT PTC
#define LED0_PIN  0
#define LED1_PORT PTC
#define LED1_PIN  1
#endif
 
#include "sdk_project_config.h"
 
void delay(volatile int cycles)
{
    /* Delay function - do nothing for a number of cycles */
    while(cycles--);
}
 
int main(void)
{
  status_t error;
  /* Configure clocks for PORT */
  error = CLOCK_DRV_Init(&clockMan1_InitConfig0);
  DEV_ASSERT(error == STATUS_SUCCESS);
  /* Set pins as GPIO */
  error = PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);
  DEV_ASSERT(error == STATUS_SUCCESS);
 
  /* Set Output value LED0 & LED1 */
  PINS_DRV_SetPins(LED0_PORT, 1 << LED0_PIN);
  PINS_DRV_ClearPins(LED1_PORT, 1 << LED1_PIN);
 
  for (;;)
  {
      /* Insert a small delay to make the blinking visible */
      delay(720000);
 
      /* Toggle output value LED0 & LED1 */
      PINS_DRV_TogglePins(LED0_PORT, 1 << LED0_PIN);
      PINS_DRV_TogglePins(LED1_PORT, 1 << LED1_PIN);
  }
}

 

---end of code

 

When I click to generate code i got 10 errors, most of them are from undefined variables of the clock.

0 项奖励