STM32F407移植1588v2(ptpd)

news2024/11/24 23:10:03

硬件:

STM32F407ZGT6开发板

软件:

VSCode

arm-none-eabi-gcc

openOCD

st-link

在github搜到一个在NUCLEO-F429ZI开发板上移植ptpd的example,因为和F407差别很小,所以就打算用这个demo移植到手头的开发板上。因为目前只需要slave,所以只调试了slave。据介绍,master好像原作者没有充分测试过。

源项目链接:

https://github.com/mpthompson/stm32_ptpd

1.修改ETH引脚

projects/nucleo_ptpd_slave/src/hal_system.c中 HAL_ETH_MspInit 函数里有ETH引脚初始化:

 根据自己手头板子调整引脚初始化,其实可以先用STM32CubeMX生成一个测试工程,测试一下板子硬件是好的再移植是最正确的流程。关于ETH硬件测试工程可以参考我之前的博文:

(GCC)从零开始的ETH开发--STM32F407ZGTX_我我我只会printf的博客-CSDN博客

这里记得在初始化完成后,使用复位引脚复位PHY。还有原工程是F429,现在改成F407需要修改头文件hal_system.h中:

还有时钟类型需要根据实际修改,一般都是外部晶振:

2.修改makefile

F429和F407启动文件不同,所以需要修改slave工程包含的makefile:

 其次删除newlib_stubs.c文件,否则编译后的固件没办法使用。

还有修改宏定义:

还有注意修改ld脚本文件,这里我使用的是自己新建的ld文件:

其他修改可有可无,根据自己情况修改。makefile文件如下:

# Makefile for PTPD slave for NUCLEO-F429ZI.

# Project name
NAME = nucleo_ptpd_slave
CPU = -mcpu=cortex-m4
# fpu
FPU = -mfpu=fpv5-d16

# float-abi
FLOAT-ABI = -mfloat-abi=hard

# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# Outputs
BINMAP = $(NAME).map
BINELF = $(NAME).elf
BINHEX = $(NAME).hex
BINBIN = $(NAME).bin
BINCRC = $(NAME).crc
BINMAP = $(NAME).map

# GNU ARM Embedded Toolchain
PREFIX = arm-none-eabi-
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
CXX = $(GCC_PATH)/$(PREFIX)g++
LD = $(GCC_PATH)/$(PREFIX)ld
AR = $(GCC_PATH)/$(PREFIX)ar
AS = $(GCC_PATH)/$(PREFIX)as
NM = $(GCC_PATH)/$(PREFIX)nm
SIZE = $(GCC_PATH)/$(PREFIX)size
A2L = $(GCC_PATH)/$(PREFIX)addr2line
OBJCOPY = $(GCC_PATH)/$(PREFIX)objcopy
OBJDUMP = $(GCC_PATH)/$(PREFIX)objdump
else
CC = $(PREFIX)gcc
CXX = $(PREFIX)g++
LD = $(PREFIX)ld
AR = $(PREFIX)ar
AS = $(PREFIX)as
NM = $(PREFIX)nm
SIZE = $(PREFIX)size
A2L = $(PREFIX)addr2line
OBJCOPY = $(PREFIX)objcopy
OBJDUMP = $(PREFIX)objdump
endif

# Startup
# SRCS = ../shared_stm32/startup/gcc/startup_stm32f429xx.s
SRCS = ../shared_stm32/startup/gcc/startup_stm32f407xx.s

# Application
SRCS += ./src/main.c
SRCS += ./src/hal_system.c

# Application Shared
SRCS += ../shared/event.c
SRCS += ../shared/outputf.c
SRCS += ../shared/peek.c
SRCS += ../shared/reboot.c
SRCS += ../shared/shell.c
SRCS += ../shared/syslog.c
SRCS += ../shared/telnet.c
SRCS += ../shared/uptime.c

# Application Shared Nucleo
SRCS += ../shared_nucleo/buttons.c
SRCS += ../shared_nucleo/leds.c

