打印
[其他ST产品]

使用keil5中的RL_TCPNet中间件建立一个工程

[复制链接]
楼主: 原来是wjc
手机看帖
扫描二维码
随时随地手机跟帖
21
原来是wjc|  楼主 | 2023-4-19 00:07 | 只看该作者 |只看大图 回帖奖励 |倒序浏览
配置启动文件的中断调用堆栈

使用特权

评论回复
22
原来是wjc|  楼主 | 2023-4-19 00:09 | 只看该作者
RTX系统配置要注意以下几点:1.RTOS kernel Timer要和系统时钟频率相同。2.RL_TCPnet在初始化时会创建2个线程,每个线程给它分配1k的栈空间,"Number of threads whith usr-provied stack size "设置为2;"Total stack size for threads whith user-provied stack size "设置2048,总共2K。待会儿调试窗口看到线程的运行状况。3.定时器线程运行栈设置为512。

使用特权

评论回复
23
原来是wjc|  楼主 | 2023-4-19 00:09 | 只看该作者
中断服务程序使用堆栈介绍

使用特权

评论回复
24
原来是wjc|  楼主 | 2023-4-19 00:10 | 只看该作者
RL_TCPnet在RTXv4中使用的堆栈需求

使用特权

评论回复
25
原来是wjc|  楼主 | 2023-4-19 00:10 | 只看该作者
3.配置NetWork

RTX配置好后,接下来就是配置网络。

NetConfig.c配置基本上不用改。“Local Host Name”可以改成自定义。作用可以不使用IP地址就行访问。如:ping my_host 指令

使用特权

评论回复
26
原来是wjc|  楼主 | 2023-4-19 00:10 | 只看该作者
Net_Config_ETH_0.h的配置:改IP地址和网关,不开启DHCP,将该线程栈设置1024。IPV6可以关掉,其它默认。

使用特权

评论回复
27
原来是wjc|  楼主 | 2023-4-19 00:10 | 只看该作者
Net_Config_UDP.h配置使用默认配置5个socket

使用特权

评论回复
28
原来是wjc|  楼主 | 2023-4-19 00:10 | 只看该作者
Net_Debug.c配置开启相应的服务报警,该报警有3个级别,我选择全部显示,当然也可以只选择errors 级别

使用特权

评论回复
29
原来是wjc|  楼主 | 2023-4-19 00:11 | 只看该作者
4.更改必要的代码

现在大体上基本上配置完了,接下来配置一下复位脚,向udp_socket.c添加代码。注意stdio需要初始化,外部声明stdout_init(),然后在main函数进行初始化。
#include "rl_net.h"
#include "GPIO_STM32F10x.h"//需要手动添加
#include <stdio.h>  //需要手动添加

int32_t udp_sock;                       // UDP socket handle

extern int stdout_init (void);//需要手动添加
void send_udp_data (void);


static void delay_ms (int ms) {
  ms *= (SystemCoreClock/10000);
  while (ms--) { __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); }
}

void GPIO_Configuration(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOA,&GPIO_InitStructure);
}

void PHY_Reset(void)
{
        GPIO_ResetBits(GPIOA,GPIO_Pin_6);
        delay_ms(100);
        GPIO_SetBits(GPIOA,GPIO_Pin_6);
}

使用特权

评论回复
30
原来是wjc|  楼主 | 2023-4-19 00:11 | 只看该作者
更改一下例子代码,这个例子代码的作用是本地UDP接收到0x01 0xAA指令就向目标UDP回显数据。目标IP和端口是192.168.1.220:77,当然这可以自己随意改动
// Notify the user application about UDP socket events.
uint32_t udp_cb_func (int32_t socket, const  NET_ADDR *addr, const uint8_t *buf, uint32_t len) {

  // Data received
  if ((buf[0] == 0x01) && (len == 2)) {
    // Switch LEDs on and off
    // LED_out (buf[1]);
                send_udp_data();
  }
  return (0);
}

// Send UDP data to destination client.
void send_udp_data (void) {

  if (udp_sock > 0) {
    // IPv4 address: 192.168.0.1
    NET_ADDR addr = { NET_ADDR_IP4, 77, 192, 168, 1, 220 };//可以根据自己的IP地址来
    // IPv6 address: [fe80::1c30:6cff:fea2:455e]
//  NET_ADDR addr = { NET_ADDR_IP6, 2000,
//                    0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//                    0x1c, 0x30, 0x6c, 0xff, 0xfe, 0xa2, 0x45, 0x5e };
    uint8_t *sendbuf;

    sendbuf = netUDP_GetBuffer (2);
    sendbuf[0] = 0x01;
    sendbuf[1] = 0xAA;

    netUDP_Send (udp_sock, &addr, sendbuf, 2);
  }
}

使用特权

评论回复
31
原来是wjc|  楼主 | 2023-4-19 00:11 | 只看该作者
主函数添加复位引脚初始化代码
int main (void) {

        stdout_init();
        GPIO_Configuration();
        PHY_Reset();
        printf("PHY_RESET!\r\n");
        netInitialize ();

  // Initialize UDP socket and open port 2000
  udp_sock = netUDP_GetSocket (udp_cb_func);
  if (udp_sock > 0) {
    netUDP_Open (udp_sock, 2000);
  }
}

使用特权

评论回复
32
原来是wjc|  楼主 | 2023-4-19 00:11 | 只看该作者
调试

编译一下没有错误,配置一下工程,生成Hex文件就可以测试啦!

使用特权

评论回复
33
原来是wjc|  楼主 | 2023-4-19 00:12 | 只看该作者
进入Debug调试模式,打开线程窗口可以看到系统创建的2个线程。如果使能其它服务,将会创建其它线程,对应的RTX的Number of Threads的相关配置要更改设置。

使用特权

评论回复
34
原来是wjc|  楼主 | 2023-4-19 00:12 | 只看该作者
连接好串口,查看串口调试助手打印的信息,可以很层次的看见系统运行的情况。可以很清晰的看到,数据通信是按模型层次来一步步传递的。

使用特权

评论回复
35
原来是wjc|  楼主 | 2023-4-19 00:12 | 只看该作者
打开网络调试助手,设置本地IP和远程目标IP。发送数据,就可以看到数据回显,表示通信成功

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则