使用MPLABx和XC 8进行切割

ygya80vv  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(48)

我正在使用Windows Powershell的ceedling开始单元测试。我已经取得了很大的进展,让Unity与XC 8编译器一起工作。但是我有一个问题似乎无法解决。这里是一些构建转储。

'xc8-cc -mcpu=PIC16F18325 -gdwarf-3 -D"__PIC16f18325__" -D"__XC8" -D"UNITY_INT_WIDTH=16" -D"UNITY_POINTER_WIDTH=16" -D"CMOCK_MEM_INDEX_TYPE=uint16_t" -D"CMOCK_MEM_PTR_AS_INT=uint16_t" -D"CMOCK_MEM_ALIGN=1" -D"CMOCK_MEM_SIZE=256" -D"UNITY_OUTPUT_COLOR" -D"TEST" -D"UNITY_INCLUDE_CONFIG_H" -D"UNITY_EXCLUDE_SETJMP_H" -D"UNITY_EXCLUDE_MATH_H" -D"UNITY_EXCLUDE_FLOAT" -D"CMOCK_MEM_SIZE=256" -I"C:/Users/timtru/MPLABXProjects/XT_Lock_PIC16F18325.X/vendor/ceedling/vendor/unity/src" -I"C:/Users/timtru/MPLABXProjects/XT_Lock_PIC16F18325.X/vendor/ceedling/vendor/cmock/src" -I"build/ceedling/generated/test/mocks" -I"test" -I"test/source" -I"test/support" -I"source" -I"source/mcc_generated_files" -I"source/mcc_generated_files/docs/doxygen_generator" -I"source/mcc_generated_files/drivers" -I"C:/Program Files/Microchip/xc8/v2.36/pic/include" -I"C:/Program Files/Microchip/xc8/v2.36/pic/include/c90" -I"C:/Program Files/Microchip/xc8/v2.36/pic/include/c99" -I"C:/Program Files/Microchip/xc8/v2.36/pic/include/legacy" -I"C:/Program Files/Microchip/xc8/v2.36/pic/include/proc" -Wl,-Map="build/ceedling/generated/test/out/test_main.map" -o"./build/ceedling/generated/test/out/test_build.elf" build/ceedling/generated/test/out/c/test_main_runner.p1 build/ceedling/generated/test/out/c/test_main.p1 build/ceedling/generated/test/out/c/unity.p1 build/ceedling/generated/test/out/c/mcc.p1 build/ceedling/generated/test/out/c/main.p1 build/ceedling/generated/test/out/c/I2_p0.p1 build/ceedling/generated/test/out/c/process_commands.p1 build/ceedling/generated/test/out/c/cmock.p1 2>&1'
    > Produced output:
    C:\Program Files\Microchip\xc8\v2.36\pic\sources\c99\pic\__eeprom.c:22:9: error: use of undeclared identifier 'NVMCON1bits'

字符串
'NVMCON 1bits在XC 8安装目录-“C:/Program Files/Microchip/xc 8/v2.36/pic/include/proc”中的pic16f18325.h文件中声明,该文件被视为xc 8-cc参数列表中的最后一个-I。在IDE中,MPLAB使用XC. H文件通知编译器它正在为哪个处理器构建。这种机制导致正确的“processor”.h文件被拉入。<xc.h>必然会出现在每个源文件中。要使其工作,需要什么(在project.yml中)?

# Notes:
# Project.yml

:project:
    :build_root: build/ceedling/generated
    :test_file_prefix: test_
    :which_ceedling: vendor/ceedling
    :use_exceptions: FALSE
    :release_build: FALSE
    :use_test_preprocessor: FALSE
    :use_auxiliary_dependencies: TRUE
    :default_tasks:
    - test:all

