Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-hillmann committed Aug 23, 2022
0 parents commit 6957f90
Show file tree
Hide file tree
Showing 28 changed files with 3,973 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ignore
build/*
out/*
debug/*
.vscode/*
CMakeUserPresets.json

#allow
!debug/*.jdebug
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "cmake"]
path = cmake
url = git@github.com:embedded-office/cmake-scripts.git
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 23.08.2022

### Add

- Add quickstart application running on my ST Nucleo-144 Board with a STM32F446ZE.
- Provide driver for CAN1 on STM32F4xx devices
- Provide driver for FMPI2C on STM32F4xx devices
- Provide driver for TIM2 on STM32F4xx devices

[unreleased]: https://github.com/embedded-office/canopen-stack/compare/v1.0.0...HEAD
[1.0.0]: https://github.com/embedded-office/canopen-stack/releases/tag/v1.0.0
41 changes: 41 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#*****************************************************************************
# Copyright 2020 Embedded Office GmbH & Co. KG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#******************************************************************************

#---
# preamble
#
cmake_minimum_required(VERSION 3.20) # buildPresets is introduced in 3.20
project(canopen-stm32f4xx)
enable_language(C ASM)

#---
# project wide setup
#
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED OFF)
set(CMAKE_C_EXTENSIONS OFF)

#---
# externally provided content
#
include(cmake/CPM.cmake)
add_subdirectory(dependencies)

#---
# main targets built by this project
#
add_subdirectory(src)
31 changes: 31 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"version": 3,
"configurePresets": [
{
"name": "base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "build/${presetName}",
"toolchainFile": "cmake/toolchain-gcc_cortex-m4.cmake",
"cacheVariables": {
"CPM_SOURCE_CACHE": "build/_deps"
}
},
{
"name": "debug",
"inherits": "base",
"displayName": "GCC-ARM (Cortex-M4) - Debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"inherits": "base",
"displayName": "GCC-ARM (Cortex-M4) - Release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
]
}
103 changes: 103 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@

# Repository Structure

```
+- cmake : submodule referencing the repository 'cmake-scripts'
+- debug : debugger configurations
+- dependencies : external managed components
+- src : canopen example project
| +- app : application source code
| +- config : configuration of startup and HAL
| +- driver : canopen target specific drivers
```

# CANopen Demo for STM32F4xx Microcontrollers

This project demonstrates the usage of the free [CANopen Stack Project](https://canopen-stack.org). The included application is the Quickstart - "*CANopen clock application*", described in detail at the [project website](https://canopen-stack.org/latest/start/quickstart/).

We use the [STM32Cube MCU Full Package for the STM32F4 series](https://github.com/STMicroelectronics/STM32CubeF4) made by ST Microelectronics as the low-level foundation for the chip configuration, the startup, and the driver implementation. With some slight enhancements to match our CMake build environment, we provide a small source code package out of a [forked repository](https://github.com/embedded-office/STM32CubeF4) for integration in our demo projects.

My hardware setup for this development and testing is:
- the [Nucleo-144 STM32F446](https://www.st.com/en/evaluation-tools/nucleo-f446ze.html)
- a CAN tranceiver [Waveshare SN65HVD230 CAN Board](https://www.waveshare.com/sn65hvd230-can-board.htm)
- an Atmel [AT24C256 I2C EEPROM](https://www.microchip.com/en-us/product/AT24C256C)
- the [KVaser USBcan II HS/HS](https://www.kvaser.com/product/kvaser-usbcan-ii-hshs/) for CAN bus monitoring
- the [Saleae Logic Analyzer](https://www.saleae.com/) for low level measurements

The wiring is pretty simple. For your reference, see the essence in a small diagram:

![Collection of relevant hardware information](doc/image/nucleo144-can-connection.jpg)

For details, check:
- the [User Manual for STM32 Nucleo-144 boards](https://www.st.com/resource/en/user_manual/um1974-stm32-nucleo144-boards-mb1137-stmicroelectronics.pdf)
- the [STM32F446xx Datasheet](https://www.st.com/resource/en/datasheet/stm32f446re.pdf)
- the [Reference Manual for STM32446xx MCUs](https://www.st.com/resource/en/reference_manual/dm00135183-stm32f446xx-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf)

## Usage

### Development Tools

Download and install these free tools for your system:

- Install the build tools [Cmake](https://cmake.org/)
- Install the build system [Ninja](https://ninja-build.org/)
- Install the cross-compiler [Arm GNU Toolchain](https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain)

*Note: on my Windows machine, I use the [Ozone debugger](https://www.segger.com/downloads/jlink/) with the free [ST-Link Reflash Utility](https://www.segger.com/products/debug-probes/j-link/models/other-j-links/st-link-on-board/) from Segger. The generated debug information in the ELF image should be suitable for all other debuggers, too.*


### Submodule: cmake-scripts

The basic collection of re-usable CMake scripts are placed as a Git submodule in the directory `/cmake`. The Git submodule is a reference to a specific commit hash of the Git repository [cmake-scripts](https://github.com/embedded-office/cmake-scripts).

*Small reminder: when cloning this repository you need to initialize and update the submodules:*

```bash
# clone Git repository and initialize submodules:
$ git clone --recurse-submodules <repository>

# or, in case you have already cloned the Git repository:
$ git clone <repository>
$ cd <repository-directory>
$ git submodule update --init
```


### Project dependencies

We use two extern managed components to build our target application. When using external projects it is important to define naming rules for exported CMake `target` names to eliminate name collisions.

For the example application in this repository we use:

- Target [stm32f4xx-hal](https://github.com/embedded-office/STM32CubeF4) - a fork of the STM32CubeF4 package with enhancements for usage with CMake
- Target [canopen-stack](https://github.com/embedded-office/canopen-stack) - the free CANopen Stack, provided by Embedded Office

*Note: The used versions of the dependencies are defined in the directory `/dependencies`.*


## Build instructions

Just type in the project root directory:

```bash
# configure the project for debugging
$ cmake --preset debug

# build the application for your target
$ cmake --build ./build/debug
```

The target image file `canopen-stm32f4xx.elf` and the corresponding map file `canopen-stm32f4xx.map` are generated and placed in `out/debug`.


## Load and Executing on target

For the Ozone debugger there is a basic debugger configuration `debug/ozone.jdebug`, which loads the image to the target and runs to function `main()`.

- power up your STM32F446 nucleo board
- double-click the debugger configuration
- watch the uploading and running to main ...

... and have fun playing with this tiny CANopen quickstart application :)

If you encounter any improvement in descriptions, project setup, build system, implementation or documentation, please rise an issue and help me to simplify the life of Embedded software engineers.
1 change: 1 addition & 0 deletions cmake
Submodule cmake added at 8f8cfd
Loading

0 comments on commit 6957f90

Please sign in to comment.