[已解决] 基于stm32芯片的cubemx与simulink联合PIL实验

[复制链接]
Automation233 发表于 2022-4-18 17:19:20
本帖最后由 Automation233 于 2022-4-18 17:25 编辑

用cubemx与simulink进行联合开发,在我进行到PIL的时候出现了错误,
其中的关键参数toolchain:
请问这个参数是怎么选择的呢? 我这里是可以更改的
其中标红的我都试过了,都会出现上述错误,一模一样,
其实我运行到这里,也在一个32文件夹里生成了。c,.h文件。但是就是不知道为什会出现这个错误?
希望大家能帮我一下,网上关于TI芯片的PIL很多,但是做STM32芯片的PIL比较少,谢谢大家的帮忙。
Snipaste_2022-04-18_17-14-33.png
Snipaste_2022-04-18_17-15-13.png
Snipaste_2022-04-18_17-15-32.png
Snipaste_2022-04-18_17-16-50.png

最佳答案


TCCMATLAB 发表于 2022-4-19 10:20:08
Automation233 发表于 2022-4-19 09:58
有的,找到个。lib文件。请问然后怎么操作?

错误里面描述了:
Missing object code for source files PLANT4.c, main.c。

说明你配置的工具链并没有将这两个文件编译成.o, .obj, .a 或者.lib的其中一种。
需要调查为什么没有生成出来?

看看你的stm32.tmf里面有没有使用编译器把.c 生成到上面格式的目标文件。
比如用gcc, 我们可以用 gcc main.c main.o ,把.c文件生成到.o文件。
或者可以在网络上查查,怎么配置的stm32.tmf这个文件。

8 条回复


Automation233 发表于 2022-4-18 17:33:25
上面标红的toolchain全部都会出现上面一模一样的问题,所以不知道到底是不是这个选择项的问题了?

TCCMATLAB 发表于 2022-4-19 09:41:04
Automation233 发表于 2022-4-18 17:33
上面标红的toolchain全部都会出现上面一模一样的问题,所以不知道到底是不是这个选择项的问题了? ...

Processing Template Makefile: E:\STM32-MAT\STM32\rtw\stm32.tmf
打开这个文件,看下里面是否有将.c 编译成.o, .obj, .a, .lib的指令。
如果没有,需要自己修改文件,使用你选择的编译器,把生成的.c编译成目标文件。

Automation233 发表于 2022-4-19 09:48:39
TCCMATLAB 发表于 2022-4-19 09:41
Processing Template Makefile: E:\STM32-MAT\STM32\rtw\stm32.tmf
打开这个文件,看下里面是否有将.c 编 ...

#Source file extension
SRC_FILE_EXT = .c
#Object file extension
OBJ_EXT = .o
#File extension is .out for dummy artifact executable file
PROGRAM_FILE_EXT = .out
#File extension is .lib for dummy artifact library file
BINARY_FILE_EXT = .lib

是有的,这是文件里的内容,请问我要把这部分删掉吗?

TCCMATLAB 发表于 2022-4-19 09:50:28
Automation233 发表于 2022-4-19 09:48
#Source file extension
SRC_FILE_EXT = .c
#Object file extension

不用,检查下你的文件夹内,有 .o, .lib文件生成吗?

Automation233 发表于 2022-4-19 09:58:23
TCCMATLAB 发表于 2022-4-19 09:50
不用,检查下你的文件夹内,有 .o, .lib文件生成吗?

有的,找到个。lib文件。请问然后怎么操作?

TCCMATLAB 发表于 2022-4-19 10:20:08
Automation233 发表于 2022-4-19 09:58
有的,找到个。lib文件。请问然后怎么操作?

错误里面描述了:
Missing object code for source files PLANT4.c, main.c。

说明你配置的工具链并没有将这两个文件编译成.o, .obj, .a 或者.lib的其中一种。
需要调查为什么没有生成出来?

看看你的stm32.tmf里面有没有使用编译器把.c 生成到上面格式的目标文件。
比如用gcc, 我们可以用 gcc main.c main.o ,把.c文件生成到.o文件。
或者可以在网络上查查,怎么配置的stm32.tmf这个文件。

回复此楼

Automation233 发表于 2022-4-19 10:58:59
TCCMATLAB 发表于 2022-4-19 10:20
错误里面描述了:
Missing object code for source files PLANT4.c, main.c。

#
# File    : stm32.tmf
#
#
# Abstract:
#       Real-Time Workshop template makefile for the build process of SIMULINK

#------------------------- Path Information -------------------------------

# Project and application specific tools and directories:

#Use mex extension to know if 32 or 64bit installed
MEXEXT = |>MEXEXT<|


