Skip to content

Commit

Permalink
development docs
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-ortega committed Sep 19, 2020
1 parent da04e03 commit 1e72377
Show file tree
Hide file tree
Showing 67 changed files with 1,372 additions and 0 deletions.
92 changes: 92 additions & 0 deletions docs/development/Atomic Barrier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Atomic Barrier implementation

```
static int markme_bar = 0;
static int markme = 0;
markme++;
// (1) markme is read into register, but not changed
markme_bar++;
// markme_bar is read from memory and incremented
ATOMIC_BLOCK_NB(NVIC_PRIO_TIMER) {
ATOMIC_BARRIER(markme_bar);
// start of ATOMIC_BLOCK_NB scope:
// markme_bar is stored into memory (it is input/output - "+m" output operand - of asm volatile)
// BASEPRI is saved into temporary variable
// BASEPRI_MAX is decremented to NVIC_PRIO_TIMER (if it is higher than NVIC_PRIO_TIMER or zero; lower number means higher priority on ARM)
markme++;
// nothing happens, markme value is not needed yet
markme_bar++;
// (2) markme_bar re-read from memory (ATOMIC_BARRIER marked it as modified - "+m" output operand of asm volatile)
// and incremented
// end of ATOMIC_BLOCK_NB scope:
// markme_bar is stored into memory (cleanup function from ATOMIC_BARRIER) / input "m" operand), but kept for later use in register
// (actually markme_bar+1 is stored and pre-increment value kept in register)
// BASEPRI value is restored
};
markme++;
// register value read in (1) is incremented by 3
markme_bar++;
// register value read in (2) is incremented (actually +=2, because register contains pre-increment value)
// markme and markme_bar are stored into memory
```

# Atomic Barrier Warning


The ATOMIC_BLOCK/ATOMIC_BARRIER construction is dependent on gcc extensions. I relies on gcc cleanup function (`attribute ((cleanup))`) and assumes that cleanup handler is called, when leaving block, even when associated variable is eliminated.

There is (a bit paranoid) safeguard warning to make sure that generated assembly is hand-checked on new gcc version. It is assumed that only major gcc version versions need to be checked.

If GCC is upgraded and a warning appears when compiling then the generated asm source must be verified.

e.g.
```
%% serial_softserial.c
warning "Please verify that ATOMIC_BARRIER works as intended"
```

To perform the verification, proceed as per discusson on issue #167 which reads:

I hope it's enough to check that optimized-away variable still has cleanup code at end of scope.

```
static int markme=0;
markme++;
ATOMIC_BLOCK_NB(0xff) {
ATOMIC_BARRIER(markme);
markme++;
};
markme++;
```

pass `-save-temps=obj` (or `-save-temps=cwd`, but lots of files will end up in same directory as makefile) to gcc link step (LTO is in use), find resulting `*.ltrans*.ltrans.s` (grep for `markme`, on linux it ends up in `/tmp`) and check that generated assembly sequence is:

```
MSR basepri_max, r3
# (possibly markme address load)
# barier (markme) start
# (increment markme, load and store to memory)
ldr r2, [r3]
adds r0, r2, #1
str r0, [r3]
# barier(markme) end
MSR basepri, r3
# (markme value should be cached in register on next increment)
```

The # barrier(markme) must surround access code and must be inside MSR basepri instructions .

Similar approach is used for ATOMIC_BLOCK in avr libraries, so gcc should not break this behavior.

IMO attribute(cleanup) and asm volatile is defined in a way that should guarantee this.

attribute(cleanup) is probably safer way to implement atomic sections - another possibility is to explicitly place barriers in code, but that can (and will eventually) lead to missed barrier/basepri restore on same path creating very hard to find bug.

The 'MEMORY_BARRIER()' code can be omitted when 'ATOMIC_BLOCK' (with full memory barriers) is used, but it is better to explicitly state what memory is protected by barrier. gcc 5 can use this knowledge to greatly improve generated code.
20 changes: 20 additions & 0 deletions docs/development/Building Manual.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#Building Manual.

The manual PDF file is generated by concatenating relevant markdown files and by transforming the result using Gimli to obtain the final PDF file. This steps are handled automatically by the ```build_docs.sh``` script located in the root of the repository next to the Makefile.

