diff --git a/.gitignore b/.gitignore index fc4d337..c8e4d13 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -build/* +**/build/* .vscode/* diff --git a/CMSIS/CMakeLists.txt b/CMSIS/CMakeLists.txt index 60c7fa8..65df136 100644 --- a/CMSIS/CMakeLists.txt +++ b/CMSIS/CMakeLists.txt @@ -10,4 +10,3 @@ target_include_directories(cmsis INTERFACE ${CMSIS_PATH}/Core/Include ${CMSIS_PATH}/Device/${CMSIS_VENDOR}/${CMSIS_DEVICE}/Include ) -target_link_libraries(cmsis INTERFACE driver) \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 171daf6..04c3cca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,47 +1,18 @@ -cmake_minimum_required(VERSION 3.10) -set(PROJ_NAME "app") -set(BIN_FILE ${PROJ_NAME}.bin) -set(ASM_FILE ${PROJ_NAME}.asm) -project(${PROJ_NAME} VERSION 0.1) - -# toolchain path -set(TOOLCHAIN "arm-none-eabi-") -set(CMAKE_C_COMPILER "${TOOLCHAIN}gcc") -set(CMAKE_ASM_COMPILER "${TOOLCHAIN}gcc") -set(CMAKE_OBJCOPY "${TOOLCHAIN}objcopy") -set(CMAKE_OBJDUMP "${TOOLCHAIN}objdump") -set(CMAKE_AR "${TOOLCHAIN}ar") -set(CMAKE_RANLIB "${TOOLCHAIN}ranlib") -set(LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/ram.ld") - -set(BASE_DIR ${CMAKE_CURRENT_LIST_DIR}) - -set(MCU_FLAGS "-mcpu=cortex-m0plus -mthumb -g -O2 -Wall -nostartfiles -ffunction-sections -fdata-sections") -set(CMAKE_C_FLAGS "${MCU_FLAGS}") -set(CMAKE_ASM_FLAGS "${MCU_FLAGS}") -set(CMAKE_EXE_LINKER_FLAGS "${MCU_FLAGS} -T${LINKER_SCRIPT} -Wl,-Map=app.map") - enable_language(ASM) -add_executable(${PROJ_NAME}.elf main.c) -target_sources(${PROJ_NAME}.elf PUBLIC start.S) -add_subdirectory(${BASE_DIR}/driver driver) -target_link_libraries(${PROJ_NAME}.elf driver) +add_library(sdk STATIC) -add_subdirectory(${BASE_DIR}/component component) -target_link_libraries(${PROJ_NAME}.elf component) +add_subdirectory(${SDK_BASE_DIR}/driver driver) +target_link_libraries(sdk driver) -add_subdirectory(${BASE_DIR}/CMSIS) -target_link_libraries(${PROJ_NAME}.elf cmsis) +add_subdirectory(${SDK_BASE_DIR}/component component) +target_link_libraries(sdk component) -add_subdirectory(${BASE_DIR}/core0) -target_link_libraries(${PROJ_NAME}.elf core0) +add_subdirectory(${SDK_BASE_DIR}/CMSIS) +target_link_libraries(sdk cmsis) -add_subdirectory(${BASE_DIR}/core1) -target_link_libraries(${PROJ_NAME}.elf core1) - -add_custom_command(TARGET ${PROJ_NAME}.elf POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -Obinary $ ${BIN_FILE} - COMMAND ${CMAKE_OBJDUMP} -d -S $ >${ASM_FILE} - COMMENT "Generate ${BIN_FILE}\r\n" -) +# add_custom_command(TARGET ${PROJ_NAME}.elf POST_BUILD +# COMMAND ${CMAKE_OBJCOPY} -Obinary $ ${PROJ_NAME}.bin +# COMMAND ${CMAKE_OBJDUMP} -d -S $ >${PROJ_NAME}.asm +# COMMENT "Generate ${BIN_FILE}\r\n" +# ) diff --git a/component/eth/CMakeLists.txt b/component/eth/CMakeLists.txt index 66ac72f..9f31bf0 100644 --- a/component/eth/CMakeLists.txt +++ b/component/eth/CMakeLists.txt @@ -6,5 +6,3 @@ set(TARGET eth) add_library(${TARGET} STATIC ${FILELIST}) target_include_directories(${TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -# target_include_directories(${TARGET} PUBLIC ${BASE_DIR}/driver/inc) -# target_include_directories(${TARGET} PUBLIC ${BASE_DIR}/driver/inc/reg) diff --git a/component/pio_instance/CMakeLists.txt b/component/pio_instance/CMakeLists.txt index 5a30806..0412fee 100644 --- a/component/pio_instance/CMakeLists.txt +++ b/component/pio_instance/CMakeLists.txt @@ -6,5 +6,5 @@ set(TARGET pio_instance) add_library(${TARGET} STATIC ${FILELIST}) target_include_directories(${TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc) -target_include_directories(${TARGET} PUBLIC ${BASE_DIR}/driver/inc) -target_include_directories(${TARGET} PUBLIC ${BASE_DIR}/driver/inc/reg) +target_include_directories(${TARGET} PUBLIC ${SDK_BASE_DIR}/driver/inc) +target_include_directories(${TARGET} PUBLIC ${SDK_BASE_DIR}/driver/inc/reg) diff --git a/component/printf/CMakeLists.txt b/component/printf/CMakeLists.txt index 875540e..373b9aa 100644 --- a/component/printf/CMakeLists.txt +++ b/component/printf/CMakeLists.txt @@ -6,5 +6,5 @@ vsnprintf.c set(TARGET printf) add_library(${TARGET} STATIC ${FILELIST}) -target_include_directories(${TARGET} PUBLIC ${BASE_DIR}/driver/inc) -target_include_directories(${TARGET} PUBLIC ${BASE_DIR}/driver/inc/reg) +target_include_directories(${TARGET} PUBLIC ${SDK_BASE_DIR}/driver/inc) +target_include_directories(${TARGET} PUBLIC ${SDK_BASE_DIR}/driver/inc/reg) diff --git a/driver/CMakeLists.txt b/driver/CMakeLists.txt index 6cb8c13..2849181 100644 --- a/driver/CMakeLists.txt +++ b/driver/CMakeLists.txt @@ -1,4 +1,5 @@ file(GLOB FILELIST +start.S src/common.c src/system.c src/reset.c @@ -16,5 +17,5 @@ add_library(${TARGET} STATIC ${FILELIST}) target_include_directories(${TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc) target_include_directories(${TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc/reg) -target_include_directories(${TARGET} PUBLIC ${BASE_DIR}/CMSIS/Core/Include/) -target_include_directories(${TARGET} PUBLIC ${BASE_DIR}/CMSIS/Device/RaspberryPi/RP2040/Include) +target_include_directories(${TARGET} PUBLIC ${SDK_BASE_DIR}/CMSIS/Core/Include/) +target_include_directories(${TARGET} PUBLIC ${SDK_BASE_DIR}/CMSIS/Device/RaspberryPi/RP2040/Include) diff --git a/start.S b/driver/start.S similarity index 100% rename from start.S rename to driver/start.S diff --git a/example/peripherals/gpio/gpio_led/CMakeLists.txt b/example/peripherals/gpio/gpio_led/CMakeLists.txt new file mode 100644 index 0000000..fd4ff0f --- /dev/null +++ b/example/peripherals/gpio/gpio_led/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.10) + +include(proj.conf) + +set(PROJ_NAME "gpio_led") +project(${PROJ_NAME} VERSION 0.1) +add_executable(${PROJ_NAME}.elf main.c) + +add_subdirectory(${SDK_BASE_DIR} sdk) +target_link_libraries(${PROJ_NAME}.elf sdk) diff --git a/example/peripherals/gpio/gpio_led/Makefile b/example/peripherals/gpio/gpio_led/Makefile new file mode 100644 index 0000000..4cb9131 --- /dev/null +++ b/example/peripherals/gpio/gpio_led/Makefile @@ -0,0 +1,13 @@ +SDK_BASE_DIR ?= $(shell realpath ./../../../..) +export SDK_BASE_DIR + +GCC_PATH := $(shell which arm-none-eabi-gcc) +CROSS_COMPILE := $(patsubst %gcc,%,$(GCC_PATH)) +ifeq ($(GCC_PATH),) +$(error arm-none-eabi-gcc not found in PATH. Please install the ARM toolchain.) +endif + +# add custom cmake definition +#cmake_definition+=-Dxxx=sss + +include $(SDK_BASE_DIR)/project.build diff --git a/example/peripherals/gpio/gpio_led/main.c b/example/peripherals/gpio/gpio_led/main.c new file mode 100644 index 0000000..ecc492c --- /dev/null +++ b/example/peripherals/gpio/gpio_led/main.c @@ -0,0 +1,71 @@ +#include "system.h" +#include "reset.h" +#include "clock.h" +#include "sio.h" +#include "gpio.h" +#include "uart.h" +#include "stdio.h" +#include "cmsis_gcc.h" + +struct gpio_cfg_s gpio_led_cfg = { + .pin = 25, + .sio_dir = GPIO_SIO_DIR_OUT, + .funcsel = GPIO_FUNC_SIO, + .over_out = GPIO_OVER_OUT_PERIPHERAL, + .over_oe = GPIO_OVER_OE_PERIPHERAL, + .over_in = GPIO_OVER_IN_PERIPHERAL, + .over_irq = GPIO_OVER_IRQ_NORMAL, + .slew_rate = GPIO_PADS_SLEW_RATE_SLOW, /* slew rate control, slow or fast */ + .schmitt = ENABLE, /* enable or disable schmitt */ + .pull_down = DISABLE, /* enable or disable pull down */ + .pull_up = DISABLE, /* enable or disable pull up */ + .drive = GPIO_PADS_DRIVE_STRENGTH_4MA, /* drive strength */ + .ie = DISABLE, /* enable or disable input */ + .od = DISABLE, /* output disable, has priority over output enable from peripherals */ +}; + +struct uart_cfg_s uart_cfg = { + .baudrate = 6 * 1000 * 1000, + .mode = UART_MODE_TX_RX, + .data_bits = UART_DATABITS_8, + .parity = UART_PARITY_NONE, + .stop_bits = UART_STOPBITS_1, + .fifo_enable = ENABLE, + .tx_fifo_level = UART_FIFO_LEVEL_1_2, + .rx_fifo_level = UART_FIFO_LEVEL_1_2, +}; + +extern volatile uint32_t tick_1ms; + +void isr_uart0(void) +{ + uint32_t status = uart_int_get_mask_status(UART_ID_0); + printf("sts = 0x%08lX\t\n", status); +} + +int main(void) +{ + reset_enable(RESET_IO_BANK0 | RESET_PADS_BANK0 | RESET_UART0); + reset_disable(RESET_IO_BANK0 | RESET_PADS_BANK0 | RESET_UART0); + gpio_init(&gpio_led_cfg); + gpio_init_simple(0, GPIO_FUNC_UART, DISABLE, ENABLE); + + __enable_irq(); + + while (!reset_get_state(RESET_UART0)); + uart_init(UART_ID_0, &uart_cfg); + uart_int_enable(UART_ID_0, UART_INT_ALL); + // NVIC_EnableIRQ(UART0_IRQ_IRQn); + + while (1) { + static uint32_t tick_led = 0; + + if (tick_1ms > (tick_led + 500)) { + tick_led = tick_1ms; + gpio_toggle(gpio_led_cfg.pin); + printf("tick_led = %ld\r\n", tick_led); + } + } + + return 0; +} diff --git a/example/peripherals/gpio/gpio_led/proj.conf b/example/peripherals/gpio/gpio_led/proj.conf new file mode 100644 index 0000000..7d2ef31 --- /dev/null +++ b/example/peripherals/gpio/gpio_led/proj.conf @@ -0,0 +1 @@ +# set(CONFIG_COMPONENT1 1) diff --git a/project.build b/project.build new file mode 100644 index 0000000..d4d9b00 --- /dev/null +++ b/project.build @@ -0,0 +1,41 @@ +ifndef VERBOSE +MAKEFLAGS += --no-print-directory +endif + +CFLAGS := -mcpu=cortex-m0plus -mthumb -g3 -O2 -Wall -ffunction-sections -fdata-sections + +LDFLAGS := -mcpu=cortex-m0plus -mthumb -g3 -O2 -Wall -ffunction-sections -fdata-sections -nostartfiles -T$(SDK_BASE_DIR)/ram.ld -Wl,-Map=app.map + +CMAKE := cmake + +# The command to remove a file. +RM = $(CMAKE) -E remove_directory + +COMX ?=COM1 +BAUDRATE ?=2000000 + +# cmake definition config +# toolchain +cmake_definition+= -DCMAKE_C_COMPILER=$(CROSS_COMPILE)gcc +cmake_definition+= -DCMAKE_CXX_COMPILER=$(CROSS_COMPILE)g++ +cmake_definition+= -DCMAKE_ASM_COMPILER=$(CROSS_COMPILE)gcc +cmake_definition+= -DCMAKE_LINKER=$(CROSS_COMPILE)ld +cmake_definition+= -DCMAKE_OBJCOPY=$(CROSS_COMPILE)objcopy +cmake_definition+= -DCMAKE_OBJDUMP=$(CROSS_COMPILE)objdump +cmake_definition+= -DCMAKE_AR=$(CROSS_COMPILE)ar +cmake_definition+= -DCMAKE_RANLIB=$(CROSS_COMPILE)ranlib +cmake_definition+= -DCMAKE_C_FLAGS="$(CFLAGS)" +cmake_definition+= -DCMAKE_CXX_FLAGS="$(CFLAGS)" +cmake_definition+= -DCMAKE_EXE_LINKER_FLAGS="$(LDFLAGS)" + +cmake_definition+= -DCONFIG_COMX=$(COMX) +cmake_definition+= -DSDK_BASE_DIR=$(SDK_BASE_DIR) + +build:Makefile + $(CMAKE) -S . -B build -G "Unix Makefiles" $(cmake_definition) + $(MAKE) -C build -j + +clean:: + $(RM) build + +.PHONY:build clean