#------------------------ Macros read by make_rtw ------------------------------
#
# The following macros are read by the Real-Time Workshop build procedure:
#
#  MAKECMD         - This is the command used to invoke the make utility
#  HOST            - What platform this template makefile is targeted for
#                    (i.e. PC or UNIX)
#  BUILD           - Invoke make from the Real-Time Workshop build procedure (yes/no)?
#  SYS_TARGET_FILE - Name of system target file.


ifeq ($(MEXEXT),mexw64)
MAKECMD         = "%MATLAB%\bin\%MATLAB_WIN_VER%\gmake"
else ifeq ($(MEXEXT),mexw32)
MAKECMD         = "%MATLAB%\bin\%MATLAB_WIN_VER%\gmake"
else
   $(error ERROR NOT SUPPORTED OS VERSION!!! )
endif

SHELL           = cmd
HOST            = PC
BUILD           = yes
SYS_TARGET_FILE = stm32.tlc
COMPILER_TOOL_CHAIN = default
MAKEFILE_FILESEP = /

#Source file extension
SRC_FILE_EXT = .c
#Object file extension                                                                                                                                                  
OBJ_EXT = .o
#File extension is .out for dummy artifact executable file
PROGRAM_FILE_EXT = .out
#File extension is .lib for     dummy artifact library file
BINARY_FILE_EXT = .lib


#---------------------- Tokens expanded by make_rtw ----------------------------
#
# The following tokens, when wrapped with "|>" and "<|" are expanded by the
# Real-Time Workshop build procedure.
#
#  MODEL_NAME          - Name of the Simulink block diagram
#  MODEL_MODULES       - Any additional generated source modules
#  MAKEFILE_NAME       - Name of makefile created from template makefile <model>.mk
#  MATLAB_ROOT         - Path to where MATLAB is installed.
#  MATLAB_BIN          - Path to MATLAB executable.
#  S_FUNCTIONS_LIB     - List of S-functions libraries to link.
#  NUMST               - Number of sample times
#  NCSTATES            - Number of continuous states
#  BUILDARGS           - Options passed in at the command line.
#  MULTITASKING        - yes (1) or no (0): Is solver mode multitasking
#  INTEGER_CODE        - yes (1) or no (0): Is generated code purely integer
#  MAT_FILE            - yes (1) or no (0): Should mat file logging be done,
#                        if 0, the generated code runs indefinitely
#  EXT_MODE            - yes (1) or no (0): Build for external mode
#  TMW_EXTMODE_TESTING - yes (1) or no (0): Build ext_test.c for external mode
#                        testing.
#  EXTMODE_TRANSPORT   - Index of transport mechanism (e.g. tcpip, serial) for extmode
#  EXTMODE_STATIC      - yes (1) or no (0): Use static instead of dynamic mem alloc.
#  EXTMODE_STATIC_SIZE - Size of static memory allocation buffer.
#  MULTI_INSTANCE_CODE - Is the generated code multi instantiable (1/0)?
#  SHRLIBTARGET        - Is this build intended for generation of a shared library instead
#                        of executable (1/0)?
MODEL                = |>MODEL_NAME<|
MODULES              = |>MODEL_MODULES<|
MODULES_OBJ          = |>MODEL_MODULES_OBJ<|
MAKEFILE             = |>MAKEFILE_NAME<|
TOOLPATH             = "|>COMPILERPATH<|"
MATLAB_ROOT          = "|>MATLAB_ROOT<|"
ALT_MATLAB_ROOT      = "|>ALT_MATLAB_ROOT<|"
MATLAB_BIN           = "|>MATLAB_BIN<|"
ALT_MATLAB_BIN       = "|>ALT_MATLAB_BIN<|"
S_FUNCTIONS_LIB      = |>S_FUNCTIONS_LIB<|
NUMST                = |>NUMST<|
NCSTATES             = |>NCSTATES<|
BUILDARGS            = |>BUILDARGS<|
MULTITASKING         = |>MULTITASKING<|
INTEGER_CODE         = |>INTEGER_CODE<|
MAT_FILE             = |>MAT_FILE<|
ONESTEPFCN           = |>COMBINE_OUTPUT_UPDATE_FCNS<|
TERMFCN              = |>INCLUDE_MDL_TERMINATE_FCN<|
B_ERTSFCN            = |>GENERATE_ERT_S_FUNCTION<|
EXT_MODE             = |>EXT_MODE<|
TMW_EXTMODE_TESTING  = |>TMW_EXTMODE_TESTING<|
EXTMODE_TRANSPORT    = |>EXTMODE_TRANSPORT<|
EXTMODE_STATIC       = |>EXTMODE_STATIC_ALLOC<|
EXTMODE_STATIC_SIZE  = |>EXTMODE_STATIC_ALLOC_SIZE<|
MULTI_INSTANCE_CODE  = |>MULTI_INSTANCE_CODE<|
MODELREFS            = |>MODELREFS<|
MEX_OPT_FILE         = |>MEX_OPT_FILE<|
TARGET_LANG_EXT      = |>TARGET_LANG_EXT<|
SHRLIBTARGET         = |>SHRLIBTARGET<|
MAKEFILEBUILDER_TGT  = |>MAKEFILEBUILDER_TGT<|
STANDALONE_SUPPRESS_EXE = |>STANDALONE_SUPPRESS_EXE<|
OPTIMIZATION_FLAGS   = |>OPTIMIZATION_FLAGS<|
ADDITIONAL_LDFLAGS   = |>ADDITIONAL_LDFLAGS<|


