RT-Thread的 英飞凌的bsp 有些代码是做成package的,所以我们scons --menuconfig一次然后更新包:
- cd rt-thread/bsp/Infineon/psoc6-evaluationkit-062S2
- scons --menuconfig
- pkgs --update
现在可以复制rt-thread/bsp/Infineon/psoc6-evaluationkit-062S2目录备用
- cp -a rt-thread/bsp/Infineon/psoc6-evaluationkit-062S2 ~/psoc6
因ThreadX RTOS原生使用cmake管理,所以笔者也以cmake组织工程编译。为写CMakeLists.txt,需要对刚刚拷贝出来的psoc6文件仔细分析哪些是bsp驱动、哪些是RT-Thread的HAL,哪些是RT-Thread的app。经过分析后发现,
1.真正有用的目录就是libs和packages两个目录,可以其它目录都删除了
2.libs和packages目录下的目录/文件并没有全部用上,需要分析SConscript后把结果写入CMakeLists.txt编译规则,具体可以参考笔者后附的完整CMakeLists.txt文件
- set(CMAKE_SYSTEM_NAME Generic)
- set(CMAKE_SYSTEM_VERSION 1)
- set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
- cmake_minimum_required(VERSION 3.20)
- set(CMAKE_C_COMPILER arm-none-eabi-gcc)
- set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
- set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
- set(CMAKE_AR arm-none-eabi-ar)
- set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
- set(CMAKE_OBJDUMP arm-none-eabi-objdump)
- set(SIZE arm-none-eabi-size)
- set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
- set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
- set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
- set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
- add_compile_options(-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16)
- add_compile_options(-ffunction-sections -fdata-sections -fno-builtin -fno-common -Wall -Wshadow -Wdouble-promotion -Wno-unused-parameter)
- add_compile_options(-O3)
- project(cy8c624alqi C ASM)
- set(CMAKE_CXX_STANDARD 11)
- set(CMAKE_C_STANDARD 99)
- include_directories(libs/TARGET_RTT-062S2/config/GeneratedSource
- libs/TARGET_RTT-062S2
- packages/Infineon_cmsis-latest/Core/Include
- packages/Infineon_retarget-io-latest
- packages/Infineon_core-lib-latest/include
- packages/Infineon_capsense-latest
- packages/Infineon_mtb-hal-cat1-latest/include
- packages/Infineon_mtb-hal-cat1-latest/include_pvt
- packages/Infineon_mtb-hal-cat1-latest/COMPONENT_CAT1A/include
- packages/Infineon_mtb-hal-cat1-latest/COMPONENT_CAT1A/include/pin_packages
- packages/Infineon_mtb-hal-cat1-latest/COMPONENT_CAT1A/include/triggers
- packages/Infineon_mtb-pdl-cat1-latest/drivers/include
- packages/Infineon_mtb-pdl-cat1-latest/devices/COMPONENT_CAT1A/include
- packages/Infineon_mtb-pdl-cat1-latest/devices/COMPONENT_CAT1A/include/ip)
- add_definitions(-DCY_RETARGET_IO_NO_FLOAT -DCY8C624ALQI_S2D42 -DCORE_NAME_CM0P_0 -DCORE_NAME_CM4_0 -DCY_USING_PREBUILT_CM0P_IMAGE -DCY_USING_HAL -DCOMPONENT_CAT1A -DCOMPONENT_CAT1)
- file(GLOB_RECURSE SOURCES
- "applications/threadx/*.c"
- "packages/Infineon_cat1cm0p-latest/COMPONENT_CAT1A/COMPONENT_CM0P_SLEEP/*.c"
- "packages/Infineon_retarget-io-latest/cy_retarget_io.c"
- "packages/Infineon_mtb-pdl-cat1-latest/devices/COMPONENT_CAT1A/source/cy_device.c"
- "packages/Infineon_mtb-pdl-cat1-latest/drivers/source/*.c"
- "packages/Infineon_mtb-pdl-cat1-latest/drivers/source/TOOLCHAIN_GCC_ARM/cy_syslib_ext.S"
- "packages/Infineon_mtb-hal-cat1-latest/source/*.c"
- "packages/Infineon_mtb-hal-cat1-latest/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_02.c"
- "packages/Infineon_mtb-hal-cat1-latest/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_02_68_qfn.c"
- "libs/TARGET_RTT-062S2/COMPONENT_CM4/TOOLCHAIN_GCC_ARM/startup_psoc6_02_cm4.S"
- "libs/TARGET_RTT-062S2/COMPONENT_CM4/system_psoc6_cm4.c"
- "libs/TARGET_RTT-062S2/config/GeneratedSource/*.c"
- "libs/TARGET_RTT-062S2/cybsp.c"
- )
- set(THREADX_SRC_DIR ${CMAKE_SOURCE_DIR}/../../kernel/threadx/)
- set(THREADX_ARCH "cortex_m4")
- set(THREADX_TOOLCHAIN "gnu")
- add_subdirectory(${THREADX_SRC_DIR}/threadx threadx)
- set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/board/linker_scripts/link.ld)
- add_link_options(
- -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
- -Wl,--gc-sections,--print-memory-usage,-Map,${PROJECT_NAME}.map
- --specs=nano.specs
- --specs=nosys.specs)
- add_link_options(-T ${LINKER_SCRIPT})
- add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})
- target_link_libraries(${PROJECT_NAME}.elf azrtos::threadx)
- set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
- set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)
- set(LST_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.lst)
- add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
- COMMAND ${CMAKE_OBJCOPY} -Oihex [ DISCUZ_CODE_140 ]lt;TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
- COMMAND ${CMAKE_OBJCOPY} -Obinary [ DISCUZ_CODE_140 ]lt;TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
- COMMAND ${CMAKE_OBJDUMP} --all-headers --demangle --disassemble [ DISCUZ_CODE_140 ]lt;TARGET_FILE:${PROJECT_NAME}.elf> > ${LST_FILE}
- COMMAND ${SIZE} --format=berkeley [ DISCUZ_CODE_140 ]lt;TARGET_FILE:${PROJECT_NAME}.elf>
- )
创建applications/threadx目录,目录中有main.c和sample_threadx.c。其中sample_threadx.c内容来自ThreadX的测试用例,main.c内容如下:
- #include "cyhal.h"
- #include "cybsp.h"
- #include "cy_retarget_io.h"
- #define TICK_PER_SECOND 100
- extern void tx_main(void);
- extern void _tx_timer_interrupt(void);
- static void handle_error(void)
- {
- /* Disable all interrupts. */
- __disable_irq();
- CY_ASSERT(0);
- }
- int main(void)
- {
- cy_rslt_t result;
- /* Initialize the device and board peripherals */
- result = cybsp_init();
- if (result != CY_RSLT_SUCCESS)
- handle_error();
- /* Initialize retarget-io to use the debug UART port */
- result = cy_retarget_io_init_fc(CYBSP_DEBUG_UART_TX,
- CYBSP_DEBUG_UART_RX,
- NC,
- NC,
- CY_RETARGET_IO_BAUDRATE);
- if (result != CY_RSLT_SUCCESS)
- handle_error();
- tx_main();
- }
- static void SysTick_Handler_CB(void)
- {
- #ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
- _tx_execution_isr_enter();
- #endif
- _tx_timer_interrupt();
- #ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
- _tx_execution_isr_exit();
- #endif
- }
- void _tx_initialize_low_level(void)
- {
- __disable_irq();
- /* TODO Enable the cycle count register */
- /* not used */
- //_tx_initialize_unused_memory = __RAM_segment_used_end__;
- //_tx_thread_system_stack_ptr = _estack;
- SysTick_Config(SystemCoreClock / TICK_PER_SECOND);
- (void)Cy_SysInt_SetVector(SysTick_IRQn, SysTick_Handler_CB);
- NVIC_SetPriority(SVCall_IRQn, 0xff);
- NVIC_SetPriority(PendSV_IRQn, 0xff);
- NVIC_SetPriority(SysTick_IRQn, 4);
- }
编译:
- cmake -B build
- cmake --build build
烧录:
- openocd -f interface/kitprog3.cfg -f target/psoc6_2m.cfg -c "program build/cy8c624alqi.bin verify reset exit 0x10000000"
运行视频: