add cmake for f1c100s

This commit is contained in:
hathach 2024-05-04 12:36:40 +07:00
parent 666702f478
commit c020a0190d
No known key found for this signature in database
GPG Key ID: 26FAB84F615C3C52
12 changed files with 243 additions and 84 deletions

View File

@ -1,6 +1,7 @@
if (TOOLCHAIN STREQUAL "gcc")
set(TOOLCHAIN_COMMON_FLAGS
-mcpu=arm1176jzf-s
-ffreestanding
)
# set(FREERTOS_PORT GCC_ARM_CM0 CACHE INTERNAL "")
@ -10,6 +11,7 @@ elseif (TOOLCHAIN STREQUAL "clang")
-mcpu=arm1176jzf-s
-mfpu=none
-mfloat-abi=soft
-ffreestanding
)
#set(FREERTOS_PORT GCC_ARM_CM0 CACHE INTERNAL "")

View File

@ -0,0 +1,21 @@
if (TOOLCHAIN STREQUAL "gcc")
set(TOOLCHAIN_COMMON_FLAGS
-mcpu=arm926ej-s
-ffreestanding
)
# set(FREERTOS_PORT GCC_ARM_CM0 CACHE INTERNAL "")
elseif (TOOLCHAIN STREQUAL "clang")
set(TOOLCHAIN_COMMON_FLAGS
--target=arm-none-eabi
-mcpu=arm926ej-s
-mfpu=none
-mfloat-abi=soft
-ffreestanding
)
#set(FREERTOS_PORT GCC_ARM_CM0 CACHE INTERNAL "")
elseif (TOOLCHAIN STREQUAL "iar")
message(FATAL_ERROR "IAR not supported")
endif ()

View File

@ -0,0 +1,9 @@
ifeq ($(TOOLCHAIN),gcc)
CFLAGS += \
-mcpu=arm926ej-s \
else ifeq ($(TOOLCHAIN),iar)
#CFLAGS += --cpu cortex-a53
#ASFLAGS += --cpu cortex-a53
endif

View File

@ -1 +0,0 @@
// Nothing valuable here

View File

@ -1,52 +0,0 @@
MCU_DIR = hw/mcu/allwinner/f1c100s
DEPS_SUBMODULES += hw/mcu/allwinner
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
# TODO may skip nanolib
LDFLAGS += -nostdlib -lgcc -specs=nosys.specs -specs=nano.specs
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 xfel
flash: flash-xfel
exec: $(BUILD)/$(PROJECT).bin
xfel ddr
xfel write 0x80000000 $<
xfel exec 0x80000000

View File

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

View File

@ -0,0 +1,6 @@
#ifndef BOARD_H
#define BOARD_H
// Nothing valuable here
#endif

View File

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

View File

