打印
[MM32硬件]

【灵动微电子MM32F5330测评】2.配置VSCODE+CMAKE开发环境及祖传点灯

[复制链接]
2064|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 sujingliang 于 2024-6-22 18:13 编辑

前言
非常荣幸能够获得这次宝贵的测评机会,我衷心感谢灵动微电子以及21IC给予我的这份信任与支持。
昨天收到Mini-F5333评估开发板:



配置VSCODE+CMAKE开发环境
简单描述一下步骤吧,这个网上比较多:
1、安装VScode
2、安装编译器MinGW
3、安装cmake
4、VSCODE中安装cmake、c/c++、cmake tools三个插件
5、安装交叉编译工具:arm-gnu-toolchain-13.2.rel1-mingw-w64-i686-arm-none-eabi.exe
6、安装ninja

编写CMakeLists.txt
#THIS FILE IS AUTO GENERATED FROM THE TEMPLATE! DO NOT CHANGE!
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
cmake_minimum_required(VERSION 3.20)

# specify cross compilers and tools
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_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

# project settings
project(gpio_led_toggle  C CXX ASM)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)

#Uncomment for hardware floating point
#add_compile_definitions(ARM_MATH_CM4;ARM_MATH_MATRIX_CHECK;ARM_MATH_ROUNDING)
#add_compile_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
#add_link_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)

#Uncomment for software floating point
#add_compile_options(-mfloat-abi=soft)

add_compile_options(-mcpu=cortex-m33 -mthumb -mthumb-interwork)
add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0)

# uncomment to mitigate c++17 absolute addresses warnings
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-register")
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
    message(VERBOSE "Maximum optimization for speed")
    add_compile_options(-Ofast)
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
    message(VERBOSE "Maximum optimization for speed, debug info included")
    add_compile_options(-Ofast -g)
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
    message(VERBOSE "Maximum optimization for size")
    add_compile_options(-Os)
else ()
    message(VERBOSE "Minimal optimization, debug info included")
    add_compile_options(-Og -g)
endif ()

#添加宏定义
add_definitions(-DUSE_STDPERIPH_DRIVER -DCUSTOM_HSE_VAL)

