Search code examples
cmockingarmstm32cmock

Ceedling CMock settings for ARM STM32


I've been setting up Ceedling for STM32. The howto is very scarce, so far I've managed to google next to nothing. Fortunately, the framework is relatively transparent for its size. This is a PIC configuration. I set up something similar (project.yml):

...
: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 #[]
    - STM32F103xB
    - UNITY_INT_WIDTH=32
    - CMOCK_MEM_INDEX_TYPE=uint32_t
    - UNITY_LINE_TYPE=uint16_t
  :test:
    - *common_defines
    - TEST
  :test_preprocess:
    - *common_defines
    - TEST

So far so good (no real work is yet attempted). Having added this definition

    - CMOCK_MEM_PTR_AS_INT=uint32_t

I'm having a warning:

/vendor/ceedling/vendor/cmock/src/cmock.c:105:40: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   index = *(CMOCK_MEM_INDEX_TYPE*)((CMOCK_MEM_PTR_AS_INT)next - CMOCK_MEM_INDEX_SIZE);

No wonder, as next is a PC platform 64-bit pointer. Still I am not at all sure whether I have to control CMOCK_MEM_PTR_AS_INT or not. It depends on whether CMOCK_MEM_PTR_AS_INT is a critical target (ARM) platform definition.

So far I haven't found an STM32 example.


Solution

  • Here is the hard won sequence, complete with the Eclipse integration:

    Install Ceedling:

    $ gem install ceedling
    

    Create Ceedling project (troubleshooting #215):

    myproject $ cd ..
    $ ceedling new myproject
    $ cd myproject/vendor/
    $ rm -rf ceedling/
    $ git clone --recursive https://github.com/throwtheswitch/ceedling.git
    

    Modify vendor/ceedling/plugins/module_generator/config/module_generator.yml:

    :module_generator:
      :project_root: ./
      :source_root:  Src/
      :inc_root:     Inc/
      :test_root:    test/
    

    Modify project.yml:

    ...
    :paths:
      :test:
        - +:test/**
        - -:test/support
      :source:
        - Src/**
      :include:
        - Drivers/**
        - Inc/**
      :support:
        - test/support
    ...
    :defines:
      :commmon: &common_defines  # A nice typo, next to invisible :)
        - STM32F103xB
    ...
    :cmock:
      :strippables:
        - volatile
    ...
    :plugins:
      :load_paths:
        - vendor/ceedling/plugins
      :enabled:
    #    - stdout_pretty_tests_report
        - stdout_gtestlike_tests_report
        - module_generator
    

    Eclipse C/C++ Unit plugin configuration:

    • Main/Project: myproject

    • Main/Application: /home/user/.gem/ruby/2.5.0/bin/ceedling

    • Main/Disable auto build

    • Arguments/Program arguments: clobber\ntest:all

    • Testing/Test Runner: Google Test Runner

    • Environment: Variable TERM Value xterm