#--------------------------- Model and reference models -----------------------
MODELLIB                  = |>MODELLIB<|
MODELREF_LINK_LIBS        = |>MODELREF_LINK_LIBS<|
MODELREF_LINK_RSPFILE     = |>MODELREF_LINK_RSPFILE_NAME<|
RELATIVE_PATH_TO_ANCHOR   = |>RELATIVE_PATH_TO_ANCHOR<|
# NONE: standalone, SIM: modelref sim, RTW: modelref coder target
MODELREF_TARGET_TYPE      = |>MODELREF_TARGET_TYPE<|

#Matlab Path checking
ifneq ($(MATLAB_ROOT),$(ALT_MATLAB_ROOT))
MATLAB_ROOT = $(ALT_MATLAB_ROOT)
endif
MATLAB_ROOT := $(subst \,/,$(MATLAB_ROOT))
MATLAB_ROOT := $(subst Program Files,Program\ Files,$(MATLAB_ROOT))
ifneq ($(MATLAB_BIN),$(ALT_MATLAB_BIN))
MATLAB_BIN = $(ALT_MATLAB_BIN)
endif
MATLAB_BIN := $(subst Program Files,Program\ Files,$(MATLAB_BIN))
MATLAB_BIN := $(subst ~,\~,$(MATLAB_BIN))


# Place -I options here
MATLAB_INCLUDES = \
        -I$(MATLAB_ROOT)/rtw/c/ert \
        -I$(MATLAB_ROOT)/extern/include \
        -I$(MATLAB_ROOT)/simulink/include \
        -I$(MATLAB_ROOT)/rtw/c/src \
        -I$(MATLAB_ROOT)/rtw/c/src/ext_mode/common \
        -I$(MATLAB_ROOT)/toolbox/rtw/targets/pil/c

# Additional includes
ADD_INCLUDES = \
|>START_EXPAND_INCLUDES<| -I|>EXPAND_DIR_NAME<| |>END_EXPAND_INCLUDES<|


#------------------------------ Includes -------------------------------------
INCLUDES = -I. -I$(RELATIVE_PATH_TO_ANCHOR) $(MATLAB_INCLUDES) \
           $(ADD_INCLUDES)


#-------------------------------- Flags --------------------------------------

#-------------------------------- Target application --------------------------------------
# Define the target file

ifeq ($(MODELREF_TARGET_TYPE), NONE)
  ifeq ($(MAKEFILEBUILDER_TGT), 0)
    ifeq ($(STANDALONE_SUPPRESS_EXE), 1)
      # Build object code only for top level model (preliminary step for building
      # PIL application)
      BUILD_MODE=pil_prebuild
      PRODUCT=ObjectModules
    else
      # Building executable for real-time deployment
      BUILD_MODE=real_time
      PRODUCT = $(MODEL)$(PROGRAM_FILE_EXT)
    endif

  else
    # Building executable for deployment as PIL application (non-real-time simulation)
    BUILD_MODE=pil_application
    PRODUCT=$(MODEL)$(PROGRAM_FILE_EXT)
  endif

else
  # sub-model for code generation
  # Building a library for a referenced model
  BUILD_MODE=model_reference
  PRODUCT=$(MODELLIB)
endif