# Application Shared STM32
SRCS += ../shared_stm32/blink.c
SRCS += ../shared_stm32/clocks.c
SRCS += ../shared_stm32/console.c
SRCS += ../shared_stm32/delay.c
SRCS += ../shared_stm32/ethptp.c
SRCS += ../shared_stm32/extint.c
SRCS += ../shared_stm32/hardtime.c
SRCS += ../shared_stm32/network.c
SRCS += ../shared_stm32/ntime.c
SRCS += ../shared_stm32/random.c
SRCS += ../shared_stm32/systime.c
SRCS += ../shared_stm32/system_stm32f4xx.c
SRCS += ../shared_stm32/tick.c
SRCS += ../shared_stm32/watchdog.c

# Utilities
# SRCS += ../shared/newlib_stubs.c

# Drivers
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_eth.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_adc.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_crc.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_dac.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_dma.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_dma2d.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_exti.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fsmc.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_gpio.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_i2c.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_lptim.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_pwr.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_rcc.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_rng.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_rtc.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_spi.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_tim.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usart.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c
SRCS += ../../libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_utils.c

# NT Shell
SRCS += ../../libraries/ntshell-v0.3.1/lib/core/ntlibc.c
SRCS += ../../libraries/ntshell-v0.3.1/lib/util/ntopt.c
SRCS += ../../libraries/ntshell-v0.3.1/lib/core/ntshell.c
SRCS += ../../libraries/ntshell-v0.3.1/lib/util/ntstdio.c
SRCS += ../../libraries/ntshell-v0.3.1/lib/core/text_editor.c
SRCS += ../../libraries/ntshell-v0.3.1/lib/core/text_history.c
SRCS += ../../libraries/ntshell-v0.3.1/lib/core/vtrecv.c
SRCS += ../../libraries/ntshell-v0.3.1/lib/core/vtsend.c

# PTPD
SRCS += ../shared/ptpd/src/ptpd_arith.c
SRCS += ../shared/ptpd/src/ptpd_bmc.c
SRCS += ../shared/ptpd/src/ptpd_main.c
SRCS += ../shared/ptpd/src/ptpd_msg.c
SRCS += ../shared/ptpd/src/ptpd_net.c
SRCS += ../shared/ptpd/src/ptpd_protocol.c
SRCS += ../shared/ptpd/src/ptpd_servo.c
SRCS += ../shared/ptpd/src/ptpd_time.c
SRCS += ../shared/ptpd/src/ptpd_timer.c

# LWIP API
SRCS += ../../libraries/LWIP-2.1.2/src/api/api_lib.c
SRCS += ../../libraries/LWIP-2.1.2/src/api/api_msg.c
SRCS += ../../libraries/LWIP-2.1.2/src/api/err.c
SRCS += ../../libraries/LWIP-2.1.2/src/api/netbuf.c
SRCS += ../../libraries/LWIP-2.1.2/src/api/netdb.c
SRCS += ../../libraries/LWIP-2.1.2/src/api/netifapi.c
SRCS += ../../libraries/LWIP-2.1.2/src/api/sockets.c
SRCS += ../../libraries/LWIP-2.1.2/src/api/tcpip.c

# LWIP Core
SRCS += ../../libraries/LWIP-2.1.2/src/core/altcp.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/altcp_alloc.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/altcp_tcp.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/def.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/dns.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/inet_chksum.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/init.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ip.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/mem.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/memp.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/netif.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/pbuf.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/raw.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/stats.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/sys.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/tcp.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/tcp_in.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/tcp_out.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/timeouts.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/udp.c

# LWIP Core IPv4
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv4/autoip.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv4/dhcp.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv4/etharp.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv4/icmp.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv4/igmp.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv4/ip4.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv4/ip4_addr.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv4/ip4_frag.c

# LWIP Core IPv6
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv6/dhcp6.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv6/ethip6.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv6/icmp6.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv6/inet6.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv6/ip6.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv6/ip6_addr.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv6/ip6_frag.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv6/mld6.c
SRCS += ../../libraries/LWIP-2.1.2/src/core/ipv6/nd6.c

