samples/drivers/disco: add 'disco' sample program

Add a sample program for blinking with GPIO connected LEDs. The sample
program by assumes the use of Nucleo-64 F103RB development board as the
target and will need to be updated for other platforms. The intention is
that the code will serve as an example of how to use GPIOs in one's
code.

Change-Id: Ia190a7ad5b07181731c9f502d87bd0ef0ba1abde
Origin: Original
Signed-off-by: Maciej Borzecki <maciek.borzecki@gmail.com>
This commit is contained in:
Maciek Borzecki 2016-03-03 15:33:36 +01:00 committed by Gerrit Code Review
parent 84cf5a8b0b
commit 291415a6c4
6 changed files with 104 additions and 0 deletions

View file

@ -0,0 +1,6 @@
MDEF_FILE = prj.mdef
KERNEL_TYPE = micro
BOARD ?= nucleo_f103rb
CONF_FILE = prj.conf
include ${ZEPHYR_BASE}/Makefile.inc

View file

@ -0,0 +1,42 @@
Title: Disco demo
Description:
A simple 'disco' demo. The demo assumes that 2 LEDs are connected to
GPIO outputs of the MCU/board. The sample code is configured to work
on Nucleo-64 F103RB board, with LEDs connected to PB5 and PB8
pins.
After startup, the program looks up a predefined GPIO device (GPIOB),
and configures pins 5 and 8 in output mode. During each iteration of
the main loop, the state of GPIO lines will be changed so that one of
the lines is in high state, while the other is in low, thus switching
the LEDs on and off in an alternating pattern.
--------------------------------------------------------------------------------
Building and Running Project:
This microkernel project does not output to the console, but instead
causes two LEDs connected to the GPIO device to blink in an
alternating pattern. It can be built for a nucleo_f103rb board as
follows:
make
The code may need adaption before running the code on another board.
--------------------------------------------------------------------------------
Troubleshooting:
Problems caused by out-dated project information can be addressed by
issuing one of the following commands then rebuilding the project:
make clean # discard results of previous builds
# but keep existing configuration info
or
make pristine # discard results of previous builds
# and restore pre-defined configuration info
--------------------------------------------------------------------------------

View file

@ -0,0 +1 @@
# use default configuration settings

View file

@ -0,0 +1,5 @@
% Application : Disco
% TASK NAME PRIO ENTRY STACK GROUPS
% ==================================
TASK TASKA 7 main 2048 [EXE]

View file

@ -0,0 +1 @@
obj-y = main.o

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2016 Open-RnD Sp. z o.o.
*
* 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.
*/
#include <zephyr.h>
#include <device.h>
#include <gpio.h>
/**
* the demo assumes use of nucleo_f103rb board, adjust defines below
* to fit your board
*/
/* we're going to use PB8 and PB5 */
#define PORT "GPIOB"
/* PB5 */
#define LED1 5
/* PB8 */
#define LED2 8
void main(void)
{
int cnt = 0;
struct device *gpiob;
gpiob = device_get_binding(PORT);
gpio_pin_configure(gpiob, LED1, GPIO_DIR_OUT);
gpio_pin_configure(gpiob, LED2, GPIO_DIR_OUT);
while (1) {
gpio_pin_write(gpiob, LED1, cnt % 2);
gpio_pin_write(gpiob, LED2, (cnt + 1) % 2);
task_sleep(SECONDS(1));
cnt++;
}
}