STM32F407移植1588v2(ptpd)

硬件:

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后跟网卡名称 

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

ASP.NET MVC下的四种验证编程方式

ASP.NET MVC采用Model绑定为目标Action生成了相应的参数列表&#xff0c;但是在真正执行目标Action方法之前&#xff0c;还需要对绑定的参数实施验证以确保其有效性&#xff0c;我们将针对参数的验证成为Model绑定。总地来说&#xff0c;我们可以采用4种不同的编程模式来进行针…

DevExpress WPF功能区控件,更轻松创建应用工具栏!(上)

DevExpress WPF的Ribbon、Toolbar和Menus组件以Microsoft Office为灵感&#xff0c;针对WPF开发人员进行了优化&#xff0c;可帮助您在段时间内模拟当今最流行的商业生产力应用程序。 DevExpress WPF拥有120个控件和库&#xff0c;将帮助您交付满足甚至超出企业需求的高性能业…

百度CDN配置TLS

概述 为了保障您互联网通信的安全性和数据完整性&#xff0c;百度智能云CDN提供TLS版本控制功能。您可以根据不同域名的需求&#xff0c;灵活地配置TLS协议版本。 TLS&#xff08;Transport Layer Security&#xff09;即安全传输层协议&#xff0c;在两个通信应用程序之间提…

LeetCode·每日一题·1177. 构建回文串检测·前缀和

作者&#xff1a;小迅 链接&#xff1a;https://leetcode.cn/problems/can-make-palindrome-from-substring/solutions/2309940/qian-zhui-he-zhu-shi-chao-ji-xiang-xi-by-n3ps/ 来源&#xff1a;力扣&#xff08;LeetCode&#xff09; 著作权归作者所有。商业转载请联系作者获…

全景浏览技术在虚拟现实中的应用

随着虚拟现实技术的发展&#xff0c;全景浏览技术越来越受到人们的关注。全景浏览技术是一种可以将场景全方位呈现给用户的虚拟现实技术&#xff0c;可以为用户带来身临其境的视觉和听觉体验。本文将介绍全景浏览技术在虚拟现实中的应用以及如何利用代码实现这些应用。 一、全…

第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果

本节主要学习如何使用Ogre2.3加载粒子效果。为了学习方便&#xff0c;直接将官方粒子模块Sample_ParticleFX单独拿出来编译&#xff0c;学习如何实现粒子效果。 一. 前提须知 如果参考官方示例建议用最新版的Ogre 2.3.1。否则找不到有粒子效果的示例。不要用官网Ogre2.3 scri…

6.17黄金反弹是否到顶,下周开盘如何布局

近期有哪些消息面影响黄金走势&#xff1f;下周黄金多空该如何研判&#xff1f; ​黄金消息面解析&#xff1a;黄金周五(6月16日)小幅收高&#xff0c;但在触及5月以来最低盘中水准后本周以下跌收官。美市尾盘&#xff0c;现货黄金收报1957.68美元/盎司&#xff0c;下跌0.19美…

vmware设置centos客户机和windows宿主机共享文件夹

一、安装内核 kernel-devel 包 yum install gcc yum install kernel-devel-$(uname -r) 注意&#xff0c;如果自己修改过内核版本&#xff0c;需要确保 uname -r 显示的版本和实际使用的内核版本一致。 二、安装 vmware-tools 在vmware上点击菜单&#xff1a;虚拟机->安…

使用Nextcloud搭建私人云盘,并内网穿透实现公网远程访问

文章目录 摘要视频教程1. 环境搭建2. 测试局域网访问3. 内网穿透3.1 ubuntu本地安装cpolar3.2 创建隧道3.3 测试公网访问 4 配置固定http公网地址4.1 保留一个二级子域名4.1 配置固定二级子域名4.3 测试访问公网固定二级子域名 转载自cpolar极点云的文章&#xff1a;使用Nextcl…

LabVIEW开发基于Web数字图像处理

LabVIEW开发基于Web数字图像处理 数字图像处理已在各个领域找到了应用&#xff0c;并已成为一个高度活跃的研究领域。实际实施和实验在教育和研究活动中起着不可或缺的作用。为了方便快捷地实施数字图像处理操作&#xff0c;设计了一个先进的基于Web的数字图像处理虚拟实验室&…