# LWIP Netif
SRCS += ../../libraries/LWIP-2.1.2/src/netif/ethernet.c
SRCS += ../../libraries/LWIP-2.1.2/src/netif/lowpan6.c

# LWIP Port
SRCS += ../shared_stm32/lwip_port/ethernetif.c
SRCS += ../shared_stm32/lwip_port/sys_arch.c

# LWIP Apps
SRCS += ../../libraries/LWIP-2.1.2/src/apps/mdns/mdns.c

# RTOS Config
SRCS += ./src/RTX_Config.c

# RTOS Kernel
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source/rtx_delay.c
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source/rtx_evflags.c
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source/rtx_evr.c
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source/rtx_kernel.c
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source/rtx_lib.c
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source/rtx_memory.c
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source/rtx_mempool.c
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source/rtx_msgqueue.c
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source/rtx_mutex.c
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source/rtx_semaphore.c
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source/rtx_system.c
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source/rtx_thread.c
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source/rtx_timer.c
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/Source/os_systick.c

# RTOS IRQ
SRCS += ../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source/GCC/irq_cm4f.S

# List of directories that contain source code
SRC_PATHS = $(sort $(dir $(SRCS)))

# Specify the output path
OUTPATH = build

# Create the object list from the sources
OBJS = $(subst .s,.o,$(subst .S,.o,$(subst .c,.o,$(subst .cpp,.o,$(addprefix $(OUTPATH)/, $(notdir $(SRCS)))))))

#$(info SRCS=$(SRCS))
#$(info OBJS=$(OBJS))
#$(info SRC_PATHS=$(SRC_PATHS))

# Where to find source files.
vpath %.cpp $(SRC_PATHS)
vpath %.c $(SRC_PATHS)
vpath %.s $(SRC_PATHS)
vpath %.S $(SRC_PATHS)

# Includes
INCLUDES = -I.
INCLUDES += -I./src
INCLUDES += -I../shared
INCLUDES += -I../shared/ptpd/src
INCLUDES += -I../shared_stm32
INCLUDES += -I../shared_stm32/lwip_port
INCLUDES += -I../shared_nucleo
INCLUDES += -I../../libraries/CMSIS/5.4.0/CMSIS/Core/Include
INCLUDES += -I../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/Include
INCLUDES += -I../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Include
INCLUDES += -I../../libraries/CMSIS/5.4.0/CMSIS/RTOS2/RTX/Source
INCLUDES += -I../../libraries/CMSIS/5.4.0_ST/Device/ST/STM32F4xx/Include
INCLUDES += -I../../libraries/STM32F4xx_HAL_Driver/Inc
INCLUDES += -I../../libraries/LWIP-2.1.2/src
INCLUDES += -I../../libraries/LWIP-2.1.2/src/include
INCLUDES += -I../../libraries/ntshell-v0.3.1/lib/core
INCLUDES += -I../../libraries/ntshell-v0.3.1/lib/util

OPTFLAGS = -O0

MCFLAGS = -mcpu=cortex-m4
MCFLAGS += -mthumb
MCFLAGS += -mlittle-endian
MCFLAGS += -mfpu=fpv4-sp-d16
MCFLAGS += -mfloat-abi=hard
#MCFLAGS += -mapcs-frame
MCFLAGS += -MD
MCFLAGS += -Wall

#FFLAGS = -fno-common
FFLAGS += -ffunction-sections
FFLAGS += -fdata-sections
#FFLAGS += -ffreestanding
#FFLAGS += -fno-builtin

#WFLAGS = -Wno-strict-aliasing

DEFINES = -DSTM32F407xx
DEFINES += -DNDEBUG
# DEFINES += -DUSE_STM32F4XX_NUCLEO_144
DEFINES += -DUSE_STM32F4_DISCOVERY
DEFINES += -DUSE_HAL_DRIVER
DEFINES += -DUSE_FULL_LL_DRIVER
DEFINES += -D__CMSIS_RTOS
DEFINES += -DVECT_TAB_OFFSET=0x0
DEFINES += -DEVR_RTX_DISABLE

