[update] update compile directory first
This commit is contained in:
parent
2b780b6cf7
commit
dc86bbc3cc
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
build/*
|
||||
**/build/*
|
||||
.vscode/*
|
||||
|
||||
@ -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)
|
||||
@ -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 $<TARGET_FILE:${PROJ_NAME}.elf> ${BIN_FILE}
|
||||
COMMAND ${CMAKE_OBJDUMP} -d -S $<TARGET_FILE:${PROJ_NAME}.elf> >${ASM_FILE}
|
||||
COMMENT "Generate ${BIN_FILE}\r\n"
|
||||
)
|
||||
# add_custom_command(TARGET ${PROJ_NAME}.elf POST_BUILD
|
||||
# COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJ_NAME}.elf> ${PROJ_NAME}.bin
|
||||
# COMMAND ${CMAKE_OBJDUMP} -d -S $<TARGET_FILE:${PROJ_NAME}.elf> >${PROJ_NAME}.asm
|
||||
# COMMENT "Generate ${BIN_FILE}\r\n"
|
||||
# )
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
10
example/peripherals/gpio/gpio_led/CMakeLists.txt
Normal file
10
example/peripherals/gpio/gpio_led/CMakeLists.txt
Normal file
@ -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)
|
||||
13
example/peripherals/gpio/gpio_led/Makefile
Normal file
13
example/peripherals/gpio/gpio_led/Makefile
Normal file
@ -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
|
||||
71
example/peripherals/gpio/gpio_led/main.c
Normal file
71
example/peripherals/gpio/gpio_led/main.c
Normal file
@ -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;
|
||||
}
|
||||
1
example/peripherals/gpio/gpio_led/proj.conf
Normal file
1
example/peripherals/gpio/gpio_led/proj.conf
Normal file
@ -0,0 +1 @@
|
||||
# set(CONFIG_COMPONENT1 1)
|
||||
41
project.build
Normal file
41
project.build
Normal file
@ -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
|
||||
Loading…
Reference in New Issue
Block a user