Ubuntu 22.04 GCC Arm 12.2.rel1编译 DAPLink

ARMmbed / DAPLink 项目

仓库地址 https://github.com/ARMmbed/DAPLink

Arm Mbed 应该属于Arm的机构或者是Arm资助的机构. 常用的 DAPLink 基本上都是从这个项目派生的. 仓库主要是使用 Keil, 对 GCC 的支持是 2020 年才正式合并进来的 #750.

目录结构

├── docs                  # 文档
├── mbed-os.lib
├── projectfiles          # 根据不同的编译器, 对各个project生成的编译配置文件
│   ├── make_gcc_arm
│   └── uvision
├── projects.yaml         # project 列表
├── records
│   ├── board
│   ├── daplink
│   ├── family
│   ├── hic_hal
│   ├── rtos
│   ├── tools             # 对不同编译器的预设编译参数
│   └── usb
├── requirements.txt      # python依赖
├── source
│   ├── board
│   ├── cmsis-core
│   ├── daplink           # daplink的源码
│   ├── family            # 针对各厂商各型号的flash_blob.c 和 target.c
│   │   ├── ambiq
│   │   ├── arm
│   │   ├── freescale
│   │   ├── maxim
│   │   ├── nordic
│   │   ├── nuvoton
│   │   ├── nxp
│   │   ├── realtek
│   │   ├── renesas
│   │   ├── st
│   │   └── toshiba
│   ├── hic_hal
│   ├── rtos
│   ├── rtos2
│   ├── rtos_none
│   ├── target
│   └── usb
├── test
├── tools

Ubuntu 下使用 GCC Arm 编译

参考说明 How to Build

GCC Arm 工具链

下载地址

环境配置

安装python3

下载 GCC Arm 工具链, 并解压到合适的目录

导出项目, 在项目下创建 virtualenv

$ git clone https://github.com/mbedmicro/DAPLink
$ cd DAPLink
$ pip install virtualenv
$ virtualenv venv

启用虚拟环境(因为要使用progen)

$ source venv/bin/activate

第一次运行(如果后面仓库有更新也需要运行)

(venv) $ pip install -r requirements.txt

编译

方式一

PATH=$PATH:/opt/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/bin/;python tools/progen_compile.py -t make_gcc_arm --clean -v --parallel stm32f103xb_if

方式二

progen generate -t make_gcc_arm -p stm32f103xb_bl
PATH=$PATH:/opt/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/bin/;make -C projectfiles/make_gcc_arm/stm32f103xb_bl

遇到的问题

用 gcc arm 10.3 可以顺利编译, 如果用 gcc arm 11.2 会报 SysTick 错误, 如果用 11.3 或 12.2 编译, 会报这样的错误

Compiling ../../../source/usb/msc/usbd_core_msc.c
Compiling ../../../source/usb/msc/usbd_msc.c
Compiling ../../../source/usb/usbd_core.c
Assembling ../../../source/hic_hal/stm32/stm32f103xb/gcc/startup_stm32f103xb.S
Linking build/stm32f103xb_bl.elf
/opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld: /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-closer.o): in function `_close_r':
/data/jenkins/workspace/GNU-toolchain/arm-11/src/newlib-cygwin/newlib/libc/reent/closer.c:47: warning: _close is not implemented and will always fail
/opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld: /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-lseekr.o): in function `_lseek_r':
/data/jenkins/workspace/GNU-toolchain/arm-11/src/newlib-cygwin/newlib/libc/reent/lseekr.c:49: warning: _lseek is not implemented and will always fail
/opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld: /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-readr.o): in function `_read_r':
/data/jenkins/workspace/GNU-toolchain/arm-11/src/newlib-cygwin/newlib/libc/reent/readr.c:49: warning: _read is not implemented and will always fail
/opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld: /opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc_nano.a(libc_a-writer.o): in function `_write_r':
/data/jenkins/workspace/GNU-toolchain/arm-11/src/newlib-cygwin/newlib/libc/reent/writer.c:49: warning: _write is not implemented and will always fail
Memory region         Used Size  Region Size  %age Used
    m_interrupts:          1 KB         1 KB    100.00%
          m_text:         46 KB        46 KB    100.00%
        m_cfgrom:          0 GB         1 KB      0.00%
          m_data:        9168 B      20224 B     45.33%
        m_cfgram:         142 B        256 B     55.47%
collect2: error: ld returned 1 exit status
make: *** [Makefile:283: build/stm32f103xb_bl.elf] Error 1
make: Leaving directory '/home/milton/WorkC/DAPLink/projectfiles/make_gcc_arm/stm32f103xb_bl'

需要做以下的修改

  1. 编辑 vi source/daplink/sdk_stub.c

增加以下内容

__attribute__((weak)) int _write(int file, char *ptr, int len)
{
    (void)file;
    //int DataIdx;
    //for (DataIdx = 0; DataIdx < len; DataIdx++)
    //{
    //    __io_putchar(*ptr++);
    //}
    return len;
}

__attribute__((weak)) int _read(int file, char *ptr, int len)
{
    (void)file;
    //int DataIdx;
    //for (DataIdx = 0; DataIdx < len; DataIdx++)
    //{
    //    *ptr++ = __io_getchar();
    //}
    return len;
}

__attribute__((weak)) int _isatty(int fd)
{
    if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
        return 1;

    errno = EBADF;
    return 0;
}

__attribute__((weak)) int _close(int fd)
{
    if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
        return 0;

    errno = EBADF;
    return -1;
}

__attribute__((weak)) int _lseek(int fd, int ptr, int dir)
{
    (void)fd;
    (void)ptr;
    (void)dir;

    errno = EBADF;
    return -1;
}
  1. 修改 records/tools/gcc_arm.yaml

在 ld_flags 下增加 -Wl,--no-warn-rwx-segment

之后就能顺利编译了

相关链接

posted on 2023-02-02 22:21  Milton  阅读(748)  评论(0编辑  收藏  举报

导航