$(info ### BUILD_MODE              : $(BUILD_MODE))
$(info ### PRODUCT                 : $(PRODUCT))
$(info ### SHRLIBTARGET            : $(SHRLIBTARGET))
$(info ### MODULES                 : $(MODULES))

$(info ### MODELREF_TARGET_TYPE    : $(MODELREF_TARGET_TYPE))
$(info ### MAKEFILEBUILDER_TGT     : $(MAKEFILEBUILDER_TGT))
$(info ### STANDALONE_SUPPRESS_EXE : $(STANDALONE_SUPPRESS_EXE))

#-------------- Source Files, Object Files and Dependency Files -----------
# Target specific sources:
# Provided through variable TARGET_SRCS from hook file
# System specific sources:
# Provided through variable SYSTEM_SRCS from hook file

SRCS = $(MODULES)

ifeq ($(BUILD_MODE), pil_prebuild)
  SRCS += $(MODULES) $(MODEL).$(TARGET_LANG_EXT)
endif

ifeq ($(BUILD_MODE), pil_application)
  SRCS += $(TARGET_SRCS) $(TARGET_BLOCK_SRCS) $(SYSTEM_SRCS)
  PREBUILT_SRCS      = $(subst \,/,$(MODULES))
  PREBUILT_OBJS      = $(addsuffix $(OBJ_EXT), $(basename $(PREBUILT_SRCS)))
endif

ifeq ($(BUILD_MODE), real_time)
  SRCS += $(MODEL).$(TARGET_LANG_EXT) main.c
  SRCS += $(TARGET_BLOCK_SRCS) $(TARGET_SRCS) $(SYSTEM_SRCS)
endif

ifeq ($(BUILD_MODE), model_reference)
# main.c should not be compiled for referenced model
endif

LIBS = $(S_FUNCTIONS_LIB)

SHARED_OBJS = $(OBJ_EXT)
SHARED_OBJS := $(subst \,/,$(SHARED_OBJS))
MODELLIB := $(subst \,/,$(MODELLIB))


#-------------- Default target -----------
OBJS  = $(SRCS:$(SRC_FILE_EXT)=$(OBJ_EXT))
OBJS  := $(subst \,/,$(OBJS))



TARGETS = $(PRODUCT)

all: $(TARGETS)
        @echo ### Created $(PRODUCT) successfully (or it was already up to date)

clean :
        @del *.o
        @echo "### All .o files deleted."

mrproper : clean
        @del $(PRODUCT)
        @echo ### Project clean.

.PHONY : clean mrproper
        @echo ### Created $(PRODUCT) successfully (or it was already up to date)

#----------------------------- Dependencies ------------------------------------
$(OBJS) : $(MAKEFILE)


##-------------------------- Support for building modules ----------------------

ifeq ($(BUILD_MODE), pil_prebuild)
$(PRODUCT) : $(OBJS)
        @echo ### Parsed $@ $(BUILD_MODE)
endif

ifeq ($(BUILD_MODE), model_reference)
$(PRODUCT) : $(OBJS) $(LIBS)
        @echo ### Ending parsing $@ $(BUILD_MODE)
        @echo "Dummy file" > $@
endif

ifeq ($(BUILD_MODE), pil_application)
$(MODEL)$(PROGRAM_FILE_EXT): $(PREBUILT_OBJS) $(OBJS) $(MODELLIB) $(MODELREF_LINK_LIBS) $(LIBS)
        @echo ### Ending $@ $(BUILD_MODE)
        @echo "Dummy file" > $@
endif

ifeq ($(BUILD_MODE), real_time)
$(MODEL)$(PROGRAM_FILE_EXT): $(OBJS) $(MODELREF_LINK_LIBS) $(LIBS)
        @echo ### Ending $@ $(BUILD_MODE)
        @echo "Dummy file" > $@
endif


#--------------------------------- Rules -------------------------------------
%.o: $(subst \,/,$(RELATIVE_PATH_TO_ANCHOR))/%$(SRC_FILE_EXT)
        @echo ### Source $< done

%.o: $(subst \,/,$(RELATIVE_PATH_TO_ANCHOR))/%.cpp
        @echo ### Source $< done

%.o: %.cpp
        @echo ### Source $< done

%.o: %$(SRC_FILE_EXT)
        @echo ### Source $< done

%.o: $(subst ",,$(PATHSETUP))/%$(SRC_FILE_EXT)
        @echo ### Source $< done

%.o: $(subst ",,$(LIBSRC))/%$(SRC_FILE_EXT)
        @echo ### Source $< done

|>START_EXPAND_RULES<|
%.o: $(subst ",,|>EXPAND_DIR_NAME<|)/%.cpp
        @echo ### Source $< done
|>END_EXPAND_RULES<|

|>START_EXPAND_RULES<|
%.o: $(subst ",,|>EXPAND_DIR_NAME<|)/%$(SRC_FILE_EXT)
        @echo ### Source $< done
|>END_EXPAND_RULES<|

# EOF: stm32.tmf
#上面是全部的文件内容,能否帮忙看下,感谢感谢

TCCMATLAB 发表于 2022-4-19 11:37:15
Automation233 发表于 2022-4-19 10:58
#
# File    : stm32.tmf
#

没做过这一块。
可以参考网站上同样的问题。
https://community.st.com/s/question/0D53W000003MIekSAG/error-while-calling-into-the-sil-or-pil-target-connectivity-implementation-stm32g4cusersbeelecdocumentsmatlabiirfilteriirfilterslprjstm32iirfiltermodelsilset-matla
您需要登录后才可以回帖 登录 | 注册

本版积分规则

相关帖子
相关文章
热门教程
站长推荐
快速回复 返回顶部 返回列表