Added sifive-hifive test application with external bsp

pull/5/head
Daniele Lacamera 2019-04-04 16:33:24 +02:00
parent b918014203
commit 97a88ff76c
4 changed files with 190 additions and 27 deletions

View File

@ -12,6 +12,7 @@ KINETIS?=$(HOME)/src/FRDM-K64F
KINETIS_CPU=MK64FN1M0VLL12
KINETIS_DRIVERS?=$(KINETIS)/devices/MK64F12
KINETIS_CMSIS?=$(KINETIS)/CMSIS
FREEDOM_E_SDK?=$(HOME)/src/freedom-e-sdk
DEBUG?=0
VTOR?=1
CORTEX_M0?=0
@ -143,7 +144,8 @@ wolfboot-align.bin: wolfboot.bin
test-app/image.bin:
@make -C test-app TARGET=$(TARGET) EXT_FLASH=$(EXT_FLASH) SPI_FLASH=$(SPI_FLASH) ARCH=$(ARCH) V=$(V) \
KINETIS=$(KINETIS) KINETIS_CPU=$(KINETIS_CPU) KINETIS_DRIVERS=$(KINETIS_DRIVERS) \
KINETIS_CMSIS=$(KINETIS_CMSIS) NVM_FLASH_WRITEONCE=$(NVM_FLASH_WRITEONCE)
KINETIS_CMSIS=$(KINETIS_CMSIS) NVM_FLASH_WRITEONCE=$(NVM_FLASH_WRITEONCE) \
FREEDOM_E_SDK=$(FREEDOM_E_SDK)
@rm -f src/*.o hal/*.o
include tools/test.mk

View File

@ -37,6 +37,35 @@ ifeq ($(TARGET),kinetis)
$(KINETIS_DRIVERS)/drivers/fsl_ftfx_controller.o $(KINETIS_DRIVERS)/drivers/fsl_gpio.o
endif
ifeq ($(TARGET),hifive1)
CFLAGS+=-I$(FREEDOM_E_SDK)/freedom-metal/ -D__METAL_MACHINE_HEADER=\"$(FREEDOM_E_SDK)/bsp/sifive-hifive1/metal.h\"
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/clock.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/led.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/cache.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/cpu.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/gpio.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/interrupt.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/uart.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/tty.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/spi.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/shutdown.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/timer.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/drivers/sifive,fe310-g000,hfrosc.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/drivers/sifive,fe310-g000,hfxosc.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/drivers/sifive,fe310-g000,pll.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/drivers/sifive,fe310-g000,prci.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/drivers/sifive,spi0.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/drivers/sifive,uart0.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/drivers/sifive,global-external-interrupts0.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/drivers/sifive,local-external-interrupts0.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/drivers/sifive,gpio0.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/drivers/sifive,gpio-leds.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/drivers/riscv,clint0.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/drivers/riscv,plic0.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/drivers/riscv,cpu.o
APP_OBJS+=$(FREEDOM_E_SDK)/freedom-metal/src/drivers/fixed-clock.o
endif
standalone:CFLAGS+=-DTEST_APP_STANDALONE
standalone:LDFLAGS:=$(CFLAGS) -T standalone.ld -Wl,-gc-sections -Wl,-Map=image.map

View File

@ -19,6 +19,7 @@ SECTIONS
KEEP(*(.isr_vector))
*(.text*)
*(.rodata*)
*(.srodata*)
. = ALIGN(4);
_end_text = .;
} > FLASH

View File

@ -1,32 +1,163 @@
/* main.c
/*
* # sifive-welcome
* (A simple welcome example which prints SiFive banner and uses board LEDs
*
* Copyright (C) 2018 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
* Copyright 2018 SiFive, Inc
*/
/* SPDX-License-Identifier: Apache-2.0 */
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <metal/cpu.h>
#include <metal/led.h>
#include <metal/button.h>
#include <metal/switch.h>
#define RTC_FREQ 32768
struct metal_cpu *cpu0;
struct metal_interrupt *cpu_intr, *tmr_intr;
int tmr_id;
volatile uint32_t timer_isr_flag;
void display_banner (void) {
printf("\n");
printf("\n");
printf(" SIFIVE, INC.\n");
printf("\n");
printf(" 5555555555555555555555555\n");
printf(" 5555 5555\n");
printf(" 5555 5555\n");
printf(" 5555 5555\n");
printf(" 5555 5555555555555555555555\n");
printf(" 5555 555555555555555555555555\n");
printf(" 5555 5555\n");
printf(" 5555 5555\n");
printf(" 5555 5555\n");
printf(" 5555555555555555555555555555 55555\n");
printf(" 55555 555555555 55555\n");
printf(" 55555 55555 55555\n");
printf(" 55555 5 55555\n");
printf(" 55555 55555\n");
printf(" 55555 55555\n");
printf(" 55555 55555\n");
printf(" 55555 55555\n");
printf(" 55555 55555\n");
printf(" 555555555\n");
printf(" 55555\n");
printf(" 5\n");
printf("\n");
printf("\n");
printf(" Welcome to SiFive!\n");
#ifdef PLATFORM_hifive1
void main(void) {
while(1)
;
}
#endif
void timer_isr (int id, void *data) {
// Disable Timer interrupt
metal_interrupt_disable(tmr_intr, tmr_id);
// Flag showing we hit timer isr
timer_isr_flag = 1;
}
void wait_for_timer(struct metal_led *which_led) {
// clear global timer isr flag
timer_isr_flag = 0;
// Turn on desired LED
metal_led_on(which_led);
// Set timer
metal_cpu_set_mtimecmp(cpu0, metal_cpu_get_mtime(cpu0) + RTC_FREQ);
// Enable Timer interrupt
metal_interrupt_enable(tmr_intr, tmr_id);
// wait till timer triggers and isr is hit
while (timer_isr_flag == 0){};
timer_isr_flag = 0;
// Turn off this LED
metal_led_off(which_led);
}
int main (void)
{
int rc, up_cnt, dn_cnt;
struct metal_led *led0_red, *led0_green, *led0_blue;
// This demo will toggle LEDs colors so we define them here
led0_red = metal_led_get_rgb("LD0", "red");
led0_green = metal_led_get_rgb("LD0", "green");
led0_blue = metal_led_get_rgb("LD0", "blue");
if ((led0_red == NULL) || (led0_green == NULL) || (led0_blue == NULL)) {
printf("At least one of LEDs is null.\n");
return 1;
}
// Enable each LED
metal_led_enable(led0_red);
metal_led_enable(led0_green);
metal_led_enable(led0_blue);
// All Off
metal_led_off(led0_red);
metal_led_off(led0_green);
metal_led_off(led0_blue);
// Lets get the CPU and and its interrupt
cpu0 = metal_cpu_get(0);
if (cpu0 == NULL) {
printf("CPU null.\n");
return 2;
}
cpu_intr = metal_cpu_interrupt_controller(cpu0);
if (cpu_intr == NULL) {
printf("CPU interrupt controller is null.\n");
return 3;
}
metal_interrupt_init(cpu_intr);
// display welcome banner
display_banner();
// Setup Timer and its interrupt so we can toggle LEDs on 1s cadence
tmr_intr = metal_cpu_timer_interrupt_controller(cpu0);
if (tmr_intr == NULL) {
printf("TIMER interrupt controller is null.\n");
return 4;
}
metal_interrupt_init(tmr_intr);
tmr_id = metal_cpu_timer_get_interrupt_id(cpu0);
rc = metal_interrupt_register_handler(tmr_intr, tmr_id, timer_isr, cpu0);
if (rc < 0) {
printf("TIMER interrupt handler registration failed\n");
return (rc * -1);
}
// Lastly CPU interrupt
if (metal_interrupt_enable(cpu_intr, 0) == -1) {
printf("CPU interrupt enable failed\n");
return 6;
}
// Red -> Green -> Blue, repeat
while (1) {
// Turn on RED
wait_for_timer(led0_red);
// Turn on Green
wait_for_timer(led0_green);
// Turn on Blue
wait_for_timer(led0_blue);
}
// return
return 0;
}