Initial project setup

This commit is contained in:
2025-12-13 11:59:11 +02:00
commit 3218e6039f
2176 changed files with 355321 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
# 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)
- [Widora Tiny200 v2 (also called MangoPi-R3c)](https://mangopi.org/tiny200)
## Flashing
There are two options to put your code into the MCU: `flash` and `exec`. Both modes require you to install [xfel](https://github.com/xboot/xfel) tool to your PATH. You must enter FEL mode before any operation can be done. To enter FEL mode, press BOOT button, then press RESET once, and release BOOT button. You will find VID/PID=1f3a:efe8 on your PC.
Exec: `make BOARD=f1c100s exec` will just upload the image to the DDR ram and execute it. It will not touch anything in the SPI flash.
Flash: `make BOARD=f1c100s flash` will write the image to SPI flash, and then reset the chip to execute it.
## TODO
* Add F1C100s to `#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT1XXX` high speed MCU check in examples (maybe we should extract the logic?)

View File

@@ -0,0 +1,3 @@
function(update_board TARGET)
# nothing to do
endfunction()

View File

@@ -0,0 +1,11 @@
/* metadata:
name: Lctech Pi F1C200s
url: https://linux-sunxi.org/Lctech_Pi_F1C200s
*/
#ifndef BOARD_H
#define BOARD_H
// Nothing valuable here
#endif

View File

@@ -0,0 +1 @@
# nothing to do

View File

@@ -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.
*/
/* metadata:
manufacturer: Sunxi
*/
#include <stdint.h>
#include <malloc.h>
#include <irqflags.h>
#include <f1c100s-irq.h>
#include "bsp/board_api.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
void board_led_write(bool state) {
(void) state;
}
uint32_t board_button_read(void) {
return 0;
}
int board_uart_read(uint8_t* buf, int len) {
(void) buf;
(void) 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

View File

@@ -0,0 +1,114 @@
include_guard()
set(SDK_DIR ${TOP}/hw/mcu/allwinner/f1c100s)
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
# toolchain set up
set(CMAKE_SYSTEM_CPU arm926ej-s CACHE INTERNAL "System Processor")
set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
set(FAMILY_MCUS F1C100S CACHE INTERNAL "")
#------------------------------------
# BOARD_TARGET
#------------------------------------
# only need to be built ONCE for all examples
function(add_board_target BOARD_TARGET)
if (TARGET ${BOARD_TARGET})
return()
endif ()
# LD_FILE and STARTUP_FILE can be defined in board.cmake
if (NOT DEFINED LD_FILE_GNU)
set(LD_FILE_GNU ${SDK_DIR}/f1c100s.ld)
endif ()
set(LD_FILE_Clang ${LD_FILE_GNU})
if (NOT DEFINED STARTUP_FILE_GNU)
set(STARTUP_FILE_GNU ${SDK_DIR}/machine/start.S)
endif ()
set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})
add_library(${BOARD_TARGET} STATIC
${SDK_DIR}/lib/malloc.c
${SDK_DIR}/lib/printf.c
${SDK_DIR}/lib/memcpy.S
${SDK_DIR}/lib/memset.S
${SDK_DIR}/machine/sys-uart.c
${SDK_DIR}/machine/exception.c
${SDK_DIR}/machine/sys-clock.c
${SDK_DIR}/machine/sys-copyself.c
${SDK_DIR}/machine/sys-dram.c
${SDK_DIR}/machine/sys-mmu.c
${SDK_DIR}/machine/sys-spi-flash.c
${SDK_DIR}/machine/f1c100s-intc.c
${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
)
target_compile_definitions(${BOARD_TARGET} PUBLIC
__ARM32_ARCH__=5
)
target_include_directories(${BOARD_TARGET} PUBLIC
${SDK_DIR}/include
)
update_board(${BOARD_TARGET})
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_link_options(${BOARD_TARGET} PUBLIC
"LINKER:--script=${LD_FILE_GNU}"
-lgcc
--specs=nosys.specs --specs=nano.specs
"LINKER:--defsym=__bss_end__=__bss_end"
"LINKER:--defsym=__bss_start__=__bss_start"
"LINKER:--defsym=end=__bss_end"
)
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
target_link_options(${BOARD_TARGET} PUBLIC
"LINKER:--script=${LD_FILE_GNU}"
)
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
target_link_options(${BOARD_TARGET} PUBLIC
"LINKER:--config=${LD_FILE_IAR}"
)
endif ()
endfunction()
#------------------------------------
# Functions
#------------------------------------
function(family_configure_example TARGET RTOS)
family_configure_common(${TARGET} ${RTOS})
# Board target
add_board_target(board_${BOARD})
#---------- Port Specific ----------
# These files are built for each example since it depends on example's tusb_config.h
target_sources(${TARGET} PUBLIC
# BSP
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
)
target_include_directories(${TARGET} PUBLIC
# family, hw, board
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
)
# Add TinyUSB target and port source
family_add_tinyusb(${TARGET} OPT_MCU_F1C100S)
target_sources(${TARGET} PRIVATE
${TOP}/src/portable/sunxi/dcd_sunxi_musb.c
)
target_link_libraries(${TARGET} PUBLIC board_${BOARD})
# Flashing
family_add_bin_hex(${TARGET})
family_flash_jlink(${TARGET})
endfunction()

View File

@@ -0,0 +1,58 @@
SDK_DIR = hw/mcu/allwinner/f1c100s
include $(TOP)/$(BOARD_PATH)/board.mk
CPU_CORE ?= arm926ej-s
#CFLAGS += \
# -march=armv5te \
# -mtune=arm926ej-s \
# -mfloat-abi=soft \
# -marm \
CFLAGS += \
-ffreestanding \
-std=gnu99 \
-mno-thumb-interwork \
-D__ARM32_ARCH__=5 \
-D__ARM926EJS__ \
-Wno-float-equal \
-Wno-unused-parameter \
-DCFG_TUSB_MCU=OPT_MCU_F1C100S \
-Wno-error=array-bounds \
LD_FILE = ${SDK_DIR}/f1c100s.ld
# TODO may skip nanolib
LDFLAGS += \
-nostdlib -lgcc \
--specs=nosys.specs --specs=nano.specs \
SRC_C += \
src/portable/sunxi/dcd_sunxi_musb.c \
${SDK_DIR}/machine/sys-uart.c \
${SDK_DIR}/machine/exception.c \
${SDK_DIR}/machine/sys-clock.c \
${SDK_DIR}/machine/sys-copyself.c \
${SDK_DIR}/machine/sys-dram.c \
${SDK_DIR}/machine/sys-mmu.c \
${SDK_DIR}/machine/sys-spi-flash.c \
${SDK_DIR}/machine/f1c100s-intc.c \
${SDK_DIR}/lib/malloc.c \
${SDK_DIR}/lib/printf.c
SRC_S += \
${SDK_DIR}/machine/start.S \
${SDK_DIR}/lib/memcpy.S \
${SDK_DIR}/lib/memset.S
INC += \
$(TOP)/${SDK_DIR}/include \
$(TOP)/$(BOARD_PATH)
# flash target using xfel
flash: flash-xfel
exec: $(BUILD)/$(PROJECT).bin
xfel ddr
xfel write 0x80000000 $<
xfel exec 0x80000000