@ -39,10 +39,9 @@ extern void sys_uart_putc(char c);
static void timer_init(void);
void board_init(void)
{
void board_init(void) {
arch_local_irq_disable();
do_init_mem_pool();
do_init_mem_pool();
f1c100s_intc_init();
timer_init();
printf("Timer INIT done\n");
@ -50,42 +49,38 @@ void board_init(void)
}
// No LED, no button
void board_led_write(bool state)
{
void board_led_write(bool state) {
(void) state;
}
uint32_t board_button_read(void)
{
uint32_t board_button_read(void) {
return 0;
}
int board_uart_read(uint8_t* buf, int len)
{
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 board_uart_write(void const* buf, int len) {
int txsize = len;
while (txsize--) {
sys_uart_putc(*(uint8_t const*)buf);
sys_uart_putc(*(uint8_t const*) buf);
buf++;
}
return len;
}
#if CFG_TUSB_OS == OPT_OS_NONE
#if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0;
uint32_t board_millis(void)
{
uint32_t board_millis(void) {
return system_ticks;
}
static void timer_handler(void)
{
volatile uint32_t *temp_addr = (uint32_t *)(0x01C20C00 + 0x04);
static void timer_handler(void) {
volatile uint32_t* temp_addr = (uint32_t*) (0x01C20C00 + 0x04);
/* clear timer */
*temp_addr |= 0x01;
@ -95,36 +90,37 @@ static void timer_handler(void)
static void timer_init(void) {
uint32_t temp;
volatile uint32_t *temp_addr;
volatile uint32_t* temp_addr;
/* reload value */
temp = 12000000 / 1000;
temp_addr = (uint32_t *)(0x01C20C00 + 0x14);
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 = (uint32_t*) (0x01C20C00 + 0x10);
*temp_addr &= 0xffffff00;
*temp_addr |= temp;
/* open timer irq */
temp = 0x01 << 0;
temp_addr = (uint32_t *)(0x01C20C00);
temp_addr = (uint32_t*) (0x01C20C00);
*temp_addr |= temp;
/* set init value */
temp_addr = (uint32_t *)(0x01C20C00 + 0x18);
temp_addr = (uint32_t*) (0x01C20C00 + 0x18);
*temp_addr = 0;
/* begin run timer */
temp = 0x01 << 0;
temp_addr = (uint32_t *)(0x01C20C00 + 0x10);
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

114
hw/bsp/f1c100s/family.cmake Normal file
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_PROCESSOR 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 ${RTOS})
target_sources(${TARGET}-tinyusb PRIVATE
${TOP}/src/portable/sunxi/dcd_sunxi_musb.c
)
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
# Link dependencies
target_link_libraries(${TARGET} PUBLIC board_${BOARD} ${TARGET}-tinyusb)
# Flashing
family_flash_jlink(${TARGET})
endfunction()

58
hw/bsp/f1c100s/family.mk Normal file
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

View File

@ -35,7 +35,9 @@
#include <f1c100s-irq.h>
#include <device/dcd.h>
#include "musb_def.h"
#include "bsp/board.h"
//#include "bsp/board_api.h"
extern uint32_t board_millis(void); // TODO remove
typedef uint32_t u32;
typedef uint16_t u16;
@ -58,7 +60,7 @@ typedef struct TU_ATTR_PACKED
typedef struct
{
tusb_control_request_t setup_packet;
CFG_TUD_MEM_ALIGN tusb_control_request_t setup_packet;
uint16_t remaining_ctrl; /* The number of bytes remaining in data stage of control transfer. */
int8_t status_out;
pipe_state_t pipe0;
@ -350,7 +352,7 @@ static void USBC_INT_DisableRxEp(u8 ep_index)
* INTERNAL FUNCTION DECLARATION
*------------------------------------------------------------------*/
static dcd_data_t _dcd;
CFG_TUD_MEM_ALIGN static dcd_data_t _dcd;
static inline free_block_t *find_containing_block(free_block_t *beg, free_block_t *end, uint_fast16_t addr)
{
@ -560,7 +562,7 @@ static void pipe_read_write_packet_ff(tu_fifo_t *f, volatile void *fifo, unsigne
static void process_setup_packet(uint8_t rhport)
{
uint32_t *p = (uint32_t*)&_dcd.setup_packet;
uint32_t *p = (uint32_t*)(uintptr_t) &_dcd.setup_packet;
p[0] = USBC_Readl(USBC_REG_EPFIFO0(USBC0_BASE));
p[1] = USBC_Readl(USBC_REG_EPFIFO0(USBC0_BASE));
@ -594,7 +596,7 @@ static bool handle_xfer_in(uint_fast8_t ep_addr)
if (len) {
volatile void* addr = (volatile void*)(USBC_REG_EPFIFO1(USBC0_BASE) + (epnum_minus1 << 2));
if (_dcd.pipe_buf_is_fifo[TUSB_DIR_IN] & TU_BIT(epnum_minus1)) {
pipe_read_write_packet_ff((tu_fifo_t *)buf, addr, len, TUSB_DIR_IN);
pipe_read_write_packet_ff((tu_fifo_t *)(uintptr_t) buf, addr, len, TUSB_DIR_IN);
} else {
pipe_write_packet(buf, addr, len);
pipe->buf = buf + len;
@ -622,7 +624,7 @@ static bool handle_xfer_out(uint_fast8_t ep_addr)
if (len) {
volatile void* addr = (volatile void*)(USBC_REG_EPFIFO1(USBC0_BASE) + (epnum_minus1 << 2));
if (_dcd.pipe_buf_is_fifo[TUSB_DIR_OUT] & TU_BIT(epnum_minus1)) {
pipe_read_write_packet_ff((tu_fifo_t *)buf, addr, len, TUSB_DIR_OUT);
pipe_read_write_packet_ff((tu_fifo_t *)(uintptr_t )buf, addr, len, TUSB_DIR_OUT);
} else {
pipe_read_packet(buf, addr, len);
pipe->buf = buf + len;