#添加头文件路径,即.h文件
include_directories(. ./board ./device ./device/CMSIS/Include ./device/drivers)
#添加源文件路径,即.c或者.s文件
file(GLOB SOURCES  ./application/*.c ./board/*.c ./device/armgcc/*.S ./device/drivers/*.c ./device/*.c ./*.c)

#添加你的STM32F103ZETx_FLASH.ld的连接脚本路径
set(LINKER_SCRIPT D:/mini-f5330_blinky_led_armgcc/device/armgcc/linker/mm32f5333d_flash.ld)

add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map)
#选择cortex-m3内核
add_link_options(-mcpu=cortex-m33 -mthumb -mthumb-interwork)
add_link_options(-T ${LINKER_SCRIPT})

add_link_options(-specs=nano.specs -specs=nosys.specs -u _printf_float)

add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})

set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)

add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
        COMMAND ${CMAKE_OBJCOPY} -Oihex [        DISCUZ_CODE_6        ]lt;TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
        COMMAND ${CMAKE_OBJCOPY} -Obinary [        DISCUZ_CODE_6        ]lt;TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
        COMMENT "Building ${HEX_FILE}
Building ${BIN_FILE}")

编写gcc链接器(Linker)文件:mm32f5333d_flash.ld
/* ROM definition */
__ROM_BASE   = 0x08000000;
__ROM_SIZE   = 0x000020000;

/* RAM definition */
__RAM_BASE   = 0x20000000;
__RAM_SIZE   = 0x00008000;

/* Stack and heap definition */
__STACK_SIZE = 0x00000800;
__HEAP_SIZE  = 0x00000C00;


/* Memory Setting */
MEMORY {
    RAM      (xrw)   : ORIGIN = __RAM_BASE,   LENGTH = __RAM_SIZE
    FLASH    (rx)    : ORIGIN = __ROM_BASE,   LENGTH = __ROM_SIZE
}

/* Entry Point */
ENTRY(Reset_Handler)

/* Sections */
SECTIONS {
    .text :
    {
        KEEP(*(.vectors))
        *(.text*)

        KEEP(*(.init))
        KEEP(*(.fini))

        /* .ctors */
        *crtbegin.o(.ctors)
        *crtbegin?.o(.ctors)
        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
        *(SORT(.ctors.*))
        *(.ctors)

        /* .dtors */
        *crtbegin.o(.dtors)
        *crtbegin?.o(.dtors)
        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
        *(SORT(.dtors.*))
        *(.dtors)

        *(.rodata*)

        KEEP(*(.eh_frame*))
    } > FLASH

    .ARM.extab :
    {
        *(.ARM.extab* .gnu.linkonce.armextab.*)
    } > FLASH

    __exidx_start = .;
    .ARM.exidx :
    {
        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
    } > FLASH
    __exidx_end = .;

    .copy.table :
    {
        . = ALIGN(4);
        __copy_table_start__ = .;

        LONG (__etext)
        LONG (__data_start__)
        LONG ((__data_end__ - __data_start__) / 4)

        __copy_table_end__ = .;
    } > FLASH

    .zero.table :
    {
        . = ALIGN(4);
        __zero_table_start__ = .;
        __zero_table_end__ = .;
    } > FLASH

    /**
    * Location counter can end up 2byte aligned with narrow Thumb code but
    * __etext is assumed by startup code to be the LMA of a section in RAM
    * which must be 4byte aligned
    */
    __etext = ALIGN (4);

    .data : AT (__etext)
    {
        __data_start__ = .;
        *(vtable)
        *(.data)
        *(.data.*)

        . = ALIGN(4);
        /* preinit data */
        PROVIDE_HIDDEN (__preinit_array_start = .);
        KEEP(*(.preinit_array))
        PROVIDE_HIDDEN (__preinit_array_end = .);

        . = ALIGN(4);
        /* init data */
        PROVIDE_HIDDEN (__init_array_start = .);
        KEEP(*(SORT(.init_array.*)))
        KEEP(*(.init_array))
        PROVIDE_HIDDEN (__init_array_end = .);

        . = ALIGN(4);
        /* finit data */
        PROVIDE_HIDDEN (__fini_array_start = .);
        KEEP(*(SORT(.fini_array.*)))
        KEEP(*(.fini_array))
        PROVIDE_HIDDEN (__fini_array_end = .);

        KEEP(*(.jcr*))
        . = ALIGN(4);
        /* All data end */
        __data_end__ = .;

    } > RAM

    .bss :
    {
        . = ALIGN(4);
        __bss_start__ = .;
        *(.bss)
        *(.bss.*)
        *(COMMON)
        . = ALIGN(4);
        __bss_end__ = .;
    } > RAM AT > RAM

    .heap (COPY) :
    {
        . = ALIGN(8);
        __end__ = .;
        PROVIDE(end = .);
        . = . + __HEAP_SIZE;
        . = ALIGN(8);
        __HeapLimit = .;
    } > RAM

    .stack (ORIGIN(RAM) + LENGTH(RAM) - __STACK_SIZE) (COPY) :
    {
        . = ALIGN(8);
        __StackLimit = .;
        . = . + __STACK_SIZE;
        . = ALIGN(8);
        __StackTop = .;
    } > RAM
    PROVIDE(__stack = __StackTop);

    /* Check if data + heap + stack exceeds RAM limit */
    ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
}



/* This command is like INPUT, except that the named files should all be
archives, and they are searched repeatedly until no new undefined references
are created. See the description of `-(' in section Command Line Options. */

/*
* if no libs, please comment it.
* else uncomment it.

GROUP (
)

*/


点灯程序

int main(void)
{
    PLATFORM_Init();

    GPIO_LED_Toggle_Sample();

    while (1)
    {
    }
}

void GPIO_LED_Toggle_Sample(void)
{
    printf("\r\nTest %s", __FUNCTION__);

    GPIO_Configure();

    while (1)
    {
        GPIO_IO_Toggle(GPIOB, GPIO_Pin_10);
        GPIO_IO_Toggle(GPIOB, GPIO_Pin_11);
        GPIO_IO_Toggle(GPIOC, GPIO_Pin_6);
        GPIO_IO_Toggle(GPIOC, GPIO_Pin_7);

        PLATFORM_DelayMS(100);
    }
}

cmate tools配置

生成:

用POWERWRITE烧录

运行:

使用特权

评论回复
沙发
Bowclad| | 2024-6-27 18:17 | 只看该作者
cmake一直搞不懂该怎么写

使用特权

评论回复
板凳
lulugl| | 2024-12-21 23:31 | 只看该作者
cfg跟svd可以弄出来吗?

使用特权

评论回复
地板
suncat0504| | 2024-12-23 12:08 | 只看该作者
灵动微的单片机很不错的。开发华景,为啥不选择Keil?VSCode更方便吗?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

37

主题

73

帖子

0

粉丝