LIBS = -lc -lm -lnosys
LIBDIR = 
# CFLAGS
CFLAGS = -c -g -gdwarf-2 $(OPTFLAGS) $(MCFLAGS) $(FFLAGS) $(WFLAGS) $(DEFINES) $(INCLUDES)
CXXFLAGS = -c $(OPTFLAGS) $(MCFLAGS) $(FFLAGS) $(WFLAGS) $(DEFINES) $(INCLUDES) -std=c++11

# LINKER FLAGS
LDSCRIPT = nucleo_stm32f407.ld
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(OUTPATH)/$(BINMAP),--cref -Wl,--gc-sections
###
# Build Rules
.PHONY: all release debug clean

all: $(OUTPATH) release

debug: CFLAGS += -DDEBUG -g -g3 -gdwarf-2 -gdwarf-3
debug: CXXFLAGS += -DDEBUG -g -g3 -gdwarf-2 -gdwarf-3
debug: LDFLAGS += -g -g3 -gdwarf-2 -gdwarf-3
debug: release

# release: $(OUTPATH)/$(BINHEX) $(OUTPATH)/$(BINBIN) $(OUTPATH)/$(BINCRC)

release: $(OUTPATH)/$(BINHEX) $(OUTPATH)/$(BINBIN)

# $(OUTPATH):
# 	mkdir -p $(OUTPATH)

$(OUTPATH):
	mkdir $(OUTPATH)

$(OUTPATH)/$(BINHEX): $(OUTPATH)/$(BINELF)
	$(OBJCOPY) -O ihex $< $@

$(OUTPATH)/$(BINBIN): $(OUTPATH)/$(BINELF)
	$(OBJCOPY) -O binary $< $@

#$(OUTPATH)/$(BINCRC): $(OUTPATH)/$(BINBIN)
#	cksum < $< > $@

##
# C linking is used. If C++ linker is required, change:
#   $(CC) $(OBJS) $(LDFLAGS) -o $@
# to:
#   $(CXX) $(OBJS) $(LDFLAGS) -o $@
#
$(OUTPATH)/$(BINELF): $(OBJS)
	$(CC) $(OBJS) $(LDFLAGS) -o $@
	$(SIZE) $(OUTPATH)/$(BINELF)

$(OUTPATH)/%.o : %.cpp
	$(CXX) $(CXXFLAGS) $< -o $@

$(OUTPATH)/%.o : %.c
	$(CC) $(CFLAGS) $< -o $@

$(OUTPATH)/%.o : %.s
	$(CC) $(CFLAGS) $< -o $@

$(OUTPATH)/%.o : %.S
	$(CC) $(CFLAGS) $< -o $@

clean:
	rm ./$(OUTPATH)
flash: $(OUTPATH)/$(BINHEX) 
	st-flash --reset --format ihex write $(OUTPATH)/$(BINHEX)


ld文件:

ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM);    /* end of 192K RAM on AHB bus*/

/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x200;      /* required amount of heap  */
_Min_Stack_Size = 0x800; /* required amount of stack */

/* Specify the memory areas */
MEMORY
{
  FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1024K
  RAM (rwx)       : ORIGIN = 0x20000000, LENGTH = 128K
  CCM (rwx)       : ORIGIN = 0x10000000, LENGTH = 64K
}