:environment:
    - :mcu: PIC16F18325
    - :mplabx_root: "C:/Program Files/Microchip/xc8/v2.36/"
    - :path:
    - "C:/Program Files/Microchip/xc8/v2.36/pic/include/**"
    - "#{ENV['PATH']}"
    - build
    - source/**
    - source/*
    - vendor/ceedling/vendor/unity/src

#:test_build:
#  :use_assembly: TRUE

#:release_build:
#  :output: MyApp.out
#  :use_assembly: FALSE


:module_generator:
    :project_root: ./
    :source_root: source/
    :test_root: test/
    
:extension:
    :object: .p1
    :executable: .elf
    :assembly: .S

:paths:
    :test:
    - +:test/**
    - -:test/support
    :source:
    - source/**
    - -:source/mcc_generated_files/docs
    - -:source/mcc_generated_files/examples
    :include:
    - "C:/Program Files/Microchip/xc8/v2.36/pic/include/*"
    - "C:/Program Files/Microchip/xc8/v2.36/pic/include/proc/pic16f18325.h"
    :support:
    - test/support
    :libraries: []

:defines:
    # in order to add common defines:
    #  1) remove the trailing [] from the :common: section
    #  2) add entries to the :common: section (e.g. :test: has TEST defined)
    :commmon: &common_defines
    - __PIC16f18325__
    - __XC8
    - UNITY_INT_WIDTH=16
    - UNITY_POINTER_WIDTH=16
    - CMOCK_MEM_INDEX_TYPE=uint16_t
    - CMOCK_MEM_PTR_AS_INT=uint16_t
    - CMOCK_MEM_ALIGN=1
    - CMOCK_MEM_SIZE=256
    :test:
    - *common_defines
#    - UNITY_INCLUDE_CONFIG_H
    - UNITY_OUTPUT_COLOR #this is just here to make sure it gets removed by ceedling
    - TEST
    :test_preprocess:
    - *common_defines
    - TEST
:unity:
    :defines:
    - UNITY_INCLUDE_CONFIG_H 
    - UNITY_EXCLUDE_SETJMP_H
    - UNITY_EXCLUDE_MATH_H
    - UNITY_EXCLUDE_FLOAT
    
:cmock:
    :mock_prefix: mock_
    :when_no_prototypes: :warn
    :treat_externs: :include
    :enforce_strict_ordering: TRUE
    :fail_on_unexpected_calls: FALSE
    :exclude_setjmp_h: TRUE
    :defines:
    - CMOCK_MEM_SIZE=256
    :plugins:
    - :ignore
    - :ignore_arg
    - :callback
    - :expect_any_args
    :treat_as:
    int8:       INT8
    uint8:      HEX8
    uint16:     HEX16
    uint32:     UINT32
    int8_t:     INT8
    uint8_t:    HEX8
    uint16_t:   HEX16
    uint32_t:   UINT32
    bool:       UINT8

# Add -gcov to the plugins list to make sure of the gcov plugin
# You will need to have gcov and gcovr both installed to make it work.
# For more information on these options, see docs in plugins/gcov
:gcov:
    :reports:
    - HtmlDetailed
    :gcovr:
    :html_medium_threshold: 75
    :html_high_threshold: 90

:tools:
    :release_compiler:
    :name: "Microchip XC8 Compiler"
    :executable: xc8-cc
    :arguments:
        - "-mcpu=#{ENV['MCU']}"
        - -std=c99
        - -O1
        - -Wa,-a
        - -D"$": COLLECTION_DEFINES_RELEASE_AND_VENDOR
        - -I"$": COLLECTION_PATHS_SOURCE_AND_INCLUDE
        - -Iinclude/
        - -o "${2}"
        - -c
        - "${1}"

    :release_assembler:
    :name: "Microchip XC8 Compiler"
    :executable: xc8-cc
    :arguments:
        - "-mcpu=#{ENV['MCU']}"
        - -std=c99
        - -O1
        - -Wa,-a
        - -D"$": COLLECTION_DEFINES_RELEASE_AND_VENDOR
        - -I"$": COLLECTION_PATHS_SOURCE_AND_INCLUDE
        - -o "${2}"
        - -c
        - "${1}"

    :release_linker:
    :name: "Microchip XC8 Linker"
    :executable: xc8-cc
    :arguments:
        - "-mcpu=#{ENV['MCU']}"
        - -gdwarf-3
        - -D"$": COLLECTION_DEFINES_RELEASE_AND_VENDOR
        - -I"$": COLLECTION_PATHS_SOURCE_AND_INCLUDE
        - -Wl,-Map="${3}"
        - -o "${2}"
        - "{'${1}'.split(' ').map { |x| (x.include? '/out/c/') ? (Pathname(x).sub_ext('.p1')).to_s : x }.join(' ') }"
        - "${4}"

    :test_compiler:
    :name: "Microchip XC8 Compiler"
    :executable: xc8-cc
    :arguments:
        - -mcpu=#{ENV['MCU']}
        - -std=c99
        - -O1
        - -Wa,-a
        - -D"$": COLLECTION_DEFINES_TEST_AND_VENDOR
        - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR
        - -Iinclude/
        - -o "${2}"
        - -c
        - "${1}"

    :test_file_preprocessor:
    :name: "Microchip XC8 preprocessor"
    :executable: xc8-cc
    :arguments:
        - -mcpu=#{ENV['MCU']}
        - -std=c99
        - -D"$": COLLECTION_DEFINES_TEST_AND_VENDOR
        - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR
        - "${1}"

    :test_includes_preprocessor:
    :name: "Microchip XC8 includes preprocessor"
    :executable: xc8-cc
    :arguments:
        - -mcpu=#{ENV['MCU']}
        - -std=c99
        - -D"$": COLLECTION_DEFINES_TEST_AND_VENDOR
        - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR
        - "${1}"

    :test_linker:
    :name: "Microchip XC8 Linker"
    :executable: xc8-cc
    :arguments:
        - -mcpu=#{ENV['MCU']}
        - -gdwarf-3
        - -D"$": COLLECTION_DEFINES_TEST_AND_VENDOR
        - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR
        - -Wl,-Map="${3}"
        - -o"./build/ceedling/generated/test/out/test_build.elf"
        - "{'${1}'.split(' ').map { |x| (x.include? '/out/c/') ? (Pathname(x).sub_ext('.p1')).to_s : x }.join(' ') }"
        - "${4}"

    :test_fixture:
    :executable: ruby
    :name: "Microchip simulator test fixture"
    :stderr_redirect: :win #inform Ceedling what model of $stderr capture to use
    :arguments:
        - test/simulation/sim_test_fixture.rb

:plugins:
    :load_paths:
    - vendor/ceedling/plugins
    :enabled:
    - stdout_pretty_tests_report
    - module_generator
    - raw_output_report
    - warnings_report

lymgl2op

lymgl2op1#

你可能会在这个博客上找到有用的信息(Ceedling维护者):Unit Test How? Registers
你有test/support文件吗?
有一种方法可以测试您的PIC寄存器,但这需要一些努力来修改您的原始PIC头文件。
让我来介绍一下我为带有XC16的dsPIC 33所做的事情,这应该与XC8非常相似。
我使用的是从XC16目录复制到support的修改后的p33EP256MC506.h,其中:

  • 在顶部添加了这段代码,因为我使用XC16或GCC编译器进行编译:
#ifdef TEST_GCC
#define EXTERN 
#else
#define EXTERN extern
#endif

字符串

  • 删除每个__attribute__((.
  • 将每个extern替换为EXTERN
  • 添加此代码:
/* ---------------------------------------------------------- */
/* Some useful macros for inline assembler instructions       */
/* ---------------------------------------------------------- */
    
#define Nop()    ; //__builtin_nop()
#define ClrWdt() ; //__builtin_clrwdt()
#define Sleep()  ; //__builtin_pwrsav(0)
#define Idle()   ; //__builtin_pwrsav(1)


您可能还需要将支持目录添加到include

:paths:
  :test:
    - +:test/**
    - -:test/support
  :source:
    - src/**
  :support:
    - test/support  
  :include:
    - test/support

相关问题