前言
软硬件介绍:STM32F429BIT(反客的一块板子,挺适合拿来学习ThreadX的); 网卡型号:DP83848 ThreadX版本:6.1.3; NetX DUO版本:6.1.3; IDE:KEIL5 v5.31.0.0版本、STM32CubeMX; ARM编译器:AC5
一、DP83848驱动
使用STM32CubeMX配置DP83848,生成裸机工程。配置界面选择正确的PHY型号,并打开ETH中断。 示例:根据PHY数据手册,时钟不得低于25Mhz。
二、NetX DUO移植
1.移植ThreadX
ThreadX移植可参考前几篇文章,这里不再赘述。
2.添加NetX DUO文件
添加NetX DUO源码的common和ports文件夹到工程。
3.NetX DUO驱动
参考官方提供的摸板开发驱动,基本直接拷贝官方的驱动,修改完错误即可。
https://github.com/azure-rtos/samples/tags
注:①硬件初始化函数下的ETH初始化前,需要加延时,否则初始化报错。
代码如下(示例):
EthHandle.Instance = ETH;
EthHandle.Init.MACAddr = _nx_driver_hardware_address;
EthHandle.Init.AutoNegotiation = ETH_AUTONEGOTIATION_ENABLE;
EthHandle.Init.Speed = ETH_SPEED_100M;
EthHandle.Init.DuplexMode = ETH_MODE_FULLDUPLEX;
EthHandle.Init.MediaInterface = ETH_MEDIA_INTERFACE_RMII;
EthHandle.Init.RxMode = ETH_RXINTERRUPT_MODE;
EthHandle.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE;
EthHandle.Init.PhyAddress = DP83848_PHY_ADDRESS;
HAL_Delay(0x000000FF);
HAL_Delay(0x000000FF);
if (HAL_ETH_Init(&EthHandle) != HAL_OK)
{
return(NX_DRIVER_ERROR);
}
②重定义HAL_GetTick函数 代码如下(示例):
uint32_t HAL_GetTick (void)
{
static uint32_t ticks = 0U;
uint32_t i;
if (_tx_thread_system_state == TX_INITIALIZE_IS_FINISHED)
{
return ((uint32_t)_tx_time_get());
}
for (i = (SystemCoreClock >> 14U); i > 0U; i--)
{
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
}
return ++ticks;
}
4.PING测试
下面提供一个PING测试代码:
NX_PACKET_POOL pool_0;
NX_IP ip_0;
ULONG ip_thread_stack[2 * 1024 / sizeof(ULONG)];
#define NX_PACKET_POOL_SIZE ((1536 + sizeof(NX_PACKET)) * 60)
ULONG packet_pool_area[NX_PACKET_POOL_SIZE/4 + 4];
ULONG arp_space_area[512 / sizeof(ULONG)];
ULONG error_counter;
UINT status;
void PingTest(void)
{
nx_system_initialize();
status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 1536, (ULONG*)(((int)packet_pool_area + 15) & ~15) , NX_PACKET_POOL_SIZE);
if (status)
error_counter++;
status = nx_ip_create(&ip_0,
"NetX IP Instance 0",
IP_ADDRESS(192, 168, 1, 33),
0xFFFFFF00,
&pool_0, nx_driver_stm32f429,
(UCHAR*)ip_thread_stack,
sizeof(ip_thread_stack),
1);
if (status)
error_counter++;
status = nx_arp_enable(&ip_0, (void *)arp_space_area, sizeof(arp_space_area));
if (status)
error_counter++;
status = nx_tcp_enable(&ip_0);
if (status)
error_counter++;
status = nx_udp_enable(&ip_0);
if (status)
error_counter++;
status = nx_icmp_enable(&ip_0);
if (status)
error_counter++;
}
|