本帖最后由 xhackerustc 于 2024-9-1 19:39 编辑
#申请原创#
STEVAL-STWINKT1B这块开发板给人第一感觉就是板载传感器真是多,所以非常适合用来做STM家的传感 器评测。另开发板主控是用的STM32L4R9ZIJ6 MCU,其cpu基于Cortex-M4,最大频率120MHz。开发套件 自带了一块480 mAh的锂电池,STLINK-V3MINI调试器,以及一个外壳。完全组装起来后很漂亮,让人爱不释手。
linux开发环境概述
笔者长期在linux环境中干活,所以这次评测也以linux环境为例。开发环境软件上来说其实包括三大件:toolchain、项目工程编译管理和烧录调试。toolchain就用系统安装的arm-none-eabi-gcc,没安装 的读者可以看笔者其它开发板的评测,这里不赘述了。项目工程的编译笔者早期非常喜欢原始的Makefile,但后期MCU越来越复杂后切到cmake了。至于工具烧录和调试笔者特喜欢openocd与pyocd,但经笔者初步尝试,最新从源码编译的openocd成功烧录img后再openocd连接会报以下的错误,原因未知。
pyocd烧录同一个img没有此现象。另外说一句:用STM32CubeProgrammer烧录也没有此现象,说明openocd对STM32L4R9ZIJ的flash算法可能还有些兼容性问题,当然如果只用openocd调试是没任何问题的。所以笔者建议目前还是用pyocd吧。pyocd使用前需要安装下相应的Keil Pack包,STM官方已经上传至Keil官网,所以以下命令即可安装STM32L4R9ZIJ的pack包
pyocd pack install stm32l4r9zijx
点灯
下面开始大家喜闻乐见的点灯,但点灯之前有个问题源码基于什么来做。显而易见可以选择STM32CubeL4,但前面说过这个STEVAL-STWINKT1B开发板很特别,传感器特别多,STM官方甚至给它单独打造了一个名叫fp-sns-datalog2的github项目,使用上特别方便,用户甚至不用编译固件就能很方便的通过USB命令或者sdcard上的配置文件来使用它,那源码就基于它来开发吧。另外说一句:STM官方还有一个名叫fp-sns-datalog1的github项目,个人理解它与fp-sns-datalog2的区别应该就是底层的RTOS不一样,fp-sns-datalog1基于FreeRTOS,而fp-sns-datalog2基于ThreadX,两者都可以做代码基础,但笔者更喜欢ThreadX一些,所以选中了fp-sns-datalog2。
clone源码先:
git clone https://github.com/STMicroelectronics/fp-sns-datalog2.git
下面正式开始点灯之旅,先把样例工程拷贝一下
cp -a Projects/STM32L4R9ZI-STWIN/Applications/DATALOG2/ Projects/STM32L4R9ZI-STWIN/Applications/demo
经阅读STEVAL-STWINKT1B开发板开发板原理图可知,有两个LED可由用户控制,分别是LED1(蓝色)和LED2(橙色),分别接在了PE1和PD0两引脚上,修改Projects/STM32L4R9ZI-STWIN/Applications/demo/Core/Src/main.c加入点灯代码如下
<div class="blockcode"><blockquote>int main(void)
{
HAL_Init();
SystemClock_Config();
SystemPower_Config();
MX_GPIO_PE1_Init();
while (1) {
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);
HAL_Delay(500);
}
}
笔者的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 -Wdouble-promotion -Wno-unused-parameter)
add_compile_options(-O3)
project(stwinkt1b C ASM)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 99)
include_directories(Drivers/CMSIS/Include/
Drivers/CMSIS/Device/ST/STM32L4xx/Include/
Drivers/STM32L4xx_HAL_Driver/Inc/
Projects/STM32L4R9ZI-STWIN/Applications/demo/Core/Inc/
Projects/STM32L4R9ZI-STWIN/Applications/demo/mx/Inc/
Drivers/BSP/Components/iis2dh/
Drivers/BSP/Components/iis2mdc/
Drivers/BSP/Components/iis3dwb/
Drivers/BSP/Components/ism330dhcx/
Drivers/BSP/Components/lps22hh/
Drivers/BSP/Components/stts751/
Projects/STM32L4R9ZI-STWIN/Applications/demo/Core/Inc/drivers/
Projects/STM32L4R9ZI-STWIN/Applications/demo/Core/Inc/services/)
add_definitions(-DSTM32L4R9xx -DSYS_TP_MCU_STM32L4)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -include stm32l4xx_hal_conf.h -include sysconfig.h")
file(GLOB_RECURSE SOURCES
"Drivers/STM32L4xx_HAL_Driver/Src/*.c"
"Projects/STM32L4R9ZI-STWIN/Applications/demo/Core/Src/*.c"
"Projects/STM32L4R9ZI-STWIN/Applications/demo/Core/Src/tx_initialize_low_level.S"
"Projects/STM32L4R9ZI-STWIN/Applications/demo/Core/Startup/startup_stm32l4r9zijx.s"
"Projects/STM32L4R9ZI-STWIN/Applications/demo/mx/Src/*.c"
"Drivers/BSP/Components/iis2dh/iis2dh_reg.c"
"Drivers/BSP/Components/iis2mdc/iis2mdc_reg.c"
"Drivers/BSP/Components/iis3dwb/iis3dwb_reg.c"
"Drivers/BSP/Components/ism330dhcx/ism330dhcx_reg.c"
"Drivers/BSP/Components/lps22hh/lps22hh_reg.c"
"Drivers/BSP/Components/stts751/stts751_reg.c"
)
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/Projects/STM32L4R9ZI-STWIN/Applications/demo/STM32CubeIDE/STM32L4R9ZIJX_FLASH.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 printfloat)
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_22 ]lt;TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${CMAKE_OBJCOPY} -Obinary [ DISCUZ_CODE_22 ]lt;TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMAND ${CMAKE_OBJDUMP} --all-headers --demangle --disassemble [ DISCUZ_CODE_22 ]lt;TARGET_FILE:${PROJECT_NAME}.elf> > ${LST_FILE}
COMMAND ${SIZE} --format=berkeley [ DISCUZ_CODE_22 ]lt;TARGET_FILE:${PROJECT_NAME}.elf>
)
编译cmake -B build
cmake --build build -j8
烧录
pyocd load -e sector -t stm32l4r9zijx build/stwinkt1b.bin
此时STEVAL-STWINKT1B开发板上的绿色LED开始有规律闪烁,点灯完毕
|