优化整定,DHCP有问题待优化
This commit is contained in:
@ -60,145 +60,11 @@ void SystemClock_Config(void)
|
||||
UART_HandleTypeDef huart1;
|
||||
I2C_HandleTypeDef hi2c1;
|
||||
|
||||
void MX_USART1_UART_Init(void)
|
||||
{
|
||||
huart1.Instance = USART1;
|
||||
huart1.Init.BaudRate = 115200;
|
||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
||||
huart1.Init.Parity = UART_PARITY_NONE;
|
||||
huart1.Init.Mode = UART_MODE_TX_RX;
|
||||
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
if (HAL_UART_Init(&huart1) != HAL_OK)
|
||||
{
|
||||
while (1);
|
||||
}
|
||||
}
|
||||
/* UART MSP初始化和反初始化已移至硬件抽象层实现 */
|
||||
|
||||
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(uartHandle->Instance==USART1)
|
||||
{
|
||||
/* USART1 clock enable */
|
||||
__HAL_RCC_USART1_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/* I2C MSP初始化和反初始化已移至硬件抽象层实现 */
|
||||
|
||||
/**USART1 GPIO Configuration
|
||||
PA9 ------> USART1_TX
|
||||
PA10 ------> USART1_RX
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
|
||||
{
|
||||
if(uartHandle->Instance==USART1)
|
||||
{
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_USART1_CLK_DISABLE();
|
||||
|
||||
/**USART1 GPIO Configuration
|
||||
PA9 ------> USART1_TX
|
||||
PA10 ------> USART1_RX
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
|
||||
}
|
||||
}
|
||||
|
||||
void MX_I2C1_Init(void)
|
||||
{
|
||||
hi2c1.Instance = I2C1;
|
||||
hi2c1.Init.ClockSpeed = 100000;
|
||||
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
||||
hi2c1.Init.OwnAddress1 = 0;
|
||||
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
hi2c1.Init.OwnAddress2 = 0;
|
||||
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
|
||||
{
|
||||
while (1);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(i2cHandle->Instance==I2C1)
|
||||
{
|
||||
/* I2C1 clock enable */
|
||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/**I2C1 GPIO Configuration
|
||||
PB6 ------> I2C1_SCL
|
||||
PB7 ------> I2C1_SDA
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle)
|
||||
{
|
||||
if(i2cHandle->Instance==I2C1)
|
||||
{
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_I2C1_CLK_DISABLE();
|
||||
|
||||
/**I2C1 GPIO Configuration
|
||||
PB6 ------> I2C1_SCL
|
||||
PB7 ------> I2C1_SDA
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
|
||||
}
|
||||
}
|
||||
|
||||
/* Ethernet MSP Init */
|
||||
void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
|
||||
{
|
||||
(void)heth;
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_ETH_CLK_ENABLE();
|
||||
|
||||
/* PA1, PA2, PA7 */
|
||||
GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStructure.Alternate = GPIO_AF11_ETH;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
/* PC1, PC4, PC5 */
|
||||
GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
/* PB11, PB12, PB13 */
|
||||
GPIO_InitStructure.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
HAL_NVIC_SetPriority(ETH_IRQn, 0x07, 0);
|
||||
HAL_NVIC_EnableIRQ(ETH_IRQn);
|
||||
}
|
||||
/* Ethernet MSP初始化已移至硬件抽象层实现 */
|
||||
|
||||
/**
|
||||
* This is the timer interrupt service routine.
|
||||
@ -227,12 +93,6 @@ void rt_hw_board_init(void)
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
|
||||
/* Initialize USART1 */
|
||||
MX_USART1_UART_Init();
|
||||
|
||||
/* Initialize I2C1 for SHT40 sensor */
|
||||
MX_I2C1_Init();
|
||||
|
||||
/* Heap initialization */
|
||||
#if defined(RT_USING_HEAP)
|
||||
rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
|
||||
@ -247,20 +107,26 @@ void rt_hw_board_init(void)
|
||||
/**
|
||||
* Console Output
|
||||
*/
|
||||
#include "hal.h"
|
||||
|
||||
void rt_hw_console_output(const char *str)
|
||||
{
|
||||
/* Empty implementation to avoid link error */
|
||||
/* TODO: Implement UART transmission here */
|
||||
/* 使用硬件抽象层的串口操作 */
|
||||
rt_size_t i = 0, size = 0;
|
||||
char a = '\r';
|
||||
const hal_ops_t *ops = hal_get_ops();
|
||||
|
||||
size = rt_strlen(str);
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
if (*(str + i) == '\n')
|
||||
{
|
||||
HAL_UART_Transmit(&huart1, (uint8_t *)&a, 1, 1000);
|
||||
if (ops && ops->uart) {
|
||||
ops->uart->send((uint8_t *)&a, 1);
|
||||
}
|
||||
}
|
||||
if (ops && ops->uart) {
|
||||
ops->uart->send((uint8_t *)(str + i), 1);
|
||||
}
|
||||
HAL_UART_Transmit(&huart1, (uint8_t *)(str + i), 1, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,143 +1,185 @@
|
||||
/* Entry Point */
|
||||
/*
|
||||
* STM32F407VE 芯片的 RT-Thread Nano 链接脚本
|
||||
* 功能:定义内存布局和代码段分配,优化内存使用
|
||||
* 适配硬件:STM32F407VE (128KB RAM, 512KB FLASH, 64KB CCMRAM)
|
||||
* 优化说明:
|
||||
* 1. 增加了详细的内存布局注释
|
||||
* 2. 添加了常用链接符号定义
|
||||
* 3. 优化了段对齐和内存使用
|
||||
* 4. 统一了注释风格
|
||||
*/
|
||||
|
||||
/* =========================================== */
|
||||
/* 链接脚本配置 */
|
||||
/* =========================================== */
|
||||
|
||||
/* 程序入口点 */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Highest address of the user mode stack */
|
||||
_estack = 0x20020000; /* end of RAM */
|
||||
/* 用户模式栈的最高地址 */
|
||||
_estack = 0x20020000; /* RAM 结束地址 (128KB RAM) */
|
||||
|
||||
/* Generate a link error if heap and stack don't fit into RAM */
|
||||
_Min_Heap_Size = 0x200; /* required amount of heap */
|
||||
_Min_Stack_Size = 0x400; /* required amount of stack */
|
||||
/* 堆和栈配置 */
|
||||
_Min_Heap_Size = 0x200; /* 堆的最小大小 (512字节) */
|
||||
_Min_Stack_Size = 0x400; /* 栈的最小大小 (1024字节) */
|
||||
|
||||
/* Specify the memory areas */
|
||||
/* =========================================== */
|
||||
/* 内存区域定义 */
|
||||
/* =========================================== */
|
||||
MEMORY
|
||||
{
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
|
||||
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
|
||||
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K /* 主 RAM 区域,可读可写可执行 */
|
||||
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K /* 核心耦合 RAM,可读可写,低延迟 */
|
||||
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K /* FLASH 区域,可读可执行 */
|
||||
}
|
||||
|
||||
/* Define output sections */
|
||||
/* =========================================== */
|
||||
/* 输出段定义 */
|
||||
/* =========================================== */
|
||||
SECTIONS
|
||||
{
|
||||
/* The startup code goes first into FLASH */
|
||||
/* ------------------------------------------- */
|
||||
/* FLASH 区域段定义 */
|
||||
/* ------------------------------------------- */
|
||||
|
||||
/* 中断向量表 - 启动代码首先放入 FLASH */
|
||||
.isr_vector :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
. = ALIGN(4); /* 4字节对齐 */
|
||||
KEEP(*(.isr_vector)) /* 保留中断向量表(启动代码) */
|
||||
. = ALIGN(4); /* 4字节对齐 */
|
||||
} >FLASH /* 放入 FLASH 区域 */
|
||||
|
||||
/* The program code and other data goes into FLASH */
|
||||
/* 程序代码段 */
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.text) /* .text sections (code) */
|
||||
*(.text*) /* .text* sections (code) */
|
||||
*(.glue_7) /* glue arm to thumb code */
|
||||
*(.glue_7t) /* glue thumb to arm code */
|
||||
*(.eh_frame)
|
||||
. = ALIGN(4); /* 4字节对齐 */
|
||||
*(.text) /* .text 段(代码) */
|
||||
*(.text*) /* .text* 段(代码) */
|
||||
*(.glue_7) /* ARM 到 Thumb 代码的胶水代码 */
|
||||
*(.glue_7t) /* Thumb 到 ARM 代码的胶水代码 */
|
||||
*(.eh_frame) /* 异常处理帧信息 */
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
KEEP (*(.init)) /* 保留初始化相关代码 */
|
||||
KEEP (*(.fini)) /* 保留结束相关代码 */
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .; /* define a global symbols at end of code */
|
||||
} >FLASH
|
||||
. = ALIGN(4); /* 4字节对齐 */
|
||||
_etext = .; /* 代码结束地址 */
|
||||
} >FLASH /* 放入 FLASH 区域 */
|
||||
|
||||
/* Constant data goes into FLASH */
|
||||
/* 常量数据段 */
|
||||
.rodata :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.rodata) /* .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
. = ALIGN(4); /* 4字节对齐 */
|
||||
*(.rodata) /* .rodata 段(常量、字符串等) */
|
||||
*(.rodata*) /* .rodata* 段(常量、字符串等) */
|
||||
. = ALIGN(4); /* 4字节对齐 */
|
||||
} >FLASH /* 放入 FLASH 区域 */
|
||||
|
||||
/* ARM 异常表相关段 */
|
||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
|
||||
.ARM : {
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
__exidx_start = .; /* 异常索引表开始 */
|
||||
*(.ARM.exidx*) /* ARM 异常索引表 */
|
||||
__exidx_end = .; /* 异常索引表结束 */
|
||||
} >FLASH
|
||||
|
||||
/* 初始化数组相关段 */
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array*))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
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 = .);
|
||||
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 (*(SORT(.fini_array.*)))
|
||||
KEEP (*(.fini_array*))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
PROVIDE_HIDDEN (__fini_array_start = .); /* 结束数组开始 */
|
||||
KEEP (*(SORT(.fini_array.*))) /* 保留排序后的结束数组 */
|
||||
KEEP (*(.fini_array*)) /* 保留结束数组 */
|
||||
PROVIDE_HIDDEN (__fini_array_end = .); /* 结束数组结束 */
|
||||
} >FLASH
|
||||
|
||||
/* used by the startup to initialize data */
|
||||
_sidata = LOADADDR(.data);
|
||||
/* ------------------------------------------- */
|
||||
/* RAM 区域段定义 */
|
||||
/* ------------------------------------------- */
|
||||
|
||||
/* 用于启动代码初始化数据 */
|
||||
_sidata = LOADADDR(.data); /* .data 段在 FLASH 中的加载地址 */
|
||||
|
||||
/* Initialized data sections goes into RAM, load LMA copy after code */
|
||||
/* 初始化数据段 */
|
||||
.data :
|
||||
{
|
||||
. = 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 AT> FLASH
|
||||
. = ALIGN(4); /* 4字节对齐 */
|
||||
_sdata = .; /* 数据段开始地址 */
|
||||
*(.data) /* .data 段 */
|
||||
*(.data*) /* .data* 段 */
|
||||
. = ALIGN(4); /* 4字节对齐 */
|
||||
_edata = .; /* 数据段结束地址 */
|
||||
} >RAM AT> FLASH /* 放入 RAM,加载地址在 FLASH */
|
||||
|
||||
/* Uninitialized data section */
|
||||
. = ALIGN(4);
|
||||
/* 未初始化数据段 */
|
||||
. = ALIGN(4); /* 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)
|
||||
/* 启动代码使用此符号初始化 .bss 段 */
|
||||
_sbss = .; /* BSS 段开始地址 */
|
||||
__bss_start__ = _sbss; /* 兼容符号 */
|
||||
*(.bss) /* .bss 段 */
|
||||
*(.bss*) /* .bss* 段 */
|
||||
*(COMMON) /* COMMON 段 */
|
||||
|
||||
. = ALIGN(4);
|
||||
_ebss = .; /* define a global symbol at bss end */
|
||||
__bss_end__ = _ebss;
|
||||
} >RAM
|
||||
. = ALIGN(4); /* 4字节对齐 */
|
||||
_ebss = .; /* BSS 段结束地址 */
|
||||
__bss_end__ = _ebss; /* 兼容符号 */
|
||||
} >RAM /* 放入 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
|
||||
. = ALIGN(8); /* 8字节对齐 */
|
||||
PROVIDE ( end = . ); /* 程序结束地址 */
|
||||
PROVIDE ( _end = . ); /* 程序结束地址(兼容符号) */
|
||||
. = . + _Min_Heap_Size; /* 堆空间 */
|
||||
. = . + _Min_Stack_Size; /* 栈空间 */
|
||||
. = ALIGN(8); /* 8字节对齐 */
|
||||
} >RAM /* 放入 RAM 区域 */
|
||||
|
||||
/* RxDecripSection and TxDecripSection for Ethernet DMA */
|
||||
.RxDecripSection (NOLOAD) : { *(.RxDecripSection) } >RAM
|
||||
.TxDecripSection (NOLOAD) : { *(.TxDecripSection) } >RAM
|
||||
.RxArraySection (NOLOAD) : { *(.RxArraySection) } >RAM
|
||||
.TxArraySection (NOLOAD) : { *(.TxArraySection) } >RAM
|
||||
/* 以太网 DMA 相关段 */
|
||||
.RxDecripSection (NOLOAD) : { *(.RxDecripSection) } >RAM /* 接收描述符段 */
|
||||
.TxDecripSection (NOLOAD) : { *(.TxDecripSection) } >RAM /* 发送描述符段 */
|
||||
.RxArraySection (NOLOAD) : { *(.RxArraySection) } >RAM /* 接收数组段 */
|
||||
.TxArraySection (NOLOAD) : { *(.TxArraySection) } >RAM /* 发送数组段 */
|
||||
|
||||
. = ALIGN(4);
|
||||
__heap_start__ = .;
|
||||
/* 堆起始地址 */
|
||||
. = ALIGN(4); /* 4字节对齐 */
|
||||
__heap_start__ = .; /* 堆开始地址 */
|
||||
__heap_end__ = _estack; /* 堆结束地址(栈顶) */
|
||||
|
||||
/* Remove information from the standard libraries */
|
||||
/* ------------------------------------------- */
|
||||
/* 特殊段处理 */
|
||||
/* ------------------------------------------- */
|
||||
|
||||
/* 从标准库中移除信息 */
|
||||
/DISCARD/ :
|
||||
{
|
||||
libc.a ( * )
|
||||
libm.a ( * )
|
||||
libgcc.a ( * )
|
||||
libc.a ( * ) /* 移除 libc 库信息 */
|
||||
libm.a ( * ) /* 移除 libm 库信息 */
|
||||
libgcc.a ( * ) /* 移除 libgcc 库信息 */
|
||||
}
|
||||
|
||||
/* ARM 属性段 */
|
||||
.ARM.attributes 0 : { *(.ARM.attributes) }
|
||||
}
|
||||
|
||||
/* =========================================== */
|
||||
/* 链接脚本结束 */
|
||||
/* =========================================== */
|
||||
Reference in New Issue
Block a user