Skip to content

Commit

Permalink
add support for phyWAVE-KW2x Board, pba-d-01-kw2x
Browse files Browse the repository at this point in the history
  • Loading branch information
jfischer-no committed Jan 5, 2015
1 parent 6d5973f commit af03da0
Show file tree
Hide file tree
Showing 12 changed files with 917 additions and 0 deletions.
4 changes: 4 additions & 0 deletions boards/pba-d-01-kw2x/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# tell the Makefile.base which module to build
MODULE = $(BOARD)_base

include $(RIOTBASE)/Makefile.base
1 change: 1 addition & 0 deletions boards/pba-d-01-kw2x/Makefile.features
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FEATURES_PROVIDED = periph_gpio periph_uart periph_spi periph_i2c periph_pwm periph_adc periph_rtc periph_random periph_cpuid
50 changes: 50 additions & 0 deletions boards/pba-d-01-kw2x/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# define the cpu used by the phyWAVE-KW22 board
export CPU = kw2x
export CPU_MODEL = kw22d512

#define the default port depending on the host OS
OS := $(shell uname)
ifeq ($(OS),Linux)
PORT ?= /dev/ttyACM0
else ifeq ($(OS),Darwin)
PORT ?= $(shell ls -1 /dev/tty.SLAB_USBtoUART* | head -n 1)
else
$(info CAUTION: No flash tool for your host system found!)
endif
export PORT

# define tools used for building the project
export PREFIX = arm-none-eabi-
export CC = $(PREFIX)gcc
export AR = $(PREFIX)ar
export AS = $(PREFIX)as
export LINK = $(PREFIX)gcc
export SIZE = $(PREFIX)size
export OBJCOPY = $(PREFIX)objcopy
export TERMPROG = $(RIOTBASE)/dist/tools/pyterm/pyterm
export FLASHER = $(RIOTBOARD)/$(BOARD)/dist/flash.sh
export DEBUGGER = $(RIOTBOARD)/$(BOARD)/dist/debug.sh
export RESET = $(RIOTBOARD)/$(BOARD)/dist/reset.sh
export DEBUGSERVER = openocd

# define build specific options
CPU_USAGE = -mcpu=cortex-m4
FPU_USAGE =
export CFLAGS += -ggdb -g3 -std=gnu99 -Os -Wall -Wstrict-prototypes $(CPU_USAGE) $(FPU_USAGE) -mlittle-endian -mthumb -mthumb-interwork -nostartfiles
export CFLAGS += -ffunction-sections -fdata-sections -fno-builtin
export ASFLAGS += -ggdb -g3 $(CPU_USAGE) $(FPU_USAGE) -mlittle-endian
export LINKFLAGS += -g3 -ggdb -std=gnu99 $(CPU_USAGE) $(FPU_USAGE) -mlittle-endian -static -lgcc -mthumb -mthumb-interwork -nostartfiles
export LINKFLAGS += -T$(LINKERSCRIPT)
export OFLAGS = -O binary
export FFLAGS = $(HEXFILE)
export DEBUGGER_FLAGS = $(RIOTBOARD)/$(BOARD)/dist/gdb.conf $(ELFFILE)
export TERMFLAGS = -p $(PORT)

# use newLib nano-specs if available
ifeq ($(shell $(LINK) -specs=nano.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0)
export LINKFLAGS += -specs=nano.specs -lc -lnosys
endif

# export board specific includes to the global includes-listing
export INCLUDES += -I$(RIOTBOARD)/$(BOARD)/include/

54 changes: 54 additions & 0 deletions boards/pba-d-01-kw2x/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
* Copyright (C) 2014 PHYTEC Messtechnik GmbH
*
* 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 board_pba-d-01
* @{
*
* @file
* @brief Board specific implementations for the Phytec PBA-D-01
* evaluation board for PWA-A-002 Module
*
* @author Johann Fischer <j.fischer@phytec.de>
*
* @}
*/

#include "board.h"

static void leds_init(void);

void board_init(void)
{
leds_init();
cpu_init();
}

/**
* @brief Initialize the boards on-board RGB-LED
*
*/
static void leds_init(void)
{
/* enable clock */
LED_B_PORT_CLKEN();
LED_G_PORT_CLKEN();
LED_R_PORT_CLKEN();
/* configure pins as gpio */
LED_B_PORT->PCR[LED_B_PIN] = PORT_PCR_MUX(1);
LED_G_PORT->PCR[LED_G_PIN] = PORT_PCR_MUX(1);
LED_R_PORT->PCR[LED_R_PIN] = PORT_PCR_MUX(1);
LED_B_GPIO->PDDR |= (1 << LED_B_PIN);
LED_G_GPIO->PDDR |= (1 << LED_G_PIN);
LED_R_GPIO->PDDR |= (1 << LED_R_PIN);
/* turn all LEDs off */
LED_B_GPIO->PSOR |= (1 << LED_B_PIN);
LED_G_GPIO->PSOR |= (1 << LED_G_PIN);
LED_R_GPIO->PSOR |= (1 << LED_R_PIN);
}
36 changes: 36 additions & 0 deletions boards/pba-d-01-kw2x/dist/debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Based on iot-lab_M3 debug.sh script.
# Author: Jonas Remmert j.remmert@phytec.de

echo PBA-D-01 Debug script executed

openocd -f"../../boards/pba-d-01-kw2x/dist/mkw22d512.cfg" \ #"${RIOTBOARD}/${BOARD}/dist/mkw22d512.cfg" \
-c "tcl_port 6333" \
-c "telnet_port 4444" \
-c "init" \
-c "targets" \
-c "reset halt" \
-l /dev/null &

# save pid to terminate afterwards
OCD_PID=$?

# needed for openocd to set up
sleep 1

retval=$(arm-none-eabi-readelf -x .fcfield $2 | awk '/0x00000400/ {print $2 $3 $4 $5}')
unlocked_fcfield="fffffffffffffffffffffffffeffffff"

if [ "$retval" == "$unlocked_fcfield" ]; then
echo "Flash configuration tested... [OK]"
arm-none-eabi-gdb -tui --command=${1} ${2}
#cgdb -d arm-none-eabi-gdb --command=${1} ${2}

else
echo "Hexdump, .fcfield of $2"
retval=$(arm-none-eabi-readelf -x .fcfield $2)
echo $retval
echo "Fcfield not fitting to MKW22Dxxx, danger of bricking the device during flash...[abort]"
fi
kill ${OCD_PID}
48 changes: 48 additions & 0 deletions boards/pba-d-01-kw2x/dist/flash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Based on iot-lab_M3 debug.sh script.
# Author: Jonas Remmert j.remmert@phytec.de

elffile=`echo $1 | sed 's/.hex/.elf/'`

echo The file: $elffile will be flashed to the board: $BOARD .
echo Press y to proceed, v to proceed with verify or any other key to abort.
read x

retval=$(arm-none-eabi-readelf -x .fcfield $elffile | awk '/0x00000400/ {print $2 $3 $4 $5}')
unlocked_fcfield="fffffffffffffffffffffffffeffffff"

if [ "$retval" != "$unlocked_fcfield" ]; then
echo "Hexdump, .fcfield of $elffile"
retval=$(arm-none-eabi-readelf -x .fcfield $elffile)
echo $retval
echo "Fcfield not fitting to MKW22Dxxx, danger of bricking the device during flash...[abort]"
exit 0
fi
echo "Flash configuration tested... [OK]"


# flash without verify
if [ $x = "y" ] || [ $x = "v" ];# -o $x -eq v ];
then
echo "Flashing device, do not disconnect or reset the target until this script exits!!!"
openocd -f "../../boards/pba-d-01-kw2x/dist/mkw22d512.cfg" \
-c "init" \
-c "reset halt" \
-c "flash write_image erase $elffile" \
-c "reset run" \
-c "exit"
fi

# verify
if [ "$x" = "v" ];
then
echo "Flashing device in 1s, do not disconnect or reset the target until this script exits!!!"
openocd -f "../../boards/pba-d-01-kw2x/dist/mkw22d512.cfg" \
-c "init" \
-c "reset halt" \
-c "verify_image $elffile" \
-c "reset run" \
-c "exit"
fi
echo done...
4 changes: 4 additions & 0 deletions boards/pba-d-01-kw2x/dist/gdb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target remote localhost:3333
monitor reset halt
set print pretty
set arm force-mode thumb
71 changes: 71 additions & 0 deletions boards/pba-d-01-kw2x/dist/mkw22d512.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#
# Freescale Kinetis kw2xdxxx devices
#
source [find interface/cmsis-dap.cfg]

#
# K21 devices support both JTAG and SWD transports.
#
source [find target/swj-dp.tcl]

if { [info exists CHIPNAME] } {
set _CHIPNAME $CHIPNAME
} else {
set _CHIPNAME kw22d512
}

# Work-area is a space in RAM used for flash programming
set WORKAREASIZE 0x4000

if { [info exists WORKAREASIZE] } {
set _WORKAREASIZE $WORKAREASIZE
} else {
set _WORKAREASIZE 0x1000
}

if { [info exists ENDIAN] } {
set _ENDIAN $ENDIAN
} else {
set _ENDIAN little
}

if { [info exists CPUTAPID] } {
set _CPUTAPID $CPUTAPID
} else {
set _CPUTAPID 0x2ba01477
}

set _TARGETNAME $_CHIPNAME.cpu

swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
#swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID

target create $_TARGETNAME cortex_m -chain-position $_CHIPNAME.cpu

$_CHIPNAME.cpu configure -event examine-start { puts "START..." ; }

# It is important that "kinetis mdm check_security" is called for
# 'examine-end' event and not 'eximine-start'. Calling it in 'examine-start'
# causes "kinetis mdm check_security" to fail the first time openocd
# calls it when it tries to connect after the CPU has been power-cycled.
$_CHIPNAME.cpu configure -event examine-end {
kinetis mdm check_security
}

$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0

set _FLASHNAME $_CHIPNAME.flash
flash bank $_FLASHNAME kinetis 0 0 0 0 $_TARGETNAME

#reset_config srst_only srst_nogate connect_assert_srst
adapter_khz 1000

if {![using_hla]} {
# if srst is not fitted use SYSRESETREQ to
# perform a soft reset
cortex_m reset_config sysresetreq
}

$_TARGETNAME configure -event reset-init {
adapter_khz 24000
}
74 changes: 74 additions & 0 deletions boards/pba-d-01-kw2x/dist/pll_freq.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
1;
# not a function file:

F = [2405:5:2480];
i = 1;
PLL_INT0 = [];
PLL_FRAC0 = [];
tmp_frac = 0;
tmp_int = 11;

while (i <= length(F))
tmp_frac = (F(i)./32 - tmp_int - 64).*65536;
if tmp_frac >= 65536
tmp_int++;
else
PLL_FRAC0 = [PLL_FRAC0 tmp_frac];
PLL_INT0 = [PLL_INT0 tmp_int];
i++;
endif
endwhile

%F
%Fcalc = ((PLL_INT0 + 64) + (PLL_FRAC0./65536)).*32
%PLL_INT0
%PLL_FRAC0

printf("static const uint8_t pll_int_lt[%d] = {\n", length(F));
for i = 1:4:length(F)
printf(" ");
printf("%d,", PLL_INT0(i:1:i+3));
printf("\n");
endfor
printf("};\n");
printf("\n");
printf("static const uint16_t pll_frac_lt[%d] = {\n", length(F));
for i = 1:4:length(F)
printf(" ");
printf("%d,", PLL_FRAC0(i:1:i+3));
printf("\n");
endfor
printf("};\n\n");

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

POWER_MAX=8;
POWER_MIN=-35;
RANGE_MAX=31;
RANGE_MIN=3;

i = [0:1:abs(diff([POWER_MAX POWER_MIN]))];
pow_lt = round(i .* (RANGE_MAX - RANGE_MIN) ./ length(i) + RANGE_MIN);

printf("static const uint8_t pow_lt[%d] = {", length(pow_lt));
printf(" ");
for i = 0:1:length(pow_lt)-1
if (rem(i,4) == 0)
printf("\n ");
endif
printf("%d,", pow_lt(i+1));
endfor
printf("\n};\n\n");

i = [0:1:abs(diff([RANGE_MAX RANGE_MIN]))];
level_lt = round(i .* (POWER_MAX - POWER_MIN) ./ length(i) + POWER_MIN);
length(level_lt)

printf("static const int level_lt[%d] = {", length(level_lt));
for i = 0:1:length(level_lt)-1
if (rem(i,4) == 0)
printf("\n ");
endif
printf("%d,", level_lt(i+1));
endfor
printf("\n};\n\n");
6 changes: 6 additions & 0 deletions boards/pba-d-01-kw2x/dist/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

openocd -f "../../boards/pba-d-01-kw2x/dist/mkw22d512.cfg" \
-c "init" \
-c "reset run" \
-c "shutdown"
Loading

0 comments on commit af03da0

Please sign in to comment.