SECTIONS
{
  .isr_vector :
  {
    . = ALIGN(4);
    _sflash = .;        /* create a global symbol at flash start */
    KEEP(*(.isr_vector))
    . = ALIGN(4);
  } >FLASH

  .text :
  {
    . = ALIGN(4);
    *(.text)           /* .text sections (code) */
    *(.text*)          /* .text* sections (code) */
    *(.rodata)         /* .rodata sections (constants, strings, etc.) */
    *(.rodata*)        /* .rodata* sections (constants, strings, etc.) */
    *(.glue_7)         /* glue arm to thumb code */
    *(.glue_7t)        /* glue thumb to arm code */
    *(.eh_frame)

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

    . = ALIGN(4);
    _etext = .;        /* define a global symbols at end of code */
    _exit = .;
  } >FLASH

  .ARM.extab   : {
    . = ALIGN(4);
    *(.ARM.extab* .gnu.linkonce.armextab.*)
    . = ALIGN(4);
  } >FLASH

  .ARM : {
    . = ALIGN(4);
    __exidx_start = .;
    *(.ARM.exidx*)
    __exidx_end = .;
    . = ALIGN(4);
  } >FLASH


  .preinit_array     :
  {
    PROVIDE_HIDDEN (__preinit_array_start = .);
    KEEP (*(.preinit_array*))
    PROVIDE_HIDDEN (__preinit_array_end = .);
  } >FLASH
  .init_array :
  {
    PROVIDE_HIDDEN (__init_array_start = .);
    KEEP (*(SORT(.init_array.*)))
    KEEP (*(.init_array*))
    PROVIDE_HIDDEN (__init_array_end = .);
  } >FLASH
  .fini_array :
  {
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(.fini_array*))
    KEEP (*(SORT(.fini_array.*)))
    PROVIDE_HIDDEN (__fini_array_end = .);
  } >FLASH

  /* used by the startup to initialize data */
  _sidata = .;

  /* Initialized data sections goes into RAM, load LMA copy after code */
  .data : AT ( _sidata )
  {
    . = ALIGN(4);
    _sdata = .;        /* create a global symbol at data start */
    *(.data)           /* .data sections */
    *(.data*)          /* .data* sections */

    . = ALIGN(4);
    _edata = .;        /* define a global symbol at data end */
  } >RAM

  /* Uninitialized data section */
  . = ALIGN(4);
  .bss :
  {
    /* This is used by the startup in order to initialize the .bss secion */
    _sbss = .;         /* define a global symbol at bss start */
    __bss_start__ = _sbss;
    *(.bss)
    *(.bss*)
    *(COMMON)

    . = ALIGN(4);
    _ebss = .;         /* define a global symbol at bss end */
    __bss_end__ = _ebss;
  } >RAM

  /* User_heap_stack section, used to check that there is enough RAM left */
  ._user_heap_stack :
  {
    . = ALIGN(8);
    PROVIDE ( end = . );
    PROVIDE ( _end = . );
    . = . + _Min_Heap_Size;
    . = . + _Min_Stack_Size;
    . = ALIGN(8);
  } >RAM
  /* Remove information from the compiler libraries */
  /DISCARD/ :
  {
    libc.a ( * )
    libm.a ( * )
    libgcc.a ( * )
  }

  .ARM.attributes 0 : { *(.ARM.attributes) }
}

注意我使用的gcc版本是:

gcc version 10.3.1 20210621 (release) (GNU Arm Embedded Toolchain 10.3-2021.08)

如果你是用同样的版本,可以直接使用上述makefile,否则可能出现编译失败错误。

3.修改串口

串口配置在console.c文件中,因为我使用的串口和 USE_STM32F4_DISCOVERY 这个开发板串口相同,所以我在上文宏定义的地方直接使用了USE_STM32F4_DISCOVERY宏定义,如果你也按上文使用了USE_STM32F4_DISCOVERY宏定义,但是串口又不相同,请修改:

以及中断名称:

GCC下重定向printf请添加:

int _write (int fd, char *pBuffer, int size)
{
  for (int i = 0; i < size; i++)
  {
    if(pBuffer[i] == '\n')
      console_putc('\r');
    console_putc((int)pBuffer[i]);
  }
  return size;
}

4.修改报文

注意,此处修改只是我为了和电脑运行的ptp4l之间进行测试,如果不修改报文,ptp4l会认为报文异常。

还有slave和master之间稳定的限幅可以设置的大一点:

5.代码编译

至此所有修改完成,在slave工程目录下make即可:

6.代码运行

ubuntu下使用

sudo ptp4l -E -4 -S -i ens40 -m 

-i后跟网卡名称 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/644461.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【C语言】VScode中配置C语言/C++运行环境(保姆级图文)

