繁体   English   中英

与 MPLABx 和 XC8 同步

[英]ceedling with MPLABx and XC8

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

'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'

'NVMCON1bits 在 XC8 安装目录-"C:/Program Files/Microchip/xc8/v2.36/pic/include/proc" 的 pic16f18325.h 文件中声明,它被视为 xc8-cc 参数中的最后一个 -I列表。 在 IDE 中,MPLAB 使用 XC.H 文件来通知编译器它正在构建的处理器。 这种机制导致正确的“处理器”.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

您可以在此博客(Ceedling 维护者)上找到有用的信息: 单元测试如何? 寄存器

你有test/support中的任何文件吗?

有一种方法可以测试您的 PIC 寄存器,但这需要一些努力来修改您的原始 PIC 头文件。

让我介绍一下我为带有 XC16 的 dsPIC33 所做的事情,这对于 XC8 应该非常相似。

我正在使用从 XC16 目录复制的修改后的p33EP256MC506.hsupport where :

  • 在顶部添加了此代码,因为我使用 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 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM