Skip to content

Commit af03da0

Browse files
committed
add support for phyWAVE-KW2x Board, pba-d-01-kw2x
1 parent 6d5973f commit af03da0

File tree

12 files changed

+917
-0
lines changed

12 files changed

+917
-0
lines changed

boards/pba-d-01-kw2x/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# tell the Makefile.base which module to build
2+
MODULE = $(BOARD)_base
3+
4+
include $(RIOTBASE)/Makefile.base
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FEATURES_PROVIDED = periph_gpio periph_uart periph_spi periph_i2c periph_pwm periph_adc periph_rtc periph_random periph_cpuid
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# define the cpu used by the phyWAVE-KW22 board
2+
export CPU = kw2x
3+
export CPU_MODEL = kw22d512
4+
5+
#define the default port depending on the host OS
6+
OS := $(shell uname)
7+
ifeq ($(OS),Linux)
8+
PORT ?= /dev/ttyACM0
9+
else ifeq ($(OS),Darwin)
10+
PORT ?= $(shell ls -1 /dev/tty.SLAB_USBtoUART* | head -n 1)
11+
else
12+
$(info CAUTION: No flash tool for your host system found!)
13+
endif
14+
export PORT
15+
16+
# define tools used for building the project
17+
export PREFIX = arm-none-eabi-
18+
export CC = $(PREFIX)gcc
19+
export AR = $(PREFIX)ar
20+
export AS = $(PREFIX)as
21+
export LINK = $(PREFIX)gcc
22+
export SIZE = $(PREFIX)size
23+
export OBJCOPY = $(PREFIX)objcopy
24+
export TERMPROG = $(RIOTBASE)/dist/tools/pyterm/pyterm
25+
export FLASHER = $(RIOTBOARD)/$(BOARD)/dist/flash.sh
26+
export DEBUGGER = $(RIOTBOARD)/$(BOARD)/dist/debug.sh
27+
export RESET = $(RIOTBOARD)/$(BOARD)/dist/reset.sh
28+
export DEBUGSERVER = openocd
29+
30+
# define build specific options
31+
CPU_USAGE = -mcpu=cortex-m4
32+
FPU_USAGE =
33+
export CFLAGS += -ggdb -g3 -std=gnu99 -Os -Wall -Wstrict-prototypes $(CPU_USAGE) $(FPU_USAGE) -mlittle-endian -mthumb -mthumb-interwork -nostartfiles
34+
export CFLAGS += -ffunction-sections -fdata-sections -fno-builtin
35+
export ASFLAGS += -ggdb -g3 $(CPU_USAGE) $(FPU_USAGE) -mlittle-endian
36+
export LINKFLAGS += -g3 -ggdb -std=gnu99 $(CPU_USAGE) $(FPU_USAGE) -mlittle-endian -static -lgcc -mthumb -mthumb-interwork -nostartfiles
37+
export LINKFLAGS += -T$(LINKERSCRIPT)
38+
export OFLAGS = -O binary
39+
export FFLAGS = $(HEXFILE)
40+
export DEBUGGER_FLAGS = $(RIOTBOARD)/$(BOARD)/dist/gdb.conf $(ELFFILE)
41+
export TERMFLAGS = -p $(PORT)
42+
43+
# use newLib nano-specs if available
44+
ifeq ($(shell $(LINK) -specs=nano.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0)
45+
export LINKFLAGS += -specs=nano.specs -lc -lnosys
46+
endif
47+
48+
# export board specific includes to the global includes-listing
49+
export INCLUDES += -I$(RIOTBOARD)/$(BOARD)/include/
50+

boards/pba-d-01-kw2x/board.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (C) 2014 Freie Universität Berlin
3+
* Copyright (C) 2014 PHYTEC Messtechnik GmbH
4+
*
5+
* This file is subject to the terms and conditions of the GNU Lesser General
6+
* Public License v2.1. See the file LICENSE in the top level directory for more
7+
* details.
8+
*/
9+
10+
/**
11+
* @ingroup board_pba-d-01
12+
* @{
13+
*
14+
* @file
15+
* @brief Board specific implementations for the Phytec PBA-D-01
16+
* evaluation board for PWA-A-002 Module
17+
*
18+
* @author Johann Fischer <[email protected]>
19+
*
20+
* @}
21+
*/
22+
23+
#include "board.h"
24+
25+
static void leds_init(void);
26+
27+
void board_init(void)
28+
{
29+
leds_init();
30+
cpu_init();
31+
}
32+
33+
/**
34+
* @brief Initialize the boards on-board RGB-LED
35+
*
36+
*/
37+
static void leds_init(void)
38+
{
39+
/* enable clock */
40+
LED_B_PORT_CLKEN();
41+
LED_G_PORT_CLKEN();
42+
LED_R_PORT_CLKEN();
43+
/* configure pins as gpio */
44+
LED_B_PORT->PCR[LED_B_PIN] = PORT_PCR_MUX(1);
45+
LED_G_PORT->PCR[LED_G_PIN] = PORT_PCR_MUX(1);
46+
LED_R_PORT->PCR[LED_R_PIN] = PORT_PCR_MUX(1);
47+
LED_B_GPIO->PDDR |= (1 << LED_B_PIN);
48+
LED_G_GPIO->PDDR |= (1 << LED_G_PIN);
49+
LED_R_GPIO->PDDR |= (1 << LED_R_PIN);
50+
/* turn all LEDs off */
51+
LED_B_GPIO->PSOR |= (1 << LED_B_PIN);
52+
LED_G_GPIO->PSOR |= (1 << LED_G_PIN);
53+
LED_R_GPIO->PSOR |= (1 << LED_R_PIN);
54+
}

boards/pba-d-01-kw2x/dist/debug.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Based on iot-lab_M3 debug.sh script.
4+
# Author: Jonas Remmert [email protected]
5+
6+
echo PBA-D-01 Debug script executed
7+
8+
openocd -f"../../boards/pba-d-01-kw2x/dist/mkw22d512.cfg" \ #"${RIOTBOARD}/${BOARD}/dist/mkw22d512.cfg" \
9+
-c "tcl_port 6333" \
10+
-c "telnet_port 4444" \
11+
-c "init" \
12+
-c "targets" \
13+
-c "reset halt" \
14+
-l /dev/null &
15+
16+
# save pid to terminate afterwards
17+
OCD_PID=$?
18+
19+
# needed for openocd to set up
20+
sleep 1
21+
22+
retval=$(arm-none-eabi-readelf -x .fcfield $2 | awk '/0x00000400/ {print $2 $3 $4 $5}')
23+
unlocked_fcfield="fffffffffffffffffffffffffeffffff"
24+
25+
if [ "$retval" == "$unlocked_fcfield" ]; then
26+
echo "Flash configuration tested... [OK]"
27+
arm-none-eabi-gdb -tui --command=${1} ${2}
28+
#cgdb -d arm-none-eabi-gdb --command=${1} ${2}
29+
30+
else
31+
echo "Hexdump, .fcfield of $2"
32+
retval=$(arm-none-eabi-readelf -x .fcfield $2)
33+
echo $retval
34+
echo "Fcfield not fitting to MKW22Dxxx, danger of bricking the device during flash...[abort]"
35+
fi
36+
kill ${OCD_PID}

boards/pba-d-01-kw2x/dist/flash.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
# Based on iot-lab_M3 debug.sh script.
4+
# Author: Jonas Remmert [email protected]
5+
6+
elffile=`echo $1 | sed 's/.hex/.elf/'`
7+
8+
echo The file: $elffile will be flashed to the board: $BOARD .
9+
echo Press y to proceed, v to proceed with verify or any other key to abort.
10+
read x
11+
12+
retval=$(arm-none-eabi-readelf -x .fcfield $elffile | awk '/0x00000400/ {print $2 $3 $4 $5}')
13+
unlocked_fcfield="fffffffffffffffffffffffffeffffff"
14+
15+
if [ "$retval" != "$unlocked_fcfield" ]; then
16+
echo "Hexdump, .fcfield of $elffile"
17+
retval=$(arm-none-eabi-readelf -x .fcfield $elffile)
18+
echo $retval
19+
echo "Fcfield not fitting to MKW22Dxxx, danger of bricking the device during flash...[abort]"
20+
exit 0
21+
fi
22+
echo "Flash configuration tested... [OK]"
23+
24+
25+
# flash without verify
26+
if [ $x = "y" ] || [ $x = "v" ];# -o $x -eq v ];
27+
then
28+
echo "Flashing device, do not disconnect or reset the target until this script exits!!!"
29+
openocd -f "../../boards/pba-d-01-kw2x/dist/mkw22d512.cfg" \
30+
-c "init" \
31+
-c "reset halt" \
32+
-c "flash write_image erase $elffile" \
33+
-c "reset run" \
34+
-c "exit"
35+
fi
36+
37+
# verify
38+
if [ "$x" = "v" ];
39+
then
40+
echo "Flashing device in 1s, do not disconnect or reset the target until this script exits!!!"
41+
openocd -f "../../boards/pba-d-01-kw2x/dist/mkw22d512.cfg" \
42+
-c "init" \
43+
-c "reset halt" \
44+
-c "verify_image $elffile" \
45+
-c "reset run" \
46+
-c "exit"
47+
fi
48+
echo done...

boards/pba-d-01-kw2x/dist/gdb.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target remote localhost:3333
2+
monitor reset halt
3+
set print pretty
4+
set arm force-mode thumb
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#
2+
# Freescale Kinetis kw2xdxxx devices
3+
#
4+
source [find interface/cmsis-dap.cfg]
5+
6+
#
7+
# K21 devices support both JTAG and SWD transports.
8+
#
9+
source [find target/swj-dp.tcl]
10+
11+
if { [info exists CHIPNAME] } {
12+
set _CHIPNAME $CHIPNAME
13+
} else {
14+
set _CHIPNAME kw22d512
15+
}
16+
17+
# Work-area is a space in RAM used for flash programming
18+
set WORKAREASIZE 0x4000
19+
20+
if { [info exists WORKAREASIZE] } {
21+
set _WORKAREASIZE $WORKAREASIZE
22+
} else {
23+
set _WORKAREASIZE 0x1000
24+
}
25+
26+
if { [info exists ENDIAN] } {
27+
set _ENDIAN $ENDIAN
28+
} else {
29+
set _ENDIAN little
30+
}
31+
32+
if { [info exists CPUTAPID] } {
33+
set _CPUTAPID $CPUTAPID
34+
} else {
35+
set _CPUTAPID 0x2ba01477
36+
}
37+
38+
set _TARGETNAME $_CHIPNAME.cpu
39+
40+
swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
41+
#swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
42+
43+
target create $_TARGETNAME cortex_m -chain-position $_CHIPNAME.cpu
44+
45+
$_CHIPNAME.cpu configure -event examine-start { puts "START..." ; }
46+
47+
# It is important that "kinetis mdm check_security" is called for
48+
# 'examine-end' event and not 'eximine-start'. Calling it in 'examine-start'
49+
# causes "kinetis mdm check_security" to fail the first time openocd
50+
# calls it when it tries to connect after the CPU has been power-cycled.
51+
$_CHIPNAME.cpu configure -event examine-end {
52+
kinetis mdm check_security
53+
}
54+
55+
$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
56+
57+
set _FLASHNAME $_CHIPNAME.flash
58+
flash bank $_FLASHNAME kinetis 0 0 0 0 $_TARGETNAME
59+
60+
#reset_config srst_only srst_nogate connect_assert_srst
61+
adapter_khz 1000
62+
63+
if {![using_hla]} {
64+
# if srst is not fitted use SYSRESETREQ to
65+
# perform a soft reset
66+
cortex_m reset_config sysresetreq
67+
}
68+
69+
$_TARGETNAME configure -event reset-init {
70+
adapter_khz 24000
71+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
1;
2+
# not a function file:
3+
4+
F = [2405:5:2480];
5+
i = 1;
6+
PLL_INT0 = [];
7+
PLL_FRAC0 = [];
8+
tmp_frac = 0;
9+
tmp_int = 11;
10+
11+
while (i <= length(F))
12+
tmp_frac = (F(i)./32 - tmp_int - 64).*65536;
13+
if tmp_frac >= 65536
14+
tmp_int++;
15+
else
16+
PLL_FRAC0 = [PLL_FRAC0 tmp_frac];
17+
PLL_INT0 = [PLL_INT0 tmp_int];
18+
i++;
19+
endif
20+
endwhile
21+
22+
%F
23+
%Fcalc = ((PLL_INT0 + 64) + (PLL_FRAC0./65536)).*32
24+
%PLL_INT0
25+
%PLL_FRAC0
26+
27+
printf("static const uint8_t pll_int_lt[%d] = {\n", length(F));
28+
for i = 1:4:length(F)
29+
printf(" ");
30+
printf("%d,", PLL_INT0(i:1:i+3));
31+
printf("\n");
32+
endfor
33+
printf("};\n");
34+
printf("\n");
35+
printf("static const uint16_t pll_frac_lt[%d] = {\n", length(F));
36+
for i = 1:4:length(F)
37+
printf(" ");
38+
printf("%d,", PLL_FRAC0(i:1:i+3));
39+
printf("\n");
40+
endfor
41+
printf("};\n\n");
42+
43+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44+
45+
POWER_MAX=8;
46+
POWER_MIN=-35;
47+
RANGE_MAX=31;
48+
RANGE_MIN=3;
49+
50+
i = [0:1:abs(diff([POWER_MAX POWER_MIN]))];
51+
pow_lt = round(i .* (RANGE_MAX - RANGE_MIN) ./ length(i) + RANGE_MIN);
52+
53+
printf("static const uint8_t pow_lt[%d] = {", length(pow_lt));
54+
printf(" ");
55+
for i = 0:1:length(pow_lt)-1
56+
if (rem(i,4) == 0)
57+
printf("\n ");
58+
endif
59+
printf("%d,", pow_lt(i+1));
60+
endfor
61+
printf("\n};\n\n");
62+
63+
i = [0:1:abs(diff([RANGE_MAX RANGE_MIN]))];
64+
level_lt = round(i .* (POWER_MAX - POWER_MIN) ./ length(i) + POWER_MIN);
65+
length(level_lt)
66+
67+
printf("static const int level_lt[%d] = {", length(level_lt));
68+
for i = 0:1:length(level_lt)-1
69+
if (rem(i,4) == 0)
70+
printf("\n ");
71+
endif
72+
printf("%d,", level_lt(i+1));
73+
endfor
74+
printf("\n};\n\n");

boards/pba-d-01-kw2x/dist/reset.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
openocd -f "../../boards/pba-d-01-kw2x/dist/mkw22d512.cfg" \
4+
-c "init" \
5+
-c "reset run" \
6+
-c "shutdown"

0 commit comments

Comments
 (0)