summaryrefslogtreecommitdiff
path: root/hw/bsp
diff options
context:
space:
mode:
authorYunhao Tian <[email protected]>2021-12-04 18:02:07 +0800
committerYunhao Tian <[email protected]>2021-12-04 18:02:07 +0800
commit68ca62dfd7e7fe757ba436fee7721520119da92b (patch)
tree62089abe09894d0824fa22837b2a86f1b1dfb0c5 /hw/bsp
parentdff54d854ddae3ff5c8dc81bac77fd8b50564598 (diff)
Add BSP support for F1C100s
Diffstat (limited to 'hw/bsp')
-rw-r--r--hw/bsp/f1c100s/README.md17
-rw-r--r--hw/bsp/f1c100s/board.h1
-rw-r--r--hw/bsp/f1c100s/board.mk45
-rw-r--r--hw/bsp/f1c100s/f1c100s.c130
4 files changed, 193 insertions, 0 deletions
diff --git a/hw/bsp/f1c100s/README.md b/hw/bsp/f1c100s/README.md
new file mode 100644
index 000000000..a4865b925
--- /dev/null
+++ b/hw/bsp/f1c100s/README.md
@@ -0,0 +1,17 @@
+# BSP support for F1Cx00s boards
+
+This folder contains necessary file and scripts to run TinyUSB examples on F1Cx00s boards.
+
+Currently tested on:
+
+* Lichee Pi Nano (F1C100s)
+
+## make flash
+`make flash` will use [xfel](https://github.com/xboot/xfel) to write the code to onchip DDR memory and execute it. It will not write the program to SPI Flash.
+
+To enter FEL mode, you have to press BOOT button, then press RESET once, and release BOOT button. You will find VID/PID=1f3a:efe8 on your PC.
+
+## TODO
+* Test on Tiny200 v2 (F1C200s)
+* Make it able to load .bin directly to SPI Flash and boot
+* Add F1C100s to `#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX` high speed MCU check in examples (maybe we should extract the logic?) \ No newline at end of file
diff --git a/hw/bsp/f1c100s/board.h b/hw/bsp/f1c100s/board.h
new file mode 100644
index 000000000..238ac796d
--- /dev/null
+++ b/hw/bsp/f1c100s/board.h
@@ -0,0 +1 @@
+// Nothing valuable here \ No newline at end of file
diff --git a/hw/bsp/f1c100s/board.mk b/hw/bsp/f1c100s/board.mk
new file mode 100644
index 000000000..993aa0d24
--- /dev/null
+++ b/hw/bsp/f1c100s/board.mk
@@ -0,0 +1,45 @@
+DEFINES += -D__ARM32_ARCH__=5 -D__ARM926EJS__
+
+CFLAGS += \
+ -ffreestanding \
+ -std=gnu99 \
+ -march=armv5te \
+ -mtune=arm926ej-s \
+ -mfloat-abi=soft \
+ -marm \
+ -mno-thumb-interwork \
+ -Wno-unused-parameter \
+ -Wno-float-equal \
+ -DCFG_TUSB_MCU=OPT_MCU_F1C100S \
+ -Wno-error=cast-align \
+ -Wno-error=address-of-packed-member \
+ $(DEFINES)
+
+LD_FILE = hw/mcu/allwinner/f1c100s/f1c100s.ld
+LDFLAGS += -nostdlib -lgcc
+MCU_DIR = hw/mcu/allwinner/f1c100s
+
+SRC_C += \
+ src/portable/sunxi/dcd_sunxi_musb.c \
+ $(MCU_DIR)/machine/sys-uart.c \
+ $(MCU_DIR)/machine/exception.c \
+ $(MCU_DIR)/machine/sys-clock.c \
+ $(MCU_DIR)/machine/sys-copyself.c \
+ $(MCU_DIR)/machine/sys-dram.c \
+ $(MCU_DIR)/machine/sys-mmu.c \
+ $(MCU_DIR)/machine/sys-spi-flash.c \
+ $(MCU_DIR)/machine/f1c100s-intc.c \
+ $(MCU_DIR)/lib/malloc.c \
+ $(MCU_DIR)/lib/printf.c
+
+SRC_S += \
+ $(MCU_DIR)/machine/start.S \
+ $(MCU_DIR)/lib/memcpy.S \
+ $(MCU_DIR)/lib/memset.S
+
+INC += \
+ $(TOP)/$(MCU_DIR)/include \
+ $(TOP)/$(BOARD_PATH)
+
+# flash target using on-board stlink
+flash: flash-xfel
diff --git a/hw/bsp/f1c100s/f1c100s.c b/hw/bsp/f1c100s/f1c100s.c
new file mode 100644
index 000000000..6cf18597c
--- /dev/null
+++ b/hw/bsp/f1c100s/f1c100s.c
@@ -0,0 +1,130 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 Ha Thach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * This file is part of the TinyUSB stack.
+ */
+
+#include <stdint.h>
+#include <malloc.h>
+#include <irqflags.h>
+#include <f1c100s-irq.h>
+#include "bsp/board.h"
+#include "board.h"
+
+extern void sys_uart_putc(char c);
+
+//--------------------------------------------------------------------+
+// Board porting API
+//--------------------------------------------------------------------+
+
+static void timer_init(void);
+
+void board_init(void)
+{
+ arch_local_irq_disable();
+ do_init_mem_pool();
+ f1c100s_intc_init();
+ timer_init();
+ printf("Timer INIT done\n");
+ arch_local_irq_enable();
+}
+
+// No LED, no button, sorry
+void board_led_write(bool state)
+{
+
+}
+
+uint32_t board_button_read(void)
+{
+ return 0;
+}
+
+int board_uart_read(uint8_t* buf, int len)
+{
+ return 0;
+}
+
+int board_uart_write(void const * buf, int len)
+{
+ int txsize = len;
+ while (txsize--) {
+ sys_uart_putc(*(uint8_t const*)buf);
+ buf++;
+ }
+ return len;
+}
+
+#if CFG_TUSB_OS == OPT_OS_NONE
+volatile uint32_t system_ticks = 0;
+
+uint32_t board_millis(void)
+{
+ return system_ticks;
+}
+
+static void timer_handler(void)
+{
+ volatile uint32_t *temp_addr = (uint32_t *)(0x01C20C00 + 0x04);
+
+ /* clear timer */
+ *temp_addr |= 0x01;
+
+ system_ticks++;
+}
+
+static void timer_init(void) {
+ uint32_t temp;
+ volatile uint32_t *temp_addr;
+
+ /* reload value */
+ temp = 12000000 / 1000;
+ temp_addr = (uint32_t *)(0x01C20C00 + 0x14);
+ *temp_addr = temp;
+
+ /* continuous | /2 | 24Mhz | reload*/
+ temp = (0x00 << 7) | (0x01 << 4) | (0x01 << 2) | (0x00 << 1);
+ temp_addr = (uint32_t *)(0x01C20C00 + 0x10);
+ *temp_addr &= 0xffffff00;
+ *temp_addr |= temp;
+
+ /* open timer irq */
+ temp = 0x01 << 0;
+ temp_addr = (uint32_t *)(0x01C20C00);
+ *temp_addr |= temp;
+
+ /* set init value */
+ temp_addr = (uint32_t *)(0x01C20C00 + 0x18);
+ *temp_addr = 0;
+
+ /* begin run timer */
+ temp = 0x01 << 0;
+ temp_addr = (uint32_t *)(0x01C20C00 + 0x10);
+ *temp_addr |= temp;
+
+ f1c100s_intc_set_isr(F1C100S_IRQ_TIMER0, timer_handler);
+ f1c100s_intc_enable_irq(F1C100S_IRQ_TIMER0);
+}
+#else
+static void timer_init(void) { }
+#endif