Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions boards/openlabs-kw41z-mini/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE = board

include $(RIOTBASE)/Makefile.base
9 changes: 9 additions & 0 deletions boards/openlabs-kw41z-mini/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_adc
USEMODULE += saul_gpio
endif

# TODO uncomment after #12277 (add support for kw41zrf) is merged
# ifneq (,$(filter netdev_default gnrc_netdev_default,$(USEMODULE)))
# USEMODULE += kw41zrf
# endif
15 changes: 15 additions & 0 deletions boards/openlabs-kw41z-mini/Makefile.features
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CPU = kinetis
CPU_MODEL = mkw41z512vht4

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_dac
FEATURES_PROVIDED += periph_i2c
# TODO uncomment this after Kinetis PWM support is merged
# FEATURES_PROVIDED += periph_pwm
FEATURES_PROVIDED += periph_rtc
FEATURES_PROVIDED += periph_rtt
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += riotboot
17 changes: 17 additions & 0 deletions boards/openlabs-kw41z-mini/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Configure riotboot bootloader and slot lengths.
RIOTBOOT_LEN ?= 0x4000
NUM_SLOTS ?= 2
SLOT0_LEN ?= 0x3C000
SLOT1_LEN ?= $(SLOT0_LEN)

# support SWD and UART via Pi GPIO header
PORT_LINUX ?= /dev/serial0
# TODO change to bcm2835gpio after it's merged as it's faster
# DEBUG_ADAPTER ?= bcm2835gpio
DEBUG_ADAPTER ?= sysfs_gpio
SRST_PIN ?= 16
SWCLK_PIN ?= 20
SWDIO_PIN ?= 21

# Include default FRDM board config for openocd configuration
include $(RIOTBOARD)/common/frdm/Makefile.include
43 changes: 43 additions & 0 deletions boards/openlabs-kw41z-mini/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2017 Thomas Stilwell <stilwellt@openlabs.co>
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/

/**
* @ingroup boards_openlabs-kw41z-mini
* @{
*
* @file
* @brief Board specific initialization for openlabs-kw41z-mini
*
* @author Thomas Stilwell <stilwellt@openlabs.co>
*
* @}
*/

#include "board.h"
#include "periph/rtc.h"
#include "periph/gpio.h"

void board_init(void)
{
/* initialize the CPU core */
cpu_init();

/* initialize and turn off LEDs */
LED0_OFF;
gpio_init(LED0_PIN, GPIO_OUT);
Comment thread
benpicco marked this conversation as resolved.

/* enable OSCERCLK output on PTB3 */
#if PTB3_OUTPUT_OSCERCLK
Comment thread
benpicco marked this conversation as resolved.
SIM->SOPT2 |= SIM_SOPT2_CLKOUTSEL(0b110);
gpio_init_port(GPIO_PIN(PORT_B, 3), PORT_PCR_MUX(4));

/* enable 32KHz oscillator output on PTB3 */
#elif PTB3_OUTPUT_OSC32K
Comment thread
benpicco marked this conversation as resolved.
SIM->SOPT1 |= SIM_SOPT1_OSC32KOUT_MASK;
#endif
}
100 changes: 100 additions & 0 deletions boards/openlabs-kw41z-mini/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
@defgroup boards_openlabs-kw41z-mini openlabs.co kw41z-mini board
@ingroup boards
@brief Support for openlabs-kw41z-mini

### General information

This is an open-source development board shipped by openlabs.co with
source files located at https://openlabs.co/OSHW/kw41z-mini

A driver for the radio transceiver is available in #12277 (802.15.4 only).


### Programming Pinout

Programming and debugging can be done with a Raspberry Pi (or equivalent)
running OpenOCD.


Pi GPIO Pins kw41z-mini
====================================
||
GPIO_19 ------||------- RST
||
GPIO_20 ------||------- SWDCLK
||
GPIO_21 ------||------- SWDIO
||
3.3V -------||------- 3.3V
||
GND -------||------- GND
||


### Compiling and Flashing

# install build deps for openocd
apt install git build-essential libtool automake
# fetch and build openocd with support for JTAG via RPi or generic GPIO
git clone https://github.com/beduino-project/openocd.git
cd openocd
./bootstrap
./configure --enable-bcm2835gpio --enable-sysfsgpio
make -j4 && sudo make install

# install arm toolchain
apt install git gcc-arm-none-eabi gdb-arm-none-eabi
# fetch Riot
git clone https://github.com/RIOT-OS/RIOT.git
# build and flash the gnrc_networking example
cd RIOT/examples/gnrc_networking
BOARD=openlabs-kw41z-mini CFLAGS+="-DKW41ZRF_ENABLE_LEDS=1" make -j4 flash


### Debug Uart Pinout

It is also possible to use the Pi for connecting to the debug uart.


Pi GPIO Pins kw41z-mini
==================================
||
UART TX ----||------ RXI
||
UART RX ----||------ TXO
||
GND ------||------ GND
||


# enable the uart on the Pi
echo "enable_uart=1" >> /boot/config.txt
reboot
# install serial terminal
apt install picocom
# run serial terminal to access debug uart
picocom -b115200 /dev/serial0