目录 省流助手1. 下载安装VScode2. 下载编译器MinGW并解压3. 将MinGW添加至环境变量4. 安装vscode的插件5. 运行代码6. 调整和优化&#xff08;这部分转自零流火星动力猿 2022.4.12&#xff09;总结 欢迎关注 『C语言』 系列&#xff0c;持续更新中 欢迎关注 『C语言』 系列&am…

初识滴滴交易策略之三:供需调节

本篇文章分为&#xff1a; 1.什么是交易市场中的供需&#xff1f; 供需的动态性供需的相互作用 2.滴滴业务场景涉及的供需调节技术 供需感知和供需预测 时序预测供需调节以提升市场匹配程度&#xff0c;保持供需平衡 整数规划为司机规划更好的出车方式 模仿学习&#xff08;Imi…

【工具篇】Maven使用${revision}实现多模块版本统一管理

背景说明 在使用Maven多模块结构工程时&#xff0c;版本管理是一件很繁琐且容易出错的事情。每次升级版本号都要手动调整或者通过mvn versions:set -DnewVerionxx命令去更改每一个子模块的版本号&#xff0c;非常的不方便&#xff0c;而且会改动所有的模块&#xff0c;出现如下…

Vue语法(4)

目录 1. 自定义指令 1.1 使用方法 1.2 实际案例 1.3 全局指令和局部指令 2. 组件对象 2.1 组件基础 2.2 组件对象 2.3 组件的属性——props 2.4 全局组件和局部组件 2.5 单文件组件 1. 概念&#xff1a; 2. 配置开发环境的指令&#xff1a; 3. 单文件组…

云迁移为业务赋能,跨出数字化转型第一步

新钛云服已累计为您分享752篇技术干货 云迁移如何赋能企业业务 随着科技的迅猛发展和数字化转型的浪潮席卷全球&#xff0c;越来越多的企业开始意识到云计算的重要性和潜力。在这个数字化时代&#xff0c;企业不再满足于传统的IT架构和数据中心&#xff0c;而是追求更高效、灵活…

《JAX可微分编程》包邮送书五本

文章目录 前言JAX到底是什么&#xff1f;书籍内容介绍包邮送书5本 前言 2015年&#xff0c;Google Brain开放了一个名为「TensorFlow」的研究项目&#xff0c;这款产品迅速流行并成为人工智能业界的主流深度学习框架&#xff0c;塑造了现代机器学习的生态系统。 7年后&#x…

Shell脚本文本三剑客之sed编辑器

目录 一、sed编辑器简介 二、sed工作流程 三、sed命令 四、sed命令的使用 1.sed打印文件内容&#xff08;p&#xff09; &#xff08;1&#xff09;打印文件所有行 &#xff08;2&#xff09;打印文件指定行 2.sed增加、插入、替换行&#xff08;a、i、c&#xff09; …

CVPR 2023 | 视频AIGC,预测/插帧/生成/编辑

1、A Dynamic Multi-Scale Voxel Flow Network for Video Prediction 视频预测&#xff08;video prediction&#xff09;的性能已经通过先进的深度神经网络大幅提高。然而&#xff0c;大多数当前的方法存在着大的模型尺寸和需要额外的输入&#xff08;如&#xff0c;语义/深度…

【Instruction Tuning】ChatGLM 微调实战(附源码)

在之前的文章中&#xff0c;我们已经讲过了 ChatGPT 的三个主要流程&#xff1a; SFT&#xff1a;通过 Instruction Tuning 来微调一个监督学习模型。Reward Model&#xff1a;通过排序序列来训练一个打分模型。Reinforcement Learning&#xff1a;通过强化学习来进一步优化模…

【MySQL新手入门系列一】:手把手教你入门MySQL

如果您是一位刚刚开始学习MySQL的新手&#xff0c;本文将为您提供一些实用的入门知识和技巧&#xff0c;帮助您快速上手。 本篇文章将以windows为例&#xff0c;介绍MySQL的基础知识&#xff0c;以及如何安装、卸载、配置和使用它。 导读 一、概览1.1 MySQL是什么1.2 为什么要学…

一文掌握linux网络相关命令