一文搞定C++异常机制(附代码+详细解析)

C异常 1.引文C语言传统的处理错误的方式&#xff1a; 2.C异常概念3.异常的使用3.1 异常的抛出和捕获3.2 异常的重新抛出异常捕获中的内存泄漏问题 3.3异常安全3.4异常规范 4.异常优缺点5.总结&#xff1a; 1.引文 C语言传统的处理错误的方式&#xff1a; 终止程序&#xff0c…

python---列表和元组(5)

元组的相关操作 元组的创建 创建元组的时候指定初始值 元组中的元素也可以是任意类型 通过下标访问元组中的元素 下标从0开始到len-1结束 通过切片来获取元组中的一个部分 使用for循环来遍历元组 使用in 判定元素是否存在 使用index查找元素下标 使用来拼接两个元组 元…

2023年互联网Java面试复习大纲:ZK+Redis+MySQL+Java基础+架构

多数的公司总体上面试都是以自我介绍项目介绍项目细节/难点提问基础知识点考核算法题这个流程下来的。有些公司可能还会问几个实际的场景类的问题&#xff0c;这个环节阿里是必问的&#xff0c;这种问题通常是没有正确答案的&#xff0c;就看个人的理解&#xff0c;个人的积累了…

github action 基于个人项目实践

前言: DevOps 和 Jenkins 作为一名开发&#xff0c;虽然也没有经常听到 Devops &#xff08;研发和运维一体化&#xff09;这个概念&#xff0c;但日常工作中已经无处不在地用着 DevOps 工具。自研也好&#xff0c;基于开源项目改造也好&#xff0c;互联网公司基本都会有自已的…

Django-搭建sysinfo获取系统信息

文章目录 前言一、项目搭建二、主机信息监控三、Celery定时任务和异步任务 前言 使用Django&#xff0c;搭建sysinfo&#xff0c;Linux中,sysinfo是用来获取系统相关信息的结构体 本篇基于&#xff1a;https://github.com/hypersport/sysinfo#readme项目借鉴路径: https://gi…

基于开源大模型Vicuna-13B构建私有制库问答系统

本教程专注在怎么使用已经开源的模型和项目&#xff0c;构建一个可以私有化部署的问答知识库&#xff0c;而且整体效果要有所保障。 主要工作包括&#xff1a; 选择基础模型&#xff0c;openAI&#xff0c;claude 这些商用的&#xff0c;或者其他的开源的&#xff0c;这次我们…

中国金融,如何向科技要答案?

一个科技初创公司&#xff0c;能否凭借科创成果及时获得信贷准入&#xff1f; 一个农民兄弟能否在春播时&#xff0c;获得精准的无抵押贷款&#xff1b;秋收时&#xff0c;通过银行App找到性价比最高的买家&#xff1f; 一家企业&#xff0c;能否通过其生产及交易信息获取线上融…

React diff的原理是什么

一、是什么 跟Vue一致&#xff0c;React通过引入Virtual DOM的概念&#xff0c;极大地避免无效的Dom操作&#xff0c;使我们的页面的构建效率提到了极大的提升 而diff算法就是更高效地通过对比新旧Virtual DOM来找出真正的Dom变化之处 传统diff算法通过循环递归对节点进行依…

WIFI中的频段、信道、信道带宽

一、波长、波速与频率 波长波速/频率 “波速”由“介质”决定。 “频率”由“波源”决定。 “波长”由“介质”(波速V)、“波源”(频率f)共同决定。&#xff08;λV/f&#xff09; 波长&#xff08;wavelength&#xff09;&#xff1a; 指波在一个振动周期内传播的距离。也就…

Flutter自定义系列之折线波动图,心率图,价格走势图

随着前两篇文章的学习&#xff0c;我今天继续给大家演示下简单的自定义之折线波动图&#xff0c;心率图&#xff0c;价格走势图。 这里&#xff0c;我们创建一个自定义的StatefulWidget&#xff0c;用于显示动态的价格线。 我们将使用CustomPaint和CustomPainter来绘制价格线…