It is recommended (if possible) to switch the Pi to the better-clocked
uart for higher baud rates:

echo "dtoverlay=disable-bt" >> /boot/config.txt
reboot


### Notes

To get a working radio, add #12277 and uncomment the lines in
boards/openlabs-kw41z-mini/Makefile.dep

The DAC output is on pin PTB18.

ADC input A3 needs a hack applied to cpu/kinetis/periph/adc.c to remove
ADC_CFG2_MUXSEL_MASK from CFG2 to switch to the correct mux setting.

The PWM peripheral on this board isn't supported in the Kinetis PWM driver yet.

Use external I2C pullup resistors if I2C is used.
*/
77 changes: 77 additions & 0 deletions boards/openlabs-kw41z-mini/include/adc_params.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2017 Thomas Stilwell <stilwellt@openlabs.co>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup boards_openlabs-kw41z-mini
* @{
*
* @file
* @brief Board specific configuration of direct mapped ADC
*
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
* @author Thomas Stilwell <stilwellt@openlabs.co>
*/

#ifndef ADC_PARAMS_H
#define ADC_PARAMS_H

#include "board.h"
#include "saul/periph.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief ADC configuration
*/
static const saul_adc_params_t saul_adc_params[] =
{
{
.name = "A0",
.line = ADC_LINE(0),
.res = ADC_RES_16BIT,
},
{
.name = "A1",
.line = ADC_LINE(1),
.res = ADC_RES_16BIT,
},
{
.name = "A2",
.line = ADC_LINE(2),
.res = ADC_RES_16BIT,
},
{
.name = "A3",
.line = ADC_LINE(3),
.res = ADC_RES_16BIT,
},
{
.name = "coretemp",
.line = ADC_LINE(4),
.res = ADC_RES_16BIT,
},
{
.name = "corebandgap",
.line = ADC_LINE(5),
.res = ADC_RES_16BIT,
},
{
.name = "dcdcvbat",
.line = ADC_LINE(6),
.res = ADC_RES_16BIT,
},
};

#ifdef __cplusplus
}
#endif

#endif /* ADC_PARAMS_H */
/** @} */
98 changes: 98 additions & 0 deletions boards/openlabs-kw41z-mini/include/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (C) 2017 Thomas Stilwell <stilwellt@openlabs.co>
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/

/**
* @ingroup boards_openlabs-kw41z-mini
* @{
*
* @file
* @brief Board specific definitions for openlabs-kw41z-mini
*
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
* @author Thomas Stilwell <stilwellt@openlabs.co>
*/

#ifndef BOARD_H
#define BOARD_H

#include "cpu.h"
#include "periph_conf.h"

#ifdef __cplusplus
extern "C"
{
#endif

/*
* NMI shares a pin with DAC output and ADC input. Holding the pin low during
* reset will cause a hang unless NMI is disabled. It can be enabled in
* applications where the pin is not held low during reset.
*/
#define KINETIS_FOPT 0xFB /* disable NMI (0xFF to enable) */

/**
* @name LED pin definitions and handlers
* @{
*/
#define LED0_PIN GPIO_PIN(PORT_B, 0)
#define LED0_MASK (1 << 0)
#define LED0_ON (GPIOB->PCOR = LED0_MASK)
#define LED0_OFF (GPIOB->PSOR = LED0_MASK)
#define LED0_TOGGLE (GPIOB->PTOR = LED0_MASK)
/** @} */

/**
* @name xtimer configuration
* @{
*/
#if KINETIS_XTIMER_SOURCE_PIT
/* PIT xtimer configuration */
#define XTIMER_DEV (TIMER_PIT_DEV(0))
#define XTIMER_CHAN (0)
/* Default xtimer settings should work on the PIT */
#else
/* LPTMR xtimer configuration */
#define XTIMER_DEV (TIMER_LPTMR_DEV(0))
#define XTIMER_CHAN (0)
/* LPTMR is 16 bits wide and runs at 32768 Hz (clocked by the RTC) */
#define XTIMER_WIDTH (16)
#define XTIMER_BACKOFF (16)
#define XTIMER_ISR_BACKOFF (5)
#define XTIMER_HZ (32768ul)
#endif
/** @} */

/**
* @def PTB3_OUTPUT_OSC32K
*
* @brief Enable LF oscillator output on PTB3 to aid debugging or calibration
*/
#ifndef PTB3_OUTPUT_OSC32K
#define PTB3_OUTPUT_OSC32K (0)
#endif

/**
* @def PTB3_OUTPUT_OSCERCLK
*
* @brief Enable HF oscillator output on PTB3 to aid debugging or calibration
*/
#ifndef PTB3_OUTPUT_OSCERCLK
#define PTB3_OUTPUT_OSCERCLK (0)
#endif

/**
* @brief Initialize board-specific hardware, including clock, LEDs, and stdio
*/
void board_init(void);

#ifdef __cplusplus
}
#endif

#endif /* BOARD_H */
/** @} */
Loading