Initial setup for PY32F002A
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
build/
|
||||
.cache/
|
||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "py32f0-sdk"]
|
||||
path = py32f0-sdk
|
||||
url = https://github.com/IOsetting/py32f0-template.git
|
||||
74
CMakeLists.txt
Normal file
74
CMakeLists.txt
Normal file
@@ -0,0 +1,74 @@
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
|
||||
project(puya32-playground LANGUAGES C ASM)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_C_EXTENSIONS ON)
|
||||
|
||||
set(HAL_DEFINES
|
||||
PY32F002Ax5
|
||||
)
|
||||
|
||||
set(HAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/py32f0-sdk)
|
||||
|
||||
add_library(py32-hal STATIC)
|
||||
|
||||
target_include_directories(py32-hal PUBLIC
|
||||
${HAL_DIR}/Libraries/CMSIS/Core/Include
|
||||
${HAL_DIR}/Libraries/CMSIS/Device/PY32F0xx/Include
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Inc
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_BSP/Inc
|
||||
)
|
||||
|
||||
target_compile_definitions(py32-hal PUBLIC
|
||||
${HAL_DEFINES}
|
||||
)
|
||||
|
||||
target_sources(py32-hal PRIVATE
|
||||
# LL drivers
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_adc.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_crc.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_exti.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_gpio.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_led.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_pwr.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_rtc.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_tim.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_utils.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_comp.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_dma.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_flash.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_i2c.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_lptim.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_rcc.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_spi.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_usart.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_BSP/Src/py32f0xx_bsp_clock.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_BSP/Src/py32f0xx_bsp_led.c
|
||||
${HAL_DIR}/Libraries/PY32F0xx_LL_BSP/Src/py32f0xx_bsp_printf.c
|
||||
# Startup code
|
||||
${HAL_DIR}/Libraries/CMSIS/Device/PY32F0xx/Source/system_py32f0xx.c
|
||||
${HAL_DIR}/Libraries/CMSIS/Device/PY32F0xx/Source/gcc/startup_py32f002a.s
|
||||
)
|
||||
|
||||
# Set up target executable
|
||||
add_executable(puya32-playground)
|
||||
|
||||
target_link_libraries(puya32-playground
|
||||
PRIVATE py32-hal
|
||||
)
|
||||
|
||||
target_sources(puya32-playground PRIVATE
|
||||
src/main.c
|
||||
)
|
||||
|
||||
# clang-format
|
||||
add_custom_target(check-format
|
||||
find include/ src/ -iname '*.[ch]' -exec clang-format -Werror --dry-run {} +
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
add_custom_target(clang-format
|
||||
find include/ src/ -iname '*.[ch]' -exec clang-format -i {} +
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
38
CMakePresets.json
Normal file
38
CMakePresets.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"version": 3,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "default",
|
||||
"hidden": true,
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/build/${presetName}",
|
||||
"toolchainFile": "${sourceDir}/cmake/gcc-arm-none-eabi.cmake",
|
||||
"cacheVariables": {
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Debug",
|
||||
"inherits": "default",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Release",
|
||||
"inherits": "default",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
}
|
||||
],
|
||||
"buildPresets": [
|
||||
{
|
||||
"name": "Debug",
|
||||
"configurePreset": "Debug"
|
||||
},
|
||||
{
|
||||
"name": "Release",
|
||||
"configurePreset": "Release"
|
||||
}
|
||||
]
|
||||
}
|
||||
43
cmake/gcc-arm-none-eabi.cmake
Normal file
43
cmake/gcc-arm-none-eabi.cmake
Normal file
@@ -0,0 +1,43 @@
|
||||
set(CMAKE_SYSTEM_NAME Generic)
|
||||
set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||
|
||||
set(CMAKE_C_COMPILER_ID GNU)
|
||||
set(CMAKE_CXX_COMPILER_ID GNU)
|
||||
|
||||
# Some default GCC settings
|
||||
# arm-none-eabi- must be part of path environment
|
||||
set(TOOLCHAIN_PREFIX arm-none-eabi-)
|
||||
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
|
||||
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
|
||||
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}g++)
|
||||
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy)
|
||||
set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size)
|
||||
|
||||
set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf")
|
||||
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf")
|
||||
set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf")
|
||||
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||
|
||||
# MCU specific flags
|
||||
set(TARGET_FLAGS "-mcpu=cortex-m0plus ")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS}")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp -MMD -MP")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fdata-sections -ffunction-sections")
|
||||
|
||||
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-Os -g0")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-Os -g0")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions -fno-threadsafe-statics")
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${TARGET_FLAGS}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T \"${CMAKE_SOURCE_DIR}/py32f0-sdk/Libraries/LDScripts/py32f002ax5.ld\"")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --specs=nano.specs --specs=nosys.specs")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--print-memory-usage")
|
||||
set(TOOLCHAIN_LINK_LIBRARIES "m")
|
||||
1
py32f0-sdk
Submodule
1
py32f0-sdk
Submodule
Submodule py32f0-sdk added at 5c15e13230
75
src/main.c
Normal file
75
src/main.c
Normal file
@@ -0,0 +1,75 @@
|
||||
#include <py32f0xx_ll_bus.h>
|
||||
#include <py32f0xx_ll_gpio.h>
|
||||
#include <py32f0xx_ll_rcc.h>
|
||||
#include <py32f0xx_bsp_printf.h>
|
||||
#include <py32f0xx_ll_utils.h>
|
||||
|
||||
#define LED_PIN LL_GPIO_PIN_0
|
||||
|
||||
static void init(void)
|
||||
{
|
||||
/* LL_RCC_HSI_Enable(); */
|
||||
/* while(LL_RCC_HSI_IsReady() != 1); */
|
||||
|
||||
/* LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); */
|
||||
/* LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSISYS); */
|
||||
/* while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSISYS); */
|
||||
|
||||
/* LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); */
|
||||
/* LL_Init1msTick(8000000); */
|
||||
/* LL_SetSystemCoreClock(8000000); */
|
||||
|
||||
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
|
||||
LL_GPIO_SetPinMode(GPIOA, LED_PIN, LL_GPIO_MODE_OUTPUT);
|
||||
|
||||
BSP_USART_Config(115200);
|
||||
|
||||
LL_Init1msTick(8000000);
|
||||
LL_SetSystemCoreClock(8000000);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
init();
|
||||
|
||||
printf("Hello, PY32F002A!\r\n");
|
||||
|
||||
while(1) {
|
||||
LL_GPIO_TogglePin(GPIOA, LED_PIN);
|
||||
LL_mDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System service call via SWI instruction.
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Pendable request for system service.
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System tick timer.
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user