簡體   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