本帖最后由 sujingliang 于 2024-9-27 21:49 编辑
为了配置LWIP又花费了不少时间,虽然已有大佬在其他技术网站分享了配置过程,但轮到自己配置还是遇到不少问题。
先分析一下重点需要关注的问题吧:
一、重点
1、原理图上ETH管脚部分有错误,STM32CubeMX默认生成的也是错的
正确的如下:
/**ETH GPIO Configuration
PD7 ------> ETH_RMII_REF_CLK
PD4 ------> ETH_PHY_INTN
PG11 ------> ETH_RMII_TX_EN
PC1 ------> ETH_MDC
PA2 ------> ETH_MDIO
PC4 ------> ETH_RMII_RXD0
PA7 ------> ETH_RMII_CRS_DV
PC5 ------> ETH_RMII_RXD1
PB0 ------> ETH_RMII_TXD0
PB1 ------> ETH_RMII_TXD1
*/
还有跳线JP6要调到PC1
2、要从一个好的模板开始配
完全从头配费时费力,很容易出错。而且STM32H7S78-DK配置需要考虑支持BOOT,APPLI,XIP。所以最好从一个mpu,xspi,EXTMEN_MANAGER、UART4都配好的模板开始。可以从USB_Device\MSC_Standalone例程的ioc文件开始,去掉USB、SD等等就有一个很好的基础。
3、MPU配置很关键
boot
static void MPU_Config(void)
{
MPU_Region_InitTypeDef MPU_InitStruct = {0};
/* Disables the MPU */
HAL_MPU_Disable();
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
MPU_InitStruct.BaseAddress = 0x0;
MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
MPU_InitStruct.SubRegionDisable = 0x87;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER1;
MPU_InitStruct.BaseAddress = 0x90000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_32MB;
MPU_InitStruct.SubRegionDisable = 0x0;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER2;
MPU_InitStruct.BaseAddress = 0x70000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_128MB;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER3;
MPU_InitStruct.BaseAddress = 0x24000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/* Enables the MPU */
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}
appli可能需要重新配置mpu
static void MPU_Config(void)
{
MPU_Region_InitTypeDef MPU_InitStruct = {0};
/* Disables the MPU */
HAL_MPU_Disable();
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
MPU_InitStruct.BaseAddress = 0x0;
MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
MPU_InitStruct.SubRegionDisable = 0x87;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER1;
MPU_InitStruct.BaseAddress = 0x90000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_32MB;
MPU_InitStruct.SubRegionDisable = 0x0;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER2;
MPU_InitStruct.BaseAddress = 0x70000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_128MB;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER3;
MPU_InitStruct.BaseAddress = 0x24020000;
MPU_InitStruct.Size = MPU_REGION_SIZE_32KB;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER4;
MPU_InitStruct.Size = MPU_REGION_SIZE_256B;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER5;
MPU_InitStruct.BaseAddress = 0x24040000;
MPU_InitStruct.Size = MPU_REGION_SIZE_16KB;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/* Enables the MPU */
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}
4、sct
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LOAD_FLASH 0x70000000 0x08000000 { ; load region size_region
ER_ROM 0x70000000 0x08000000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$Sections)
.ANY (+RO)
.ANY (+XO)
}
ER_ITCM 0x00000000 0x00010000 { ;
}
RW_DTCM 0x20000000 0x00010000 { ; RW data
*(STACK, +RW)
*(HEAP, +RW)
}
RW_SRAMAHB 0x30000000 0x8000 {
}
RW_BKPSRAM 0x38800000 0x1000 {
}
RW_RAM 0x24000000 0x00020000 {
.ANY (+RW +ZI)
}
RW_DMARxDscrTab 0x24020000 0x80 {
*(.RxDescripSection)
}
RW_DMATxDscrTab 0x24020080 0x80 {
*(.TxDescripSection)
}
memory_RX_POOL_base 0x24020100 0x8000-0x100 {
*(.Rx_PoolSection)
}
下面需要手工添加:
RW_DMARxDscrTab 0x24020000 0x80 {
*(.RxDescripSection)
}
RW_DMATxDscrTab 0x24020080 0x80 {
*(.TxDescripSection)
}
memory_RX_POOL_base 0x24020100 0x8000-0x100 {
*(.Rx_PoolSection)
}
5、RCC和时钟图
没用HSE、LSE
6、LWIP请参考网友分享吧
二、修改
1、main while(1)增加:
2、print_ip_address();也加到while(1)
如果获取了IP说明网络已经连上了,print_ip_address可以打印出IP。
/* USER CODE BEGIN 0 */
void print_ip_address(void) {
struct netif *netif = netif_default;
ip_addr_t ip_addr = *netif_ip_addr4(netif);
printf("IP Address: %d.%d.%d.%d\n",
ip4_addr1(&ip_addr),
ip4_addr2(&ip_addr),
ip4_addr3(&ip_addr),
ip4_addr4(&ip_addr));
}
/* USER CODE BEGIN 3 */
print_ip_address();
三、效果
四、总结
1、STM32H7S78-DK还是比较新的,目前官方出的软件包也才是第一版,所以原理图、MX、例程上存在问题也可以理解。
2、之前就发现例程中有的带IOC文件,有的不带。现在看来可能是编写的例程的人也发现了MX生成的IOC有问题,代码需要修改,所以为了不误导使用者,就不提供IOC了。所以再遇到没有IOC的例程就要多考虑一下了,这里头可能真有坑。
附IOC配置文件:
LWIP.rar
(4.61 KB)
|