Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Prerequisites

Hello World

With our development environment set up, let's make a basic project!

First, let's set up our hardware:

UART AdapterDiscovery Board
RXPB6 (TX)
TXPB7 (RX)
GND (Black)GND

Feature Branches - Git

cd ~/shared/firmware
# Create a new branch off of master
git checkout master
git checkout -b wip_getting_started

Our first step is creating a new branch, wip_getting_started. Normally, in our development workflow, we create new feature branches for each JIRA issue with the naming convention of elec_[ticket number]_[shortname]. In this case, we'll be using wip_ as a prefix instead of elec_[ticket number]_.

By convention, we use lower snake case for most of our naming schemes. For example, these documents were created under elec_281_add_basic_docs. This lets us keep our work organized. See our Git Workflow for more information.

New Project - Hello World

# Initialize the directory structure for a new project named "getting_started"
# See projects/README.md for more information on how our projects work
make new PROJECT=getting_started

With our branch created, we initialize our new project getting_started. You should see a new folder at projects/getting_started.

In your favorite editor, create a new file main.c in getting_started/src. We advise opening the firmware folder as a project or workspace in your editor supports that.

#include "log.


int main(void) {
  LOG_DEBUG("Hello World!\n");

  return 0;
}

You should have the following directory structure:

projects/getting_started/
├── inc
├── rules.mk
├── src
│   └── main.c
└── test


3 directories, 2 files

You'll notice that make new also created a rules.mk. This file is what identifies the folder getting_started as a project to our build system. Please refer to the projects readme for more information.

Running Code - Hello World

Now, it's time to build and run the project!

In a new terminal (or tmux pane), open a serial terminal:

# If no device is found, try /dev/tty[tab]
minicom -D /dev/ttyACM0

Back to the old terminal:

# Build and run the project on x86
make run PROJECT=hello_world PLATFORM=x86


# Build and run the project on STM32F0xx (discovery board)
make program PROJECT=hello_world PROBE=stlink-v2

You should see "hello world" appear twice - once when running on x86, and once in minicom! As you can see, our build system and HAL (hardware abstraction layer) allow us to build applications that can run natively on mutliple platforms. This makes testing a lot easier, and allows us to develop application code even without access to the hardware.

Clean Code - Hello World

With your code workring, we want to make sure your code matches our Coding Standards. We use two tools for that:

  • clang-format: Reformats code according to our specified style.
  • cpplint and pylint: Parses code to find discrepancies between it and our style guide. We actually use our own fork.

Note that these are both just tools, and should not be relied on to be perfect. We have a few rules that would be very difficult to parse, so please try your best to follow our style guide.

# Runs clang-format
make format
# Runs lint.py (cpplint) and pylint
make lint

Committing Changes - Git

First, we want to make s

  • No labels