##Requirements & Installation
The PDF manual generation uses the Gimli for the conversion. It can be installed via ruby gems. On Debian based systems the installation steps are:
```bash
sudo apt-get install ruby1.9.1 ruby1.9.1-dev rubygems zlib1g-dev wkhtmltopdf libxml2-dev libxslt-dev
sudo gem1.9.1 install gimli
```

##Configuration
All markdown files need to be registered in the ```build_manual.sh``` file individually by modifying the ```doc_files``` variable / array:
```bash
doc_files=( 'Configuration.md'
'Board - CC3D.md'
'...'
'...'
)
```
131 changes: 131 additions & 0 deletions docs/development/Building in Eclipse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Building in Eclipse

How to build, test & debug u360gts in Eclipse on Linux, Windows & MacOS.

## Checklist

Use this checklist to make sure you didn't miss a step. Versions mandated below are current and correct as of January 2016.

- [ ] [Download and Install](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) the latest (currently 1.8) 64bit Oracle JDK [read more](#install-the-jdk)
- [ ] [Download and Install](https://eclipse.org/downloads/packages/eclipse-ide-cc-developers/lunasr2) Eclipse Luna (4.4) 64bit CDT edition, **NB:** not Mars or Neon [read more](#install-eclipse)
- [ ] [Download and Install](https://launchpad.net/gcc-arm-embedded/4.9/4.9-2015-q3-update) the GCC ARM Embedded toolchain 4.9-2015-q3-update [read more](#install-arm-toolchain)
- [ ] *Windows platform only:* [Download and Install](https://github.com/gnuarmeclipse/windows-build-tools/releases) the latest GNU ARM Eclipse Windows Build Tools
- [ ] *Windows platform only:* Download and Install either [Cygwin](http://cygwin.com/install.html) or [MinGW MSYS](http://sourceforge.net/projects/mingw/files/latest/download)
- [ ] Optionally [Download and Install](https://github.com/gnuarmeclipse/openocd/releases) the latest GNU ARM Eclipse OpenOCD [read more](#install-openocd)
- [ ] *Linux platform only:* [Configure UDEV](http://gnuarmeclipse.github.io/openocd/install/#udev) to recognise USB JTAG probes
- [ ] *Windows platform only:* [Download and Install](http://www.st.com/web/en/catalog/tools/FM147/SC1887/PF260219) the ST-Link / ST-LinkV2 drivers. These drivers do work on Windows 10 even if not yet mentioned by ST.
- [ ] Optionally [Download and Install](https://github.com/gnuarmeclipse/qemu/releases) the latest GNU ARM Eclipse QEMU [read more](#install-qemu)
- [ ] Add a new update site to Eclipse named "GNU ARM Eclipse Plugins" with the URL "http://gnuarmeclipse.sourceforge.net/updates" and install all the features offered
- [ ] Configure [the recommended workspace settings](http://gnuarmeclipse.github.io/eclipse/workspace/preferences/)
- [ ] Checkout the u360gts source code [read more](#checkout-u360gts)
- [ ] *Windows platform only:* Add the msys or cygwin bin directory to the project path
- [ ] Build the code by going to *Project menu -> Build All* [read more](#build)
- [ ] Run the tests by creating and running a make target named "test"
- [ ] Configure debugging [read more](#configure-debugging)

## Extended Notes

### Install the JDK

The [minimum JDK version](http://gnuarmeclipse.github.io/plugins/install/#java) supported by GNU Arm Eclipse is 1.7 but the current latest, 1.8, is recommended instead. While Oracle JDK is the recommended version, [they do also support](http://gnuarmeclipse.github.io/plugins/install/#java) the OpenJDK.

### Install Eclipse

Eclipse Luna v4.4 is the preferred version for GNU Arm Tools currently. The minimum Eclipse version is Kepler 4.3. The maximum is Mars 4.5 although it is not tested by GNU Arm Eclipse and some things are [known to be broken](http://gnuarmeclipse.github.io/plugins/install/#eclipse--cdt). Eclipse Neon is currently not released.

CDT v8.6.0, as shipped in the Eclipse Luna CDT download, is recommended. The minimum CDT version is 8.3.

The 64bit Eclipse is preferred but a 32bit Eclipse can be used; ensure you run it on a 32bit JDK.

### Install ARM Toolchain

The minimum version is 4.8-2014-q2. The maximum, and currently recommended version, is 4_9-2015q3.

GNU ARM Tools recommends that you don't add the toolchain to your path environment variable. This means you can install multiple versions of the toolchain without conflict. If you'll install only one version, it can make life easier when working outside Eclipse to add it to your path.

Retain the default installation directories so that the GNU ARM Plugins can locate the toolchain.

### Install OpenOCD

You should install OpenOCD If you will be debugging on real hardware, such as the STM32F3DISCOVERY dev board. It is not required to simply build u360gts or run the tests.

### Install QEMU

No tests currently run on the QEMU emulator therefore this install is entirely optional. It is useful to test your installation, since you can compile and run a blinky demo.

### Checkout u360gts

If you'll be submitting changes to u360gts, [fork the repository](https://help.github.com/articles/fork-a-repo/) on GitHub and checkout your copy.

In Eclipse go to *File -> Import* choose *Git -> Projects from Git*

![projects from git](assets/building-in-eclipse/checkout-u360gts-001.PNG)

Choose *Clone URI*

![clone uri](assets/building-in-eclipse/checkout-u360gts-002.PNG)

Enter the URI https://github.com/u360gts/u360gts or if you've forked the repo, enter your URI instead. With a fork, you will need to specify your authentication details

![enter uri](assets/building-in-eclipse/checkout-u360gts-003.PNG)

On the branch selection dialog, de-select all branches and select only *master*

![choose branches to clone](assets/building-in-eclipse/checkout-u360gts-004.PNG)

Select the default destination directory

![destination](assets/building-in-eclipse/checkout-u360gts-005.PNG)

When the download completes, choose *Use the New Project wizard* and click Finish

![finish](assets/building-in-eclipse/checkout-u360gts-006.PNG)

Choose *C/C++ -> Makefile Project with Existing Code*

![makefile project](assets/building-in-eclipse/checkout-u360gts-007.PNG)

Enter u360gts as the project name and browse to your home directory -> git -> u360gts for the existing code location. Ensure the C (u360gts) and C++ (tests) languages are checked. Choose the Cross ARM GCC toolchain for the Indexer Settings. Click finish.

![finish checkout](assets/building-in-eclipse/checkout-u360gts-008.PNG)

Set your build and debug targets by going to project properties -> C/C++ Build and choose the Behaviour tab. Replace "all" in the build box with "TARGET=xxx DEBUG=GDB" where xxx is your platform such as NAZE

![build](assets/building-in-eclipse/checkout-u360gts-012.PNG)

On Windows only, add msys or cygwin bin directory to the project's path by right clicking the project and choosing properties

![properties](assets/building-in-eclipse/checkout-u360gts-009.PNG)

Edit the path variable in *C/C++ Build -> Environment*

![edit path](assets/building-in-eclipse/checkout-u360gts-010.PNG)

Append the full path to the relevant bin dir

![append bin dir](assets/building-in-eclipse/checkout-u360gts-011.PNG)

### Build

Choose project -> build all

![build all](assets/building-in-eclipse/checkout-u360gts-013.PNG)

### Configure Debugging

Choose debug -> debug configurations

![debug configurations](assets/building-in-eclipse/checkout-u360gts-014.PNG)

Create a new OpenOCD configuration for the obj\main\u360gts_XXX.elf application (this file is generated by the build step above)

![debug configurations](assets/building-in-eclipse/checkout-u360gts-015.PNG)

Add the appropriate openocd board configuration parameter for your dev platform

![openocd target](assets/building-in-eclipse/checkout-u360gts-016.PNG)

Add the target to your debug menu favourites

![debug favs](assets/building-in-eclipse/checkout-u360gts-017.PNG)

16 changes: 16 additions & 0 deletions docs/development/Building in Fedora.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Building in Fedora

Assuming you already have wget and git available, you should be able to build u360gts on a fresh install of Fedora with the following commands (tested on F18, F20 and Ubuntu 14.04):

```
wget http://distribute.atmel.no/tools/opensource/Atmel-ARM-GNU-Toolchain/4.8.4/arm-gnu-toolchain-4.8.4.371-linux.any.x86_64.tar.gz
tar xf arm-gnu-toolchain-4.8.4.371-linux.any.x86_64.tar.gz
export PATH=$PATH:$PWD/arm-none-eabi/bin
git clone https://github.com/u360gts/u360gts.git
cd u360gts
TARGET=NAZE make
```

This will create u360gts_NAZE.hex in the obj folder.
107 changes: 107 additions & 0 deletions docs/development/Building in Mac OS X.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Building in Mac OS X

Building in Mac OS X can be accomplished in just a few steps:

* Install general development tools (clang, make, git)
* Install ARM GCC 4.9 series compiler
* Checkout u360gts sourcecode through git
* Build the code

## Install general development tools (clang, make, git)

Open up a terminal and run `make`. If it is installed already, you should see a message like this, which means that you
already have the required development tools installed:

```
make: *** No targets specified and no makefile found. Stop.
```

If it isn't installed yet, you might get a popup like this. If so, click the "install" button to install the commandline
developer tools:

![Prompt to install developer tools](assets/mac-prompt-tools-install.png)

If you just get an error like this instead of a helpful popup prompt:

```
-bash: make: command not found
```

Try running `xcode-select --install` instead to trigger the popup.

If that doesn't work, you'll need to install the XCode development environment [from the App Store][]. After
installation, open up XCode and enter its preferences menu. Go to the "downloads" tab and install the
"command line tools" package.

[from the App Store]: https://itunes.apple.com/us/app/xcode/id497799835

## Install ARM GCC 4.9 series compiler

u360gts is built using the 4.9 series GCC compiler provided by the [GNU Tools for ARM Embedded Processors project][].

Hit the "all downloads" link on the right side of the GNU Tools for ARM page to view [the older releases][]. Grab the
Mac installation tarball for the latest version in the 4.9 series (e.g. 4.9-2015q2). Move it somewhere useful
such as a `~/development` folder (in your home directory) and double click it to unpack it. You should end up with a
folder called `~/development/gcc-arm-none-eabi-4_9-2015q2/`.

Now you just need to add the `bin/` directory from inside the GCC directory to your system's path. Run `nano ~/.profile`. Add a
new line at the end of the file which adds the path for the `bin/` folder to your path, like so:

```
export PATH=$PATH:~/development/gcc-arm-none-eabi-4_9-2015q2/bin
```

Press CTRL+X to exit nano, and answer "y" when prompted to save your changes.

Now *close this terminal window* and open a new one. Try running:

```
arm-none-eabi-gcc --version
```

You should get output similar to:

```
arm-none-eabi-gcc.exe (GNU Tools for ARM Embedded Processors) 4.9.3 20150529 (release) [ARM/embedded-4_9-branch revision 224288]
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

If `arm-none-eabi-gcc` couldn't be found, go back and check that you entered the correct path in your `~/.profile` file.

[GNU Tools for ARM Embedded Processors project]: https://launchpad.net/gcc-arm-embedded
[the older releases]: https://launchpad.net/gcc-arm-embedded/+download

## Checkout u360gts sourcecode through git

Enter your development directory and clone the [u360gts repository][] using the "HTTPS clone URL" which is shown on
the right side of the u360gts GitHub page, like so:

```
git clone https://github.com/u360gts/u360gts.git
```

This will download the entire u360gts repository for you into a new folder called "u360gts".

[u360gts repository]: https://github.com/u360gts/u360gts

## Build the code

Enter the u360gts directory and run `make TARGET=NAZE` to build firmware for the Naze32. When the build completes,
the .hex firmware should be available as `obj/u360gts_NAZE.hex` for you to flash using the u360gts
Configurator.

## Updating to the latest source

If you want to erase your local changes and update to the latest version of the u360gts source, enter your
u360gts directory and run these commands to first erase your local changes, fetch and merge the latest
changes from the repository, then rebuild the firmware:

```
git reset --hard
git pull
make clean TARGET=NAZE
make TARGET=NAZE
```
Loading

0 comments on commit 1e72377

Please sign in to comment.