欢迎关注博主 Mindtechnist 或加入【Linux C/C/Python社区】一起学习和分享Linux、C、C、Python、Matlab&#xff0c;机器人运动控制、多机器人协作&#xff0c;智能优化算法&#xff0c;滤波估计、多传感器信息融合&#xff0c;机器学习&#xff0c;人工智能等相关领域的知识和…

阿里企业邮箱登录入口

阿里企业邮箱登录入口&#xff1a;https://qiye.aliyun.com/ 阿里企业邮箱可以使用邮箱账号登录&#xff0c;也可以使用钉钉账号登录&#xff0c;打开登录入口&#xff0c;如下图&#xff1a; 阿里企业邮箱登录入口 企业邮箱购买页面&#xff1a;aliyunbaike.com/go/mail免费企…

归并排序和快速排序(C++)

归并排序是一种经典的排序算法&#xff0c;也被称为“归并算法”。它的基本思想是将待排序数组分成若干个子数组&#xff0c;每个子数组都是有序的&#xff0c;然后将这些子数组合并成一个大的有序数组。 具体实现过程如下&#xff1a; 将待排序数组不断划分为左右两个子数组&…

IMX6ULL裸机篇之SPI实验-SPI主控代码实现

一. SPI 实验 SPI实验&#xff1a;学习如何使用 I.MX6U 的 SPI 接口来驱动 ICM-20608&#xff0c;读取 ICM-20608 的六轴数据。 本文学习 SPI主控芯片的代码编写。其中&#xff0c;包括SPI工作模式设置&#xff0c;主从模式设置&#xff0c;时钟配置等实现。 二. SPI 主控芯…

光学介质材料——光学膜

手机、平板、智能电视等设备之所以能够发光发亮离不开一个重要的组成材料——光学膜。那光学膜是什么回事呢&#xff1f; 光学膜是指在光学元件或独立基板上&#xff0c;制镀或涂布一层或多层介电质膜或金属膜或这两类膜的组合&#xff0c;以改变光波的传递特性&#xff0c;包…

MySQL索引:让你的数据库查询快到起飞!

&#x1f495;世界上最美好的东西之一&#xff0c;就是你每天都有机会开始全新的一天。&#x1f495; &#x1f43c;作者&#xff1a;不能再留遗憾了&#x1f43c; &#x1f386;专栏&#xff1a;MySQL学习&#x1f386; &#x1f697;本文章主要内容&#xff1a;详细介绍如何查…

SSD、内存和 L1 Cache 相比速度差多少倍

一道面试题&#xff1a;SSD、内存和 L1 Cache 相比速度差多少倍&#xff1f; 其实比起复杂的技术问题&#xff0c;我更喜欢在面试中提问这种像生活常识一样的简单问题。因为我觉得&#xff0c;复杂的问题是由简单的问题组成的&#xff0c;如果你把简单的问题学扎实了&#xff…

自动化运维工具—Ansible

一、Ansible概述 1.1 Ansible是什么 Ansible是一个基于Python开发的配置管理和应用部署工具&#xff0c;现在也在自动化管理领域大放异彩。它融合了众多老牌运维工具的优点&#xff0c;Pubbet和Saltstack能实现的功能&#xff0c;Ansible基本上都可以实现。 Ansible能批量配…

面试问题总结---嵌入式部分和项目部分

1、本栏用来记录社招找工作过程中的内容,包括基础知识学习以及面试问题的记录等,以便于后续个人回顾学习; 暂时只有2023年3月份,第一次社招找工作的过程; 2、个人经历: 研究生期间课题是SLAM在无人机上的应用,有接触SLAM、Linux、ROS、C/C++、DJI OSDK等; 3、参加工作后…

面试问题总结----ROS部分

1、本栏用来记录社招找工作过程中的内容,包括基础知识学习以及面试问题的记录等,以便于后续个人回顾学习; 暂时只有2023年3月份,第一次社招找工作的过程; 2、个人经历: 研究生期间课题是SLAM在无人机上的应用,有接触SLAM、Linux、ROS、C/C++、DJI OSDK等; 3、参加工作后…