diff --git a/README.md b/README.md index 1e172fc..3b3e17c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,17 @@ # ABC-fw -Firmware for the ABC board +## Installation and usage -To build, use the command "west build -p auto -b nrf52840_ble_cell abc_fw/samples/hello_world/" +How to get an ABC board working: -Do this one level above this directory, if you have used the yaml script ("west init -m https://github.com/ChrisGammell/ABC-fw.git") +1. Install Zephyr stuff (steps 1-4): https://buff.ly/3ohvK42 +2. west init -m https://github.com/ContextualElectronics/ABC-fw.git +3. west update +4. west build -p auto -b contextualelectronics_abc abc_fw/samples/blinky/ +5. west flash +6. Revel in an ABC board happily blinking at you + +Note: This can be installed in a "fw" directory at the top level of an "ABC" directory, or similar. A normal directory looks like this + +* ABC + * fw + * hw \ No newline at end of file diff --git a/samples/blinky/CMakeLists.txt b/samples/blinky/CMakeLists.txt new file mode 100644 index 0000000..54f8909 --- /dev/null +++ b/samples/blinky/CMakeLists.txt @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(blinky) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/blinky/README.rst b/samples/blinky/README.rst new file mode 100644 index 0000000..96f5720 --- /dev/null +++ b/samples/blinky/README.rst @@ -0,0 +1,44 @@ +.. _blinky-sample: + +Blinky +###### + +Overview +******** + +Blinky is a simple application which blinks an LED forever using the :ref:`GPIO +API `. The source code shows how to configure GPIO pins as outputs, +then turn them on and off. + +See :ref:`pwm-blinky-sample` for a sample which uses the PWM API to blink an +LED. + +.. _blinky-sample-requirements: + +Requirements +************ + +You will see this error if you try to build Blinky for an unsupported board: + +.. code-block:: none + + Unsupported board: led0 devicetree alias is not defined + +The board must have an LED connected via a GPIO pin. These are called "User +LEDs" on many of Zephyr's :ref:`boards`. The LED must be configured using the +``led0`` :ref:`devicetree ` alias. This is usually done in the +:ref:`BOARD.dts file ` or a :ref:`devicetree overlay +`. + +Building and Running +******************** + +Build and flash Blinky as follows, changing ``reel_board`` for your board: + +.. zephyr-app-commands:: + :zephyr-app: samples/basic/blinky + :board: reel_board + :goals: build flash + :compact: + +After flashing, the LED starts to blink. Blinky does not print to the console. diff --git a/samples/blinky/prj.conf b/samples/blinky/prj.conf new file mode 100644 index 0000000..91c3c15 --- /dev/null +++ b/samples/blinky/prj.conf @@ -0,0 +1 @@ +CONFIG_GPIO=y diff --git a/samples/blinky/sample.yaml b/samples/blinky/sample.yaml new file mode 100644 index 0000000..9c8ac6f --- /dev/null +++ b/samples/blinky/sample.yaml @@ -0,0 +1,10 @@ +sample: + name: Blinky Sample +tests: + sample.basic.blinky: + tags: LED gpio + filter: dt_compat_enabled_with_alias("gpio-leds", "led0") + depends_on: gpio + harness: led + integration_platforms: + - frdm_k64f diff --git a/samples/blinky/src/main.c b/samples/blinky/src/main.c new file mode 100644 index 0000000..e2fbfd3 --- /dev/null +++ b/samples/blinky/src/main.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +/* 1000 msec = 1 sec */ +#define SLEEP_TIME_MS 1000 + +/* The devicetree node identifier for the "led0" alias. */ +#define LED0_NODE DT_ALIAS(led0) + +#if DT_NODE_HAS_STATUS(LED0_NODE, okay) +#define LED0 DT_GPIO_LABEL(LED0_NODE, gpios) +#define PIN DT_GPIO_PIN(LED0_NODE, gpios) +#define FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios) +#else +/* A build error here means your board isn't set up to blink an LED. */ +#error "Unsupported board: led0 devicetree alias is not defined" +#define LED0 "" +#define PIN 0 +#define FLAGS 0 +#endif + +void main(void) +{ + const struct device *dev; + bool led_is_on = true; + int ret; + + dev = device_get_binding(LED0); + if (dev == NULL) { + return; + } + + ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS); + if (ret < 0) { + return; + } + + while (1) { + gpio_pin_set(dev, PIN, (int)led_is_on); + led_is_on = !led_is_on; + k_msleep(SLEEP_TIME_MS); + } +} diff --git a/samples/hello_world/CMakeLists.txt b/samples/hello_world/CMakeLists.txt new file mode 100644 index 0000000..3e3d0e8 --- /dev/null +++ b/samples/hello_world/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(hello_world) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/hello_world/README.rst b/samples/hello_world/README.rst new file mode 100644 index 0000000..ce5423d --- /dev/null +++ b/samples/hello_world/README.rst @@ -0,0 +1,33 @@ +.. _hello_world: + +Hello World +########### + +Overview +******** + +A simple sample that can be used with any :ref:`supported board ` and +prints "Hello World" to the console. + +Building and Running +******************** + +This application can be built and executed on QEMU as follows: + +.. zephyr-app-commands:: + :zephyr-app: samples/hello_world + :host-os: unix + :board: qemu_x86 + :goals: run + :compact: + +To build for another board, change "qemu_x86" above to that board's name. + +Sample Output +============= + +.. code-block:: console + + Hello World! x86 + +Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`. diff --git a/samples/hello_world/prj.conf b/samples/hello_world/prj.conf new file mode 100644 index 0000000..b2a4ba5 --- /dev/null +++ b/samples/hello_world/prj.conf @@ -0,0 +1 @@ +# nothing here diff --git a/samples/hello_world/sample.yaml b/samples/hello_world/sample.yaml new file mode 100644 index 0000000..bacc394 --- /dev/null +++ b/samples/hello_world/sample.yaml @@ -0,0 +1,16 @@ +sample: + description: Hello World sample, the simplest Zephyr + application + name: hello world +common: + tags: introduction + integration_platforms: + - native_posix + harness: console + harness_config: + type: one_line + regex: + - "Hello World! (.*)" +tests: + sample.basic.helloworld: + tags: introduction diff --git a/samples/hello_world/src/main.c b/samples/hello_world/src/main.c new file mode 100644 index 0000000..6c5c8a2 --- /dev/null +++ b/samples/hello_world/src/main.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2012-2014 Wind River Systems, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +void main(void) +{ + printk("Hello World! %s\n", CONFIG_BOARD); +} diff --git a/west.yml b/west.yml index 4fe2646..b961517 100644 --- a/west.yml +++ b/west.yml @@ -1,14 +1,15 @@ -# The west manifest file for Zephyr based ABC board. - manifest: remotes: - name: zephyrproject-rtos - url-base: https://github.com/zephyrproject-rtos + url-base: https://github.com/bwasim - name: ABC-fw url-base: https://github.com/ContextualElectronics - + defaults: + remote: ABC-fw projects: - name: zephyr remote: zephyrproject-rtos - revision: v2.0.0 + revision: ble-cell import: true + self: + path: abc_fw