STM32H723 W6100总线环回程序
转发: STM32H723 W6100 BUS Loopback Program (wiznet.io)
项目介绍
1. 硬件设置
1)物理连接图
2) 插针连接
2.软件设置
1)FMC套
地址和数据引脚设置如下。 必须启用写操作才能写入数据。 通过减少定时设置来减少信号长度,可以有效地发送和接收数据。
2)M7缓存组
启用CPU DCache 并设置MPU Control,如下所示。
将Base Addr设置为0x60000000,FMC addr,将大小设置为64KB,并按如下方式更改访问权限以使访问成为可能。
3.代码编辑
1) Io6Library 库设置
右键单击该项目,您将看到下面的菜单。 单击属性。
在源位置下,选择链接文件夹
选中链接到文件夹的复选框。 按变量选择 PROJECT_LOC。 从这里输入 io6 库的位置。 在上面输入文件夹名称。
选择“包括”窗口并添加路径,如下所示。
2)主要代码
- 包括
#include "stdio.h"
#include "w6100.h"
#include "wizchip_conf.h"
- 网络信息数据
wiz_NetInfo gWIZNETINFO = { .mac = {0x00,0x08,0xdc,0x34,0x56,0x78},
.ip = {192,168,15,111},
.sn = {255, 255, 255, 0},
.gw = {192, 168, 15, 1},
.dns = {168, 126, 63, 1},
//.dhcp = NETINFO_STATIC,
.lla={0xfe,0x80,0x00,0x00,
0x00,0x00, 0x00,0x00,
0x02,0x08, 0xdc,0xff,
0xfe,0x57, 0x57,0x25}, ///< Source Link Local Address
.gua={0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00}, ///< Source Global Unicast Address
.sn6={0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 }, ///< IPv6 Prefix
.gw6={0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00} ///< Gateway IPv6 Address
};
uint8_t WIZ_Dest_IP_virtual[4] = {192, 168, 0, 230}; //DST_IP Address
uint8_t WIZ_Dest_IP_Google[4] = {216, 58, 200, 174}; //DST_IP Address
uint8_t mcastipv4_0[4] ={239,1,2,3};
uint8_t mcastipv4_1[4] ={239,1,2,4};
uint8_t mcastipv4_2[4] ={239,1,2,5};
uint8_t mcastipv4_3[4] ={239,1,2,6};
uint16_t WIZ_Dest_PORT = 15000; //DST_IP port
#define ETH_MAX_BUF_SIZE 1024
- W6100读/写功能
void W6100BusWriteByte(uint32_t addr, iodata_t data)
{
(*(__IO uint8_t *)((uint32_t)(addr)) = (data));
}
iodata_t W6100BusReadByte(uint32_t addr)
{
ret = *(__IO uint8_t *)(addr);
return ret;
}
- W6100初始化
void W6100Initialze(void)
{
//W6100Reset();
#if _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_
/* SPI method callback registration */
#if defined SPI_DMA
reg_wizchip_spi_cbfunc(W6100SpiReadByte, W6100SpiWriteByte, W6100SpiReadBurst, W6100SpiWriteBurst);
#else
reg_wizchip_spi_cbfunc(W6100SpiReadByte, W6100SpiWriteByte, 0, 0);
#endif
/* CS function register */
reg_wizchip_cs_cbfunc(W6100CsEnable, W6100CsDisable);
#else
/* Indirect bus method callback registration */
#if defined BUS_DMA
reg_wizchip_bus_cbfunc(W6100BusReadByte, W6100BusWriteByte, W6100BusReadBurst, W6100BusWriteBurst);
#else
reg_wizchip_bus_cbfunc(W6100BusReadByte, W6100BusWriteByte, 0, 0);
#endif
reg_wizchip_cs_cbfunc(W6100CsEnable, W6100CsDisable);
#endif
uint8_t temp;
unsigned char W6100_AdrSet[2][8] = {{2, 2, 2, 2, 2, 2, 2, 2}, {2, 2, 2, 2, 2, 2, 2, 2}};
uint16_t RegTemp = 0;
//RegTemp = (uint16_t)WIZCHIP_READ(_CIDR_);
//printf("CIDR_ = %04x \r\n", RegTemp);
RegTemp = getCIDR();
printf("CIDR = %04x \r\n", RegTemp);
RegTemp = getVER();
printf("VER = %04x \r\n", RegTemp);
#if 0 //teddy st
do
{
if (ctlwizchip(CW_GET_PHYLINK, (void *)&temp) == -1)
{
printf("Unknown PHY link status.\r\n");
}
} while (temp == PHY_LINK_OFF);
#endif
printf("PHY OK.\r\n");
}
- 主功能
W6100Initialze();
ctlwizchip(CW_SYS_UNLOCK,& syslock);
ctlnetwork(CN_SET_NETINFO,&gWIZNETINFO);
printf("Register value after W6100 initialize!\r\n");
print_network_information();
- 环回
loopback_tcps(0,ethBuf3,50003,AS_IPV4);
4. 测试
1)程序日志
2)hercules TCP客户端测试
文件