STM32 mit Simulink und TrueSTUDIO

Gast #5811232
Lesenswert?

Hallo zusammen,

ich probiere gerade ein STM32F4 Discoveryboard mit grafischer 
Programmierung in Simulink zum laufen zu bekommen.
Habe mit meine Toolchain mit CobeMX, Simulink, Embedded Coder und 
TrueSTUDIO eingerichtet. Wollte jetzt einfach nur mal ein LED mit einem 
Pulsegenarotor ansteuern:

test.c
1
/* Model step function */
2
void test_step(void)
3
{
4
  test_B.PulseGenerator = ((test_DW.clockTickCounter < 1000) &&
5
    (test_DW.clockTickCounter >= 0));
6
  if (test_DW.clockTickCounter >= 2999) {
7
    test_DW.clockTickCounter = 0;
8
  } else {
9
    test_DW.clockTickCounter++;
10
  }
11

12
  /* S-Function Block: <Root>/STM32_Config */
13

14
  /* S-Function Block: <Root>/GPIO_Write */
15
  if (test_B.PulseGenerator == 0)
16
    HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
17
  else
18
    HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
19

20
  //
21
}
22

23
/* Model initialize function */
24
void test_initialize(void)
25
{
26
  /* Registration code */
27

28
  /* initialize error status */
29
  rtmSetErrorStatus(test_M, (NULL));
30

31
  /* block I/O */
32
  (void) memset(((void *) &test_B), 0,
33
                sizeof(B_test));
34

35
  /* states (dwork) */
36
  (void) memset((void *)&test_DW, 0,
37
                sizeof(DW_test));
38
  test_DW.clockTickCounter = 0;
39
}


Das ganze wirft aber beim compilieren einen Fehler und so gut kenne ich 
mich leider nicht in C aus das Problem zu beheben :/
1
.......startup\startup_stm32f407xx.o -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -T../STM32F407VG_FLASH.ld -specs=nosys.specs -static -Wl,-Map=test3.map -Wl,--gc-sections -Wl,--defsym=malloc_getpagesize_P=0x80 -Wl,--start-group -lc -lm -Wl,--end-group -specs=nano.specs 
2
Src\main.o: In function `main':
3

4
C:\Users\Desktop\stm32board_test\test3\Debug/..\Src/main.c:149: undefined reference to `test_initialize'
5
C:\Users\Desktop\stm32board_test\test3\Debug/..\Src/main.c:166: undefined reference to `test_step'
6
Src\main.o: In function `SysTick_Config':
7
C:\Users\Desktop\stm32board_test\test3\Drivers\CMSIS\Include/core_cm4.h:2031: undefined reference to `test_M'
8
collect2.exe: error: ld returned 1 exit Status

Hoffe ihr könnt mir weiterhelfen :)
Gast #5812068
Lesenswert?

Hallo STK500-Besitzer,

danke für deine Antwort (und für die Literaturempfehlung :) )

So wie ich das als Amateur sehe, ist die Funktion vor der main:
1
#include "main.h"
2
#include "usb_host.h"
3

4
I2C_HandleTypeDef hi2c1;
5
I2S_HandleTypeDef hi2s3;
6
SPI_HandleTypeDef hspi1;
7

8
void SystemClock_Config(void);
9
static void MX_GPIO_Init(void);
10
static void MX_I2C1_Init(void);
11
static void MX_I2S3_Init(void);
12
static void MX_SPI1_Init(void);
13
void MX_USB_HOST_Process(void);
14

15
#include <stdio.h>
16
#include "test.h"                      /* Model's header file */
17
#include "rtwtypes.h"                  /* MathWorks types */
18

19
extern RT_MODEL_test *const test_M;
20
extern void test_SetEventsForThisBaseStep(boolean_T*);
21

22
static boolean_T OverrunFlags[1];
23
static volatile uint32_t autoReloadTimerLoopVal_S = 1;
24
static volatile uint32_t remainAutoReloadTimerLoopVal_S = 1;
25

26
int main(void)
27
{
28
  /* USER CODE BEGIN 1 */
29
  /* Data initialization */
30
  int_T i;
31

32
...

Mit test.h wird doch praktisch die Funktion in main mit eingebunden 
denke ich?

im test.h wird dann wiederum auf test.c (siehe oben) verlinkt:
1
#ifndef RTW_HEADER_test_h_
2
#define RTW_HEADER_test_h_
3
#include <stddef.h>
4
#include <string.h>
5
#include "STM32_Config.h"
6
#include "test_External_Functions.h"
7
#ifndef test_COMMON_INCLUDES_
8
# define test_COMMON_INCLUDES_
9
#include "rtwtypes.h"
10
#endif                                 /* test_COMMON_INCLUDES_ */
11

12
#include "test_types.h"
13

14
/* Macros for accessing real-time model data structure */
15
#ifndef rtmGetErrorStatus
16
# define rtmGetErrorStatus(rtm)        ((rtm)->errorStatus)
17
#endif
18

19
#ifndef rtmSetErrorStatus
20
# define rtmSetErrorStatus(rtm, val)   ((rtm)->errorStatus = (val))
21
#endif
22

23
/* Block signals (default storage) */
24
typedef struct {
25
  real_T PulseGenerator;               /* '<Root>/Pulse Generator' */
26
} B_test;
27

28
/* Block states (default storage) for system '<Root>' */
29
typedef struct {
30
  int32_T clockTickCounter;            /* '<Root>/Pulse Generator' */
31
} DW_test;
32

33
/* Real-time Model Data Structure */
34
struct tag_RTM_test {
35
  const char_T *errorStatus;
36
};
37

38
/* Block signals (default storage) */
39
extern B_test test_B;
40

41
/* Block states (default storage) */
42
extern DW_test test_DW;
43

44
/* Model entry point functions */
45
extern void test_initialize(void);
46
extern void test_step(void);
47

48
/* Real-time Model object */
49
extern RT_MODEL_test *const test_M;
50

51
#endif

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren