[STM32H7] STM32 H743驱动W5500进行UDP收发

[复制链接]
2534|29
 楼主| 自动化陈稳 发表于 2023-2-28 01:43 | 显示全部楼层 |阅读模式
前景提要
STM32 H743确实是个好芯片,但是这个MAC只有一个真是让我觉得不太够,想整双MAC的A核芯片玩玩,奈何实在也是没得精力弄Linux,虽然imx6ull也是一个好芯片。。。。

外挂MAC的方案有很多,最后还是选了W5500…
SPI口还是可以的,即是速度拉跨,但是即使10M的以太网也是很不错了,相比串口,CAN啥的
100M不指望了,这个SPI应该也跑不到那么高速吧,已经满足需求了

实际操作
芯片: STM32H743VIT6核心板
X宝买的W5500模块
自己画了个底板,不想用杜邦线,因为杜邦线不太靠谱
————————————————
版权声明:本文为CSDN博主「一只爱做笔记的码农」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/tpoem/article/details/119718534

 楼主| 自动化陈稳 发表于 2023-2-28 01:44 | 显示全部楼层
CubeMX设置
时钟设置
注意,我这个核心板是25M晶振
5101763fcebfe342d2.png
 楼主| 自动化陈稳 发表于 2023-2-28 01:45 | 显示全部楼层
引脚与外设
我这里用的是SPI3,SPI引脚就不说了吧,额外要给模块分:

RST复位引脚
INT外部中断引脚【它的IO库有没有用不知道】
片选CS【这个一定要!!】

6301963fcec10d74b3.png

 楼主| 自动化陈稳 发表于 2023-2-28 01:49 | 显示全部楼层
适配H743和W5500,搭建工程

然后生成CubeMX IDE工程
然后按照那个教程说的去Github上下W5500官方的IO库,下下来,添加好引用关系之后
适配很简单就是对接几个函数指针
简单起见,我这里是裸机环境


 楼主| 自动化陈稳 发表于 2023-2-28 01:49 | 显示全部楼层
 楼主| 自动化陈稳 发表于 2023-2-28 01:49 | 显示全部楼层
 楼主| 自动化陈稳 发表于 2023-2-28 01:49 | 显示全部楼层
基本上对IO库的对接集中在画绿色的两个文件上
按照要求补上操作SPI需要的函数接口,注册到它的IO库上
直接附上我的代码
 楼主| 自动化陈稳 发表于 2023-2-28 01:50 | 显示全部楼层
基本上对IO库的对接集中在画绿色的两个文件上
按照要求补上操作SPI需要的函数接口,注册到它的IO库上
直接附上我的代码
  1. wizchip_conf.c
  1. //****************************************************************************/
  2. //!
  3. //! \file wizchip_conf.c
  4. //! \brief WIZCHIP Config Header File.
  5. //! \version 1.0.1
  6. //! \date 2013/10/21
  7. //! \par  Revision history
  8. //!       <2015/02/05> Notice
  9. //!        The version history is not updated after this point.
  10. //!        Download the latest version directly from GitHub. Please visit the our GitHub repository for ioLibrary.
  11. //!        >> https://github.com/Wiznet/ioLibrary_Driver
  12. //!       <2014/05/01> V1.0.1  Refer to M20140501
  13. //!        1. Explicit type casting in wizchip_bus_readdata() & wizchip_bus_writedata()
  14. //            Issued by Mathias ClauBen.
  15. //!           uint32_t type converts into ptrdiff_t first. And then recoverting it into uint8_t*
  16. //!           For remove the warning when pointer type size is not 32bit.
  17. //!           If ptrdiff_t doesn't support in your complier, You should must replace ptrdiff_t into your suitable pointer type.
  18. //!       <2013/10/21> 1st Release
  19. //! \author MidnightCow
  20. //! \copyright
  21. //!
  22. //! Copyright (c)  2013, WIZnet Co., LTD.
  23. //! All rights reserved.
  24. //!
  25. //! Redistribution and use in source and binary forms, with or without
  26. //! modification, are permitted provided that the following conditions
  27. //! are met:
  28. //!
  29. //!     * Redistributions of source code must retain the above copyright
  30. //! notice, this list of conditions and the following disclaimer.
  31. //!     * Redistributions in binary form must reproduce the above copyright
  32. //! notice, this list of conditions and the following disclaimer in the
  33. //! documentation and/or other materials provided with the distribution.
  34. //!     * Neither the name of the <ORGANIZATION> nor the names of its
  35. //! contributors may be used to endorse or promote products derived
  36. //! from this software without specific prior written permission.
  37. //!
  38. //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  39. //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  40. //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  41. //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  43. //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  44. //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  45. //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  46. //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  47. //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  48. //! THE POSSIBILITY OF SUCH DAMAGE.
  49. //
  50. //*****************************************************************************/
  51. //A20140501 : for use the type - ptrdiff_t
  52. #include <stddef.h>
  53. //
  54. #include "main.h"
  55. #include "stm32h7xx.h"
  56. #include "stm32h7xx_hal.h"
  57. #include "wizchip_conf.h"
  58. #include "spi.h"


  59. /
  60. //M20150401 : Remove ; in the default callback function such as wizchip_cris_enter(), wizchip_cs_select() and etc.
  61. /

  62. /**
  63. * [url=home.php?mod=space&uid=247401]@brief[/url] Default function to enable interrupt.
  64. * [url=home.php?mod=space&uid=536309]@NOTE[/url] This function help not to access wrong address. If you do not describe this function or register any functions,
  65. * null function is called.
  66. */
  67. //void           wizchip_cris_enter(void)           {};
  68. void           wizchip_cris_enter(void)           {__set_PRIMASK(1);}//关中断进临界区

  69. /**
  70. * @brief Default function to disable interrupt.
  71. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  72. * null function is called.
  73. */
  74. //void           wizchip_cris_exit(void)          {};
  75. void           wizchip_cris_exit(void)          {__set_PRIMASK(0);}//开中断退出临界区

  76. /**
  77. * @brief Default function to select chip.
  78. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  79. * null function is called.
  80. */
  81. //void         wizchip_cs_select(void)            {};
  82. void         wizchip_cs_select(void)            {HAL_GPIO_WritePin(W5500_CS_GPIO_Port, W5500_CS_Pin, GPIO_PIN_RESET);}//片选

  83. /**
  84. * @brief Default function to deselect chip.
  85. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  86. * null function is called.
  87. */
  88. //void         wizchip_cs_deselect(void)          {};
  89. void         wizchip_cs_deselect(void)          {HAL_GPIO_WritePin(W5500_CS_GPIO_Port, W5500_CS_Pin, GPIO_PIN_SET);}//关片选

  90. /**
  91. * @brief Default function to read in direct or indirect interface.
  92. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  93. * null function is called.
  94. */
  95. //M20150601 : Rename the function for integrating with W5300
  96. //uint8_t wizchip_bus_readbyte(uint32_t AddrSel) { return * ((volatile uint8_t *)((ptrdiff_t) AddrSel)); }
  97. iodata_t wizchip_bus_readdata(uint32_t AddrSel) { return * ((volatile iodata_t *)((ptrdiff_t) AddrSel)); }//不是W5500的不管

  98. /**
  99. * @brief Default function to write in direct or indirect interface.
  100. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  101. * null function is called.
  102. */
  103. //M20150601 : Rename the function for integrating with W5300
  104. //void         wizchip_bus_writebyte(uint32_t AddrSel, uint8_t wb)  { *((volatile uint8_t*)((ptrdiff_t)AddrSel)) = wb; }
  105. void         wizchip_bus_writedata(uint32_t AddrSel, iodata_t wb)  { *((volatile iodata_t*)((ptrdiff_t)AddrSel)) = wb; }//不是W5500的不管

  106. /**
  107. * @brief Default function to read in SPI interface.
  108. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  109. * null function is called.
  110. */
  111. //uint8_t wizchip_spi_readbyte(void)        {return 0;};
  112. uint8_t wizchip_spi_readbyte(void)//SPI单字节读
  113. {
  114.     uint8_t value;

  115.     if (HAL_SPI_Receive(&hspi3, &value, 1, 1000) != HAL_OK) {
  116.         value = 0;
  117.     }

  118.     return value;
  119. }

  120. /**
  121. * @brief Default function to write in SPI interface.
  122. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  123. * null function is called.
  124. */
  125. //void         wizchip_spi_writebyte(uint8_t wb) {};
  126. void         wizchip_spi_writebyte(uint8_t wb) {
  127.         HAL_SPI_Transmit(&hspi3, &wb, 1, 1000);//SPI单字节写
  128. }

  129. /**
  130. * @brief Default function to burst read in SPI interface.
  131. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  132. * null function is called.
  133. */
  134. //void         wizchip_spi_readburst(uint8_t* pBuf, uint16_t len)         {};
  135. void         wizchip_spi_readburst(uint8_t* pBuf, uint16_t len)
  136. {
  137.     if (!pBuf) {
  138.         return;
  139.     }

  140.     HAL_SPI_Receive(&hspi3, pBuf, len, 1000);//SPI多字节读
  141. }

  142. /**
  143. * @brief Default function to burst write in SPI interface.
  144. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  145. * null function is called.
  146. */
  147. //void         wizchip_spi_writeburst(uint8_t* pBuf, uint16_t len) {};
  148. void         wizchip_spi_writeburst(uint8_t* pBuf, uint16_t len) {
  149.     if (!pBuf) {
  150.         return;
  151.     }

  152.     HAL_SPI_Transmit(&hspi3, pBuf, len, 1000);//SPI多字节写
  153. }

  154. /**
  155. * @\ref _WIZCHIP instance
  156. */
  157. //
  158. //M20150401 : For a compiler didnot support a member of structure
  159. //            Replace the assignment of struct members with the assingment of array
  160. //
  161. /*
  162. _WIZCHIP  WIZCHIP =
  163.       {
  164.       .id                  = _WIZCHIP_ID_,
  165.       .if_mode             = _WIZCHIP_IO_MODE_,
  166.       .CRIS._enter         = wizchip_cris_enter,
  167.       .CRIS._exit          = wizchip_cris_exit,
  168.       .CS._select          = wizchip_cs_select,
  169.       .CS._deselect        = wizchip_cs_deselect,
  170.       .IF.BUS._read_byte   = wizchip_bus_readbyte,
  171.       .IF.BUS._write_byte  = wizchip_bus_writebyte
  172. //    .IF.SPI._read_byte   = wizchip_spi_readbyte,
  173. //    .IF.SPI._write_byte  = wizchip_spi_writebyte
  174.       };
  175. */      
  176. _WIZCHIP  WIZCHIP =
  177. {
  178.     _WIZCHIP_IO_MODE_,
  179.     _WIZCHIP_ID_ ,
  180.     {
  181.         wizchip_cris_enter,
  182.         wizchip_cris_exit
  183.     },
  184.     {
  185.         wizchip_cs_select,
  186.         wizchip_cs_deselect
  187.     },
  188.     {
  189.         {
  190.             //M20150601 : Rename the function
  191.             //wizchip_bus_readbyte,
  192.             //wizchip_bus_writebyte
  193.             wizchip_bus_readdata,
  194.             wizchip_bus_writedata
  195.         },

  196.     }
  197. };

  198. //函数绑定
  199. void w5500_regFunc(void)
  200. {
  201.         reg_wizchip_cris_cbfunc(wizchip_cris_enter, wizchip_cris_exit);
  202.         reg_wizchip_cs_cbfunc(wizchip_cs_select, wizchip_cs_deselect);
  203.         reg_wizchip_spi_cbfunc(wizchip_spi_readbyte, wizchip_spi_writebyte);
  204.         reg_wizchip_spiburst_cbfunc(wizchip_spi_readburst, wizchip_spi_writeburst);
  205. }


  206. static uint8_t    _DNS_[4];      // DNS server ip address
  207. static dhcp_mode  _DHCP_;        // DHCP mode

  208. void reg_wizchip_cris_cbfunc(void(*cris_en)(void), void(*cris_ex)(void))
  209. {
  210.    if(!cris_en || !cris_ex)
  211.    {
  212.       WIZCHIP.CRIS._enter = wizchip_cris_enter;
  213.       WIZCHIP.CRIS._exit  = wizchip_cris_exit;
  214.    }
  215.    else
  216.    {
  217.       WIZCHIP.CRIS._enter = cris_en;
  218.       WIZCHIP.CRIS._exit  = cris_ex;
  219.    }
  220. }

  221. void reg_wizchip_cs_cbfunc(void(*cs_sel)(void), void(*cs_desel)(void))
  222. {
  223.    if(!cs_sel || !cs_desel)
  224.    {
  225.       WIZCHIP.CS._select   = wizchip_cs_select;
  226.       WIZCHIP.CS._deselect = wizchip_cs_deselect;
  227.    }
  228.    else
  229.    {
  230.       WIZCHIP.CS._select   = cs_sel;
  231.       WIZCHIP.CS._deselect = cs_desel;
  232.    }
  233. }

  234. //M20150515 : For integrating with W5300
  235. //void reg_wizchip_bus_cbfunc(uint8_t(*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, uint8_t wb))
  236. void reg_wizchip_bus_cbfunc(iodata_t(*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, iodata_t wb))
  237. {
  238.    while(!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_BUS_));
  239.    //M20150601 : Rename call back function for integrating with W5300
  240.    /*
  241.    if(!bus_rb || !bus_wb)
  242.    {
  243.       WIZCHIP.IF.BUS._read_byte   = wizchip_bus_readbyte;
  244.       WIZCHIP.IF.BUS._write_byte  = wizchip_bus_writebyte;
  245.    }
  246.    else
  247.    {
  248.       WIZCHIP.IF.BUS._read_byte   = bus_rb;
  249.       WIZCHIP.IF.BUS._write_byte  = bus_wb;
  250.    }
  251.    */
  252.    if(!bus_rb || !bus_wb)
  253.    {
  254.       WIZCHIP.IF.BUS._read_data   = wizchip_bus_readdata;
  255.       WIZCHIP.IF.BUS._write_data  = wizchip_bus_writedata;
  256.    }
  257.    else
  258.    {
  259.       WIZCHIP.IF.BUS._read_data   = bus_rb;
  260.       WIZCHIP.IF.BUS._write_data  = bus_wb;
  261.    }
  262. }

  263. void reg_wizchip_spi_cbfunc(uint8_t (*spi_rb)(void), void (*spi_wb)(uint8_t wb))
  264. {
  265.    while(!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_SPI_));
  266.    
  267.    if(!spi_rb || !spi_wb)
  268.    {
  269.       WIZCHIP.IF.SPI._read_byte   = wizchip_spi_readbyte;
  270.       WIZCHIP.IF.SPI._write_byte  = wizchip_spi_writebyte;
  271.    }
  272.    else
  273.    {
  274.       WIZCHIP.IF.SPI._read_byte   = spi_rb;
  275.       WIZCHIP.IF.SPI._write_byte  = spi_wb;
  276.    }
  277. }

  278. // 20140626 Eric Added for SPI burst operations
  279. void reg_wizchip_spiburst_cbfunc(void (*spi_rb)(uint8_t* pBuf, uint16_t len), void (*spi_wb)(uint8_t* pBuf, uint16_t len))
  280. {
  281.    while(!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_SPI_));

  282.    if(!spi_rb || !spi_wb)
  283.    {
  284.       WIZCHIP.IF.SPI._read_burst   = wizchip_spi_readburst;
  285.       WIZCHIP.IF.SPI._write_burst  = wizchip_spi_writeburst;
  286.    }
  287.    else
  288.    {
  289.       WIZCHIP.IF.SPI._read_burst   = spi_rb;
  290.       WIZCHIP.IF.SPI._write_burst  = spi_wb;
  291.    }
  292. }

  293. int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg)
  294. {
  295. #if        _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5500
  296.    uint8_t tmp = 0;
  297. #endif
  298.    uint8_t* ptmp[2] = {0,0};
  299.    switch(cwtype)
  300.    {
  301.       case CW_RESET_WIZCHIP:
  302.          wizchip_sw_reset();
  303.          break;
  304.       case CW_INIT_WIZCHIP:
  305.          if(arg != 0)
  306.          {
  307.             ptmp[0] = (uint8_t*)arg;
  308.             ptmp[1] = ptmp[0] + _WIZCHIP_SOCK_NUM_;
  309.          }
  310.          return wizchip_init(ptmp[0], ptmp[1]);
  311.       case CW_CLR_INTERRUPT:
  312.          wizchip_clrinterrupt(*((intr_kind*)arg));
  313.          break;
  314.       case CW_GET_INTERRUPT:
  315.         *((intr_kind*)arg) = wizchip_getinterrupt();
  316.          break;
  317.       case CW_SET_INTRMASK:
  318.          wizchip_setinterruptmask(*((intr_kind*)arg));
  319.          break;         
  320.       case CW_GET_INTRMASK:
  321.          *((intr_kind*)arg) = wizchip_getinterruptmask();
  322.          break;
  323.    //M20150601 : This can be supported by W5200, W5500
  324.    //#if _WIZCHIP_ > W5100
  325.    #if (_WIZCHIP_ == W5200 || _WIZCHIP_ == W5500)
  326.       case CW_SET_INTRTIME:
  327.          setINTLEVEL(*(uint16_t*)arg);
  328.          break;
  329.       case CW_GET_INTRTIME:
  330.          *(uint16_t*)arg = getINTLEVEL();
  331.          break;
  332.    #endif
  333.       case CW_GET_ID:
  334.          ((uint8_t*)arg)[0] = WIZCHIP.id[0];
  335.          ((uint8_t*)arg)[1] = WIZCHIP.id[1];
  336.          ((uint8_t*)arg)[2] = WIZCHIP.id[2];
  337.          ((uint8_t*)arg)[3] = WIZCHIP.id[3];
  338.          ((uint8_t*)arg)[4] = WIZCHIP.id[4];
  339.          ((uint8_t*)arg)[5] = 0;
  340.          break;
  341.    #if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5500
  342.       case CW_RESET_PHY:
  343.          wizphy_reset();
  344.          break;
  345.       case CW_SET_PHYCONF:
  346.          wizphy_setphyconf((wiz_PhyConf*)arg);
  347.          break;
  348.       case CW_GET_PHYCONF:
  349.          wizphy_getphyconf((wiz_PhyConf*)arg);
  350.          break;
  351.       case CW_GET_PHYSTATUS:
  352.          break;
  353.       case CW_SET_PHYPOWMODE:
  354.          return wizphy_setphypmode(*(uint8_t*)arg);
  355.    #endif
  356.    #if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5500
  357.       case CW_GET_PHYPOWMODE:
  358.          tmp = wizphy_getphypmode();
  359.          if((int8_t)tmp == -1) return -1;
  360.          *(uint8_t*)arg = tmp;
  361.          break;
  362.       case CW_GET_PHYLINK:
  363.          tmp = wizphy_getphylink();
  364.          if((int8_t)tmp == -1) return -1;
  365.          *(uint8_t*)arg = tmp;
  366.          break;
  367.    #endif      
  368.       default:
  369.          return -1;
  370.    }
  371.    return 0;
  372. }


  373. int8_t ctlnetwork(ctlnetwork_type cntype, void* arg)
  374. {
  375.    
  376.    switch(cntype)
  377.    {
  378.       case CN_SET_NETINFO:
  379.          wizchip_setnetinfo((wiz_NetInfo*)arg);
  380.          break;
  381.       case CN_GET_NETINFO:
  382.          wizchip_getnetinfo((wiz_NetInfo*)arg);
  383.          break;
  384.       case CN_SET_NETMODE:
  385.          return wizchip_setnetmode(*(netmode_type*)arg);
  386.       case CN_GET_NETMODE:
  387.          *(netmode_type*)arg = wizchip_getnetmode();
  388.          break;
  389.       case CN_SET_TIMEOUT:
  390.          wizchip_settimeout((wiz_NetTimeout*)arg);
  391.          break;
  392.       case CN_GET_TIMEOUT:
  393.          wizchip_gettimeout((wiz_NetTimeout*)arg);
  394.          break;
  395.       default:
  396.          return -1;
  397.    }
  398.    return 0;
  399. }

  400. void wizchip_sw_reset(void)
  401. {
  402.    uint8_t gw[4], sn[4], sip[4];
  403.    uint8_t mac[6];
  404. //A20150601
  405. #if _WIZCHIP_IO_MODE_  == _WIZCHIP_IO_MODE_BUS_INDIR_
  406.    uint16_t mr = (uint16_t)getMR();
  407.    setMR(mr | MR_IND);
  408. #endif
  409. //
  410.    getSHAR(mac);
  411.    getGAR(gw);  getSUBR(sn);  getSIPR(sip);
  412.    setMR(MR_RST);
  413.    getMR(); // for delay
  414. //A2015051 : For indirect bus mode
  415. #if _WIZCHIP_IO_MODE_  == _WIZCHIP_IO_MODE_BUS_INDIR_
  416.    setMR(mr | MR_IND);
  417. #endif
  418. //
  419.    setSHAR(mac);
  420.    setGAR(gw);
  421.    setSUBR(sn);
  422.    setSIPR(sip);
  423. }

  424. int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
  425. {
  426.    int8_t i;
  427. #if _WIZCHIP_ < W5200
  428.    int8_t j;
  429. #endif
  430.    int8_t tmp = 0;
  431.    wizchip_sw_reset();
  432.    if(txsize)
  433.    {
  434.       tmp = 0;
  435.    //M20150601 : For integrating with W5300
  436.    #if _WIZCHIP_ == W5300
  437.                 for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
  438.                 {
  439.                         if(txsize[i] >= 64) return -1;   //No use 64KB even if W5300 support max 64KB memory allocation
  440.                         tmp += txsize[i];
  441.                         if(tmp > 128) return -1;
  442.                 }
  443.                 if(tmp % 8) return -1;
  444.    #else
  445.                 for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
  446.                 {
  447.                         tmp += txsize[i];

  448.                 #if _WIZCHIP_ < W5200        //2016.10.28 peter add condition for w5100 and w5100s
  449.                         if(tmp > 8) return -1;
  450.                 #else
  451.                         if(tmp > 16) return -1;
  452.                 #endif
  453.                 }
  454.                 for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
  455.                 {
  456.                 #if _WIZCHIP_ < W5200        //2016.10.28 peter add condition for w5100
  457.                         j = 0;
  458.                         while((txsize[i] >> j != 1)&&(txsize[i] !=0)){j++;}
  459.                         setSn_TXBUF_SIZE(i, j);
  460.                 #else
  461.                         setSn_TXBUF_SIZE(i, txsize[i]);
  462.                 #endif
  463.                 }

  464.         #endif
  465.    }

  466.    if(rxsize)
  467.    {
  468.       tmp = 0;
  469.    #if _WIZCHIP_ == W5300
  470.       for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
  471.                 {
  472.                         if(rxsize[i] >= 64) return -1;   //No use 64KB even if W5300 support max 64KB memory allocation
  473.                         tmp += rxsize[i];
  474.                         if(tmp > 128) return -1;
  475.                 }
  476.                 if(tmp % 8) return -1;
  477.    #else
  478.                 for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
  479.                 {
  480.                         tmp += rxsize[i];
  481.                 #if _WIZCHIP_ < W5200        //2016.10.28 peter add condition for w5100 and w5100s
  482.                         if(tmp > 8) return -1;
  483.                 #else
  484.                         if(tmp > 16) return -1;
  485.                 #endif
  486.                 }

  487.                 for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
  488.                 {
  489.                 #if _WIZCHIP_ < W5200        // add condition for w5100
  490.                         j = 0;
  491.                         while((rxsize[i] >> j != 1)&&(txsize[i] !=0)){j++;}
  492.                         setSn_RXBUF_SIZE(i, j);
  493.                 #else
  494.                         setSn_RXBUF_SIZE(i, rxsize[i]);
  495.                 #endif
  496.                 }
  497.         #endif
  498.    }
  499.    return 0;
  500. }

  501. void wizchip_clrinterrupt(intr_kind intr)
  502. {
  503.    uint8_t ir  = (uint8_t)intr;
  504.    uint8_t sir = (uint8_t)((uint16_t)intr >> 8);
  505. #if _WIZCHIP_ < W5500
  506.    ir |= (1<<4); // IK_WOL
  507. #endif
  508. #if _WIZCHIP_ == W5200
  509.    ir |= (1 << 6);
  510. #endif
  511.    
  512. #if _WIZCHIP_ < W5200
  513.    sir &= 0x0F;
  514. #endif

  515. #if _WIZCHIP_ <= W5100S
  516.    ir |= sir;
  517.    setIR(ir);
  518. //A20150601 : For integrating with W5300
  519. #elif _WIZCHIP_ == W5300
  520.    setIR( ((((uint16_t)ir) << 8) | (((uint16_t)sir) & 0x00FF)) );
  521. #else
  522.    setIR(ir);
  523. //M20200227 : For clear
  524.    //setSIR(sir);
  525.    for(ir=0; ir<8; ir++){
  526.        if(sir & (0x01 <<ir) ) setSn_IR(ir, 0xff);
  527.    }

  528. #endif   
  529. }

  530. intr_kind wizchip_getinterrupt(void)
  531. {
  532.    uint8_t ir  = 0;
  533.    uint8_t sir = 0;
  534.    uint16_t ret = 0;
  535. #if _WIZCHIP_ <= W5100S
  536.    ir = getIR();
  537.    sir = ir & 0x0F;
  538. //A20150601 : For integrating with W5300
  539. #elif _WIZCHIP_  == W5300
  540.    ret = getIR();
  541.    ir = (uint8_t)(ret >> 8);
  542.    sir = (uint8_t)ret;
  543. #else
  544.    ir  = getIR();
  545.    sir = getSIR();
  546. #endif         

  547. //M20150601 : For Integrating with W5300
  548. //#if _WIZCHIP_ < W5500
  549. #if _WIZCHIP_ < W5200
  550.    ir &= ~(1<<4); // IK_WOL
  551. #endif
  552. #if _WIZCHIP_ == W5200
  553.    ir &= ~(1 << 6);
  554. #endif
  555.   ret = sir;
  556.   ret = (ret << 8) + ir;
  557.   return (intr_kind)ret;
  558. }

  559. void wizchip_setinterruptmask(intr_kind intr)
  560. {
  561.    uint8_t imr  = (uint8_t)intr;
  562.    uint8_t simr = (uint8_t)((uint16_t)intr >> 8);
  563. #if _WIZCHIP_ < W5500
  564.    imr &= ~(1<<4); // IK_WOL
  565. #endif
  566. #if _WIZCHIP_ == W5200
  567.    imr &= ~(1 << 6);
  568. #endif
  569.    
  570. #if _WIZCHIP_ < W5200
  571.    simr &= 0x0F;
  572.    imr |= simr;
  573.    setIMR(imr);
  574. //A20150601 : For integrating with W5300
  575. #elif _WIZCHIP_ == W5300
  576.    setIMR( ((((uint16_t)imr) << 8) | (((uint16_t)simr) & 0x00FF)) );
  577. #else
  578.    setIMR(imr);
  579.    setSIMR(simr);
  580. #endif   
  581. }

  582. intr_kind wizchip_getinterruptmask(void)
  583. {
  584.    uint8_t imr  = 0;
  585.    uint8_t simr = 0;
  586.    uint16_t ret = 0;
  587. #if _WIZCHIP_ < W5200
  588.    imr  = getIMR();
  589.    simr = imr & 0x0F;
  590. //A20150601 : For integrating with W5300
  591. #elif _WIZCHIP_ == W5300
  592.    ret = getIMR();
  593.    imr = (uint8_t)(ret >> 8);
  594.    simr = (uint8_t)ret;
  595. #else
  596.    imr  = getIMR();
  597.    simr = getSIMR();
  598. #endif         

  599. #if _WIZCHIP_ < W5500
  600.    imr &= ~(1<<4); // IK_WOL
  601. #endif
  602. #if _WIZCHIP_ == W5200
  603.    imr &= ~(1 << 6);  // IK_DEST_UNREACH
  604. #endif
  605.   ret = simr;
  606.   ret = (ret << 8) + imr;
  607.   return (intr_kind)ret;
  608. }

  609. int8_t wizphy_getphylink(void)
  610. {
  611.    int8_t tmp = PHY_LINK_OFF;
  612. #if _WIZCHIP_ == W5100S
  613.    if(getPHYSR() & PHYSR_LNK)
  614.            tmp = PHY_LINK_ON;
  615. #elif   _WIZCHIP_ == W5200
  616.    if(getPHYSTATUS() & PHYSTATUS_LINK)
  617.       tmp = PHY_LINK_ON;
  618. #elif _WIZCHIP_ == W5500
  619.    if(getPHYCFGR() & PHYCFGR_LNK_ON)
  620.       tmp = PHY_LINK_ON;

  621. #else
  622.    tmp = -1;
  623. #endif
  624.    return tmp;
  625. }

  626. #if _WIZCHIP_ > W5100

  627. int8_t wizphy_getphypmode(void)
  628. {
  629.    int8_t tmp = 0;
  630.    #if   _WIZCHIP_ == W5200
  631.       if(getPHYSTATUS() & PHYSTATUS_POWERDOWN)
  632.          tmp = PHY_POWER_DOWN;
  633.       else         
  634.          tmp = PHY_POWER_NORM;
  635.    #elif _WIZCHIP_ == 5500
  636.       if((getPHYCFGR() & PHYCFGR_OPMDC_ALLA) == PHYCFGR_OPMDC_PDOWN)
  637.          tmp = PHY_POWER_DOWN;
  638.       else
  639.          tmp = PHY_POWER_NORM;
  640.    #else
  641.       tmp = -1;
  642.    #endif
  643.    return tmp;
  644. }
  645. #endif

  646. #if _WIZCHIP_ == W5100S
  647. void wizphy_reset(void)
  648. {
  649.         uint16_t tmp = wiz_mdio_read(PHYMDIO_BMCR);
  650.         tmp |= BMCR_RESET;
  651.         wiz_mdio_write(PHYMDIO_BMCR, tmp);
  652.         while(wiz_mdio_read(PHYMDIO_BMCR)&BMCR_RESET){}
  653. }

  654. void wizphy_setphyconf(wiz_PhyConf* phyconf)
  655. {
  656.    uint16_t tmp = wiz_mdio_read(PHYMDIO_BMCR);
  657.    if(phyconf->mode == PHY_MODE_AUTONEGO)
  658.       tmp |= BMCR_AUTONEGO;
  659.    else
  660.    {
  661.           tmp &= ~BMCR_AUTONEGO;
  662.       if(phyconf->duplex == PHY_DUPLEX_FULL)
  663.       {
  664.               tmp |= BMCR_DUP;
  665.       }
  666.       else
  667.       {
  668.               tmp &= ~BMCR_DUP;
  669.       }
  670.       if(phyconf->speed == PHY_SPEED_100)
  671.       {
  672.               tmp |= BMCR_SPEED;
  673.       }
  674.       else
  675.       {
  676.               tmp &= ~BMCR_SPEED;
  677.       }
  678.    }
  679.    wiz_mdio_write(PHYMDIO_BMCR, tmp);
  680. }

  681. void wizphy_getphyconf(wiz_PhyConf* phyconf)
  682. {
  683.    uint16_t tmp = 0;
  684.    tmp = wiz_mdio_read(PHYMDIO_BMCR);
  685.    phyconf->by   = PHY_CONFBY_SW;
  686.    if(tmp & BMCR_AUTONEGO)
  687.    {
  688.            phyconf->mode = PHY_MODE_AUTONEGO;
  689.    }
  690.    else
  691.    {
  692.            phyconf->mode = PHY_MODE_MANUAL;
  693.            if(tmp&BMCR_DUP) phyconf->duplex = PHY_DUPLEX_FULL;
  694.            else phyconf->duplex = PHY_DUPLEX_HALF;
  695.            if(tmp&BMCR_SPEED) phyconf->speed = PHY_SPEED_100;
  696.            else phyconf->speed = PHY_SPEED_10;
  697.    }
  698. }

  699. int8_t wizphy_setphypmode(uint8_t pmode)
  700. {
  701.    uint16_t tmp = 0;
  702.    tmp = wiz_mdio_read(PHYMDIO_BMCR);
  703.    if( pmode == PHY_POWER_DOWN)
  704.    {
  705.       tmp |= BMCR_PWDN;
  706.    }
  707.    else
  708.    {
  709.            tmp &= ~BMCR_PWDN;
  710.    }
  711.    wiz_mdio_write(PHYMDIO_BMCR, tmp);
  712.    tmp = wiz_mdio_read(PHYMDIO_BMCR);
  713.    if( pmode == PHY_POWER_DOWN)
  714.    {
  715.       if(tmp & BMCR_PWDN) return 0;
  716.    }
  717.    else
  718.    {
  719.       if((tmp & BMCR_PWDN) != BMCR_PWDN) return 0;
  720.    }
  721.    return -1;
  722. }

  723. #endif
  724. #if _WIZCHIP_ == W5500
  725. void wizphy_reset(void)
  726. {
  727.    uint8_t tmp = getPHYCFGR();
  728.    tmp &= PHYCFGR_RST;
  729.    setPHYCFGR(tmp);
  730.    tmp = getPHYCFGR();
  731.    tmp |= ~PHYCFGR_RST;
  732.    setPHYCFGR(tmp);
  733. }

  734. void wizphy_setphyconf(wiz_PhyConf* phyconf)
  735. {
  736.    uint8_t tmp = 0;
  737.    if(phyconf->by == PHY_CONFBY_SW)
  738.       tmp |= PHYCFGR_OPMD;
  739.    else
  740.       tmp &= ~PHYCFGR_OPMD;
  741.    if(phyconf->mode == PHY_MODE_AUTONEGO)
  742.       tmp |= PHYCFGR_OPMDC_ALLA;
  743.    else
  744.    {
  745.       if(phyconf->duplex == PHY_DUPLEX_FULL)
  746.       {
  747.          if(phyconf->speed == PHY_SPEED_100)
  748.             tmp |= PHYCFGR_OPMDC_100F;
  749.          else
  750.             tmp |= PHYCFGR_OPMDC_10F;
  751.       }   
  752.       else
  753.       {
  754.          if(phyconf->speed == PHY_SPEED_100)
  755.             tmp |= PHYCFGR_OPMDC_100H;
  756.          else
  757.             tmp |= PHYCFGR_OPMDC_10H;
  758.       }
  759.    }
  760.    setPHYCFGR(tmp);
  761.    wizphy_reset();
  762. }

  763. void wizphy_getphyconf(wiz_PhyConf* phyconf)
  764. {
  765.    uint8_t tmp = 0;
  766.    tmp = getPHYCFGR();
  767.    phyconf->by   = (tmp & PHYCFGR_OPMD) ? PHY_CONFBY_SW : PHY_CONFBY_HW;
  768.    switch(tmp & PHYCFGR_OPMDC_ALLA)
  769.    {
  770.       case PHYCFGR_OPMDC_ALLA:
  771.       case PHYCFGR_OPMDC_100FA:
  772.          phyconf->mode = PHY_MODE_AUTONEGO;
  773.          break;
  774.       default:
  775.          phyconf->mode = PHY_MODE_MANUAL;
  776.          break;
  777.    }
  778.    switch(tmp & PHYCFGR_OPMDC_ALLA)
  779.    {
  780.       case PHYCFGR_OPMDC_100FA:
  781.       case PHYCFGR_OPMDC_100F:
  782.       case PHYCFGR_OPMDC_100H:
  783.          phyconf->speed = PHY_SPEED_100;
  784.          break;
  785.       default:
  786.          phyconf->speed = PHY_SPEED_10;
  787.          break;
  788.    }
  789.    switch(tmp & PHYCFGR_OPMDC_ALLA)
  790.    {
  791.       case PHYCFGR_OPMDC_100FA:
  792.       case PHYCFGR_OPMDC_100F:
  793.       case PHYCFGR_OPMDC_10F:
  794.          phyconf->duplex = PHY_DUPLEX_FULL;
  795.          break;
  796.       default:
  797.          phyconf->duplex = PHY_DUPLEX_HALF;
  798.          break;
  799.    }
  800. }

  801. void wizphy_getphystat(wiz_PhyConf* phyconf)
  802. {
  803.    uint8_t tmp = getPHYCFGR();
  804.    phyconf->duplex = (tmp & PHYCFGR_DPX_FULL) ? PHY_DUPLEX_FULL : PHY_DUPLEX_HALF;
  805.    phyconf->speed  = (tmp & PHYCFGR_SPD_100) ? PHY_SPEED_100 : PHY_SPEED_10;
  806. }

  807. int8_t wizphy_setphypmode(uint8_t pmode)
  808. {
  809.    uint8_t tmp = 0;
  810.    tmp = getPHYCFGR();
  811.    if((tmp & PHYCFGR_OPMD)== 0) return -1;
  812.    tmp &= ~PHYCFGR_OPMDC_ALLA;         
  813.    if( pmode == PHY_POWER_DOWN)
  814.       tmp |= PHYCFGR_OPMDC_PDOWN;
  815.    else
  816.       tmp |= PHYCFGR_OPMDC_ALLA;
  817.    setPHYCFGR(tmp);
  818.    wizphy_reset();
  819.    tmp = getPHYCFGR();
  820.    if( pmode == PHY_POWER_DOWN)
  821.    {
  822.       if(tmp & PHYCFGR_OPMDC_PDOWN) return 0;
  823.    }
  824.    else
  825.    {
  826.       if(tmp & PHYCFGR_OPMDC_ALLA) return 0;
  827.    }
  828.    return -1;
  829. }
  830. #endif


  831. void wizchip_setnetinfo(wiz_NetInfo* pnetinfo)
  832. {
  833.    setSHAR(pnetinfo->mac);
  834.    setGAR(pnetinfo->gw);
  835.    setSUBR(pnetinfo->sn);
  836.    setSIPR(pnetinfo->ip);
  837.    _DNS_[0] = pnetinfo->dns[0];
  838.    _DNS_[1] = pnetinfo->dns[1];
  839.    _DNS_[2] = pnetinfo->dns[2];
  840.    _DNS_[3] = pnetinfo->dns[3];
  841.    _DHCP_   = pnetinfo->dhcp;
  842. }

  843. void wizchip_getnetinfo(wiz_NetInfo* pnetinfo)
  844. {
  845.    getSHAR(pnetinfo->mac);
  846.    getGAR(pnetinfo->gw);
  847.    getSUBR(pnetinfo->sn);
  848.    getSIPR(pnetinfo->ip);
  849.    pnetinfo->dns[0]= _DNS_[0];
  850.    pnetinfo->dns[1]= _DNS_[1];
  851.    pnetinfo->dns[2]= _DNS_[2];
  852.    pnetinfo->dns[3]= _DNS_[3];
  853.    pnetinfo->dhcp  = _DHCP_;
  854. }

  855. int8_t wizchip_setnetmode(netmode_type netmode)
  856. {
  857.    uint8_t tmp = 0;
  858. #if _WIZCHIP_ != W5500
  859.    if(netmode & ~(NM_WAKEONLAN | NM_PPPOE | NM_PINGBLOCK)) return -1;
  860. #else
  861.    if(netmode & ~(NM_WAKEONLAN | NM_PPPOE | NM_PINGBLOCK | NM_FORCEARP)) return -1;
  862. #endif      
  863.    tmp = getMR();
  864.    tmp |= (uint8_t)netmode;
  865.    setMR(tmp);
  866.    return 0;
  867. }

  868. netmode_type wizchip_getnetmode(void)
  869. {
  870.    return (netmode_type) getMR();
  871. }

  872. void wizchip_settimeout(wiz_NetTimeout* nettime)
  873. {
  874.    setRCR(nettime->retry_cnt);
  875.    setRTR(nettime->time_100us);
  876. }

  877. void wizchip_gettimeout(wiz_NetTimeout* nettime)
  878. {
  879.    nettime->retry_cnt = getRCR();
  880.    nettime->time_100us = getRTR();
  881. }

 楼主| 自动化陈稳 发表于 2023-2-28 01:50 | 显示全部楼层
wizchip_conf.h
  1. //*****************************************************************************
  2. //
  3. //! \file wizchip_conf.h
  4. //! \brief WIZCHIP Config Header File.
  5. //! \version 1.0.0
  6. //! \date 2013/10/21
  7. //! \par  Revision history
  8. //!       <2015/02/05> Notice
  9. //!        The version history is not updated after this point.
  10. //!        Download the latest version directly from GitHub. Please visit the our GitHub repository for ioLibrary.
  11. //!        >> https://github.com/Wiznet/ioLibrary_Driver
  12. //!       <2013/10/21> 1st Release
  13. //! \author MidnightCow
  14. //! \copyright
  15. //!
  16. //! Copyright (c)  2013, WIZnet Co., LTD.
  17. //! All rights reserved.
  18. //!
  19. //! Redistribution and use in source and binary forms, with or without
  20. //! modification, are permitted provided that the following conditions
  21. //! are met:
  22. //!
  23. //!     * Redistributions of source code must retain the above copyright
  24. //! notice, this list of conditions and the following disclaimer.
  25. //!     * Redistributions in binary form must reproduce the above copyright
  26. //! notice, this list of conditions and the following disclaimer in the
  27. //! documentation and/or other materials provided with the distribution.
  28. //!     * Neither the name of the <ORGANIZATION> nor the names of its
  29. //! contributors may be used to endorse or promote products derived
  30. //! from this software without specific prior written permission.
  31. //!
  32. //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  33. //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  34. //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  35. //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  36. //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  37. //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  38. //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  39. //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  40. //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  42. //! THE POSSIBILITY OF SUCH DAMAGE.
  43. //
  44. //*****************************************************************************

  45. /**
  46. * @defgroup extra_functions 2. WIZnet Extra Functions
  47. *
  48. * @brief These functions is optional function. It could be replaced at WIZCHIP I/O function because they were made by WIZCHIP I/O functions.  
  49. * [url=home.php?mod=space&uid=1543424]@Details[/url] There are functions of configuring WIZCHIP, network, interrupt, phy, network information and timer. \n
  50. *
  51. */

  52. #ifndef  _WIZCHIP_CONF_H_
  53. #define  _WIZCHIP_CONF_H_

  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif

  57. #include <stdint.h>
  58. /**
  59. * @brief Select WIZCHIP.
  60. * [url=home.php?mod=space&uid=2539868]@Todo[/url] You should select one, \b W5100, \b W5100S, \b W5200, \b W5300, \b W5500 or etc. \n\n
  61. *       ex> <code> #define \_WIZCHIP_      W5500 </code>
  62. */

  63. #define W5100                                                5100
  64. #define W5100S                                                5100+5
  65. #define W5200                                                5200
  66. #define W5300                                                5300
  67. #define W5500                                                5500

  68. #ifndef _WIZCHIP_
  69. #define _WIZCHIP_                      W5500   // W5100, W5100S, W5200, W5300, W5500
  70. #endif

  71. #define _WIZCHIP_IO_MODE_NONE_         0x0000
  72. #define _WIZCHIP_IO_MODE_BUS_          0x0100 /**< Bus interface mode */
  73. #define _WIZCHIP_IO_MODE_SPI_          0x0200 /**< SPI interface mode */
  74. //#define _WIZCHIP_IO_MODE_IIC_          0x0400
  75. //#define _WIZCHIP_IO_MODE_SDIO_         0x0800
  76. // Add to
  77. //

  78. #define _WIZCHIP_IO_MODE_BUS_DIR_      (_WIZCHIP_IO_MODE_BUS_ + 1) /**< BUS interface mode for direct  */
  79. #define _WIZCHIP_IO_MODE_BUS_INDIR_    (_WIZCHIP_IO_MODE_BUS_ + 2) /**< BUS interface mode for indirect */

  80. #define _WIZCHIP_IO_MODE_SPI_VDM_      (_WIZCHIP_IO_MODE_SPI_ + 1) /**< SPI interface mode for variable length data*/
  81. #define _WIZCHIP_IO_MODE_SPI_FDM_      (_WIZCHIP_IO_MODE_SPI_ + 2) /**< SPI interface mode for fixed length data mode*/
  82. #define _WIZCHIP_IO_MODE_SPI_5500_     (_WIZCHIP_IO_MODE_SPI_ + 3) /**< SPI interface mode for fixed length data mode*/

  83. #if   (_WIZCHIP_ == W5100)
  84.    #define _WIZCHIP_ID_                "W5100\0"
  85. /**
  86. * @brief Define interface mode.
  87. * @todo you should select interface mode as chip. Select one of [url=home.php?mod=space&uid=144993]@ref[/url] \_WIZCHIP_IO_MODE_SPI_ , @ref \_WIZCHIP_IO_MODE_BUS_DIR_ or @ref \_WIZCHIP_IO_MODE_BUS_INDIR_
  88. */
  89. //         #define _WIZCHIP_IO_MODE_           _WIZCHIP_IO_MODE_BUS_DIR_
  90. //        #define _WIZCHIP_IO_MODE_           _WIZCHIP_IO_MODE_BUS_INDIR_
  91.               #define _WIZCHIP_IO_MODE_           _WIZCHIP_IO_MODE_SPI_

  92. //A20150601 : Define the unit of IO DATA.   
  93.    typedef   uint8_t   iodata_t;
  94. //A20150401 : Indclude W5100.h file
  95.    #include "W5100/w5100.h"

  96. #elif (_WIZCHIP_ == W5100S)
  97. #define _WIZCHIP_ID_                "W5100S\0"
  98. /**
  99. * @brief Define interface mode.
  100. * @todo you should select interface mode as chip. Select one of @ref \_WIZCHIP_IO_MODE_SPI_ , @ref \_WIZCHIP_IO_MODE_BUS_DIR_ or @ref \_WIZCHIP_IO_MODE_BUS_INDIR_
  101. */
  102. //        #define _WIZCHIP_IO_MODE_           _WIZCHIP_IO_MODE_BUS_INDIR_
  103.         //#define _WIZCHIP_IO_MODE_           _WIZCHIP_IO_MODE_SPI_5500_
  104.         #define _WIZCHIP_IO_MODE_           _WIZCHIP_IO_MODE_SPI_

  105. //A20150601 : Define the unit of IO DATA.
  106.    typedef   uint8_t   iodata_t;
  107. //A20150401 : Indclude W5100.h file
  108.         #include "W5100S/w5100s.h"
  109. #elif (_WIZCHIP_ == W5200)
  110.    #define _WIZCHIP_ID_                "W5200\0"
  111. /**
  112. * @brief Define interface mode.
  113. * @todo you should select interface mode as chip. Select one of @ref \_WIZCHIP_IO_MODE_SPI_ or @ref \        _WIZCHIP_IO_MODE_BUS_INDIR_
  114. */
  115. #ifndef _WIZCHIP_IO_MODE_
  116. // #define _WIZCHIP_IO_MODE_           _WIZCHIP_IO_MODE_BUS_INDIR_
  117.    #define _WIZCHIP_IO_MODE_           _WIZCHIP_IO_MODE_SPI_
  118. #endif
  119. //A20150601 : Define the unit of IO DATA.   
  120.    typedef   uint8_t   iodata_t;
  121.    #include "W5200/w5200.h"
  122. #elif (_WIZCHIP_ == W5500)
  123.   #define _WIZCHIP_ID_                 "W5500\0"
  124.   
  125. /**
  126. * @brief Define interface mode. \n
  127. * @todo Should select interface mode as chip.
  128. *        - @ref \_WIZCHIP_IO_MODE_SPI_ \n
  129. *          -@ref \_WIZCHIP_IO_MODE_SPI_VDM_ : Valid only in @ref \_WIZCHIP_ == W5500 \n
  130. *          -@ref \_WIZCHIP_IO_MODE_SPI_FDM_ : Valid only in @ref \_WIZCHIP_ == W5500 \n
  131. *        - @ref \_WIZCHIP_IO_MODE_BUS_ \n
  132. *          - @ref \_WIZCHIP_IO_MODE_BUS_DIR_ \n
  133. *          - @ref \_WIZCHIP_IO_MODE_BUS_INDIR_ \n
  134. *        - Others will be defined in future. \n\n
  135. *        ex> <code> #define \_WIZCHIP_IO_MODE_ \_WIZCHIP_IO_MODE_SPI_VDM_ </code>
  136. *      
  137. */
  138. #ifndef _WIZCHIP_IO_MODE_
  139.    //#define _WIZCHIP_IO_MODE_           _WIZCHIP_IO_MODE_SPI_FDM_
  140.    #define _WIZCHIP_IO_MODE_           _WIZCHIP_IO_MODE_SPI_VDM_
  141. #endif
  142. //A20150601 : Define the unit of IO DATA.   
  143.    typedef   uint8_t   iodata_t;
  144.    #include "W5500/w5500.h"
  145. #elif ( _WIZCHIP_ == W5300)
  146.    #define _WIZCHIP_ID_                 "W5300\0"
  147. /**
  148. * @brief Define interface mode.
  149. * @todo you should select interface mode as chip. Select one of @ref \_WIZCHIP_IO_MODE_SPI_ , @ref \_WIZCHIP_IO_MODE_BUS_DIR_ or @ref \_WIZCHIP_IO_MODE_BUS_INDIR_
  150. */
  151. #ifndef _WIZCHIP_IO_MODE_
  152.    #define _WIZCHIP_IO_MODE_           _WIZCHIP_IO_MODE_BUS_DIR_
  153. // #define _WIZCHIP_IO_MODE_           _WIZCHIP_IO_MODE_BUS_INDIR_
  154. #endif

  155. //A20150601 : Define the unit and bus width of IO DATA.
  156.    /**
  157.     * @brief Select the data width 8 or 16 bits.
  158.     * @todo you should select the bus width. Select one of 8 or 16.
  159.     */
  160.    #ifndef _WIZCHIP_IO_BUS_WIDTH_
  161.    #define _WIZCHIP_IO_BUS_WIDTH_       16  // 8
  162.    #endif
  163.    #if _WIZCHIP_IO_BUS_WIDTH_ == 8
  164.       typedef   uint8_t   iodata_t;
  165.    #elif _WIZCHIP_IO_BUS_WIDTH_ == 16
  166.       typedef   uint16_t   iodata_t;
  167.    #else
  168.       #error "Unknown _WIZCHIP_IO_BUS_WIDTH_. It should be 8 or 16."       
  169.    #endif
  170. //
  171.    #include "W5300/w5300.h"
  172. #else
  173.    #error "Unknown defined _WIZCHIP_. You should define one of 5100, 5200, and 5500 !!!"
  174. #endif

  175. #ifndef _WIZCHIP_IO_MODE_
  176.    #error "Undefined _WIZCHIP_IO_MODE_. You should define it !!!"
  177. #endif

  178. /**
  179. * @brief Define I/O base address when BUS IF mode.
  180. * @todo Should re-define it to fit your system when BUS IF Mode (@ref \_WIZCHIP_IO_MODE_BUS_,
  181. *       @ref \_WIZCHIP_IO_MODE_BUS_DIR_, @ref \_WIZCHIP_IO_MODE_BUS_INDIR_). \n\n
  182. *       ex> <code> #define \_WIZCHIP_IO_BASE_      0x00008000 </code>
  183. */
  184. #if _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_
  185. //        #define _WIZCHIP_IO_BASE_                                0x60000000        // for 5100S IND
  186.         #define _WIZCHIP_IO_BASE_                                0x68000000        // for W5300
  187. #elif _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_
  188.         #define _WIZCHIP_IO_BASE_                                0x00000000        // for 5100S SPI
  189. #endif

  190. #ifndef _WIZCHIP_IO_BASE_
  191. #define _WIZCHIP_IO_BASE_              0x00000000  // 0x8000
  192. #endif

  193. //M20150401 : Typing Error
  194. //#if _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS
  195. #if _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_
  196.    #ifndef _WIZCHIP_IO_BASE_
  197.       #error "You should be define _WIZCHIP_IO_BASE to fit your system memory map."
  198.    #endif
  199. #endif   

  200. #if _WIZCHIP_ >= W5200
  201.    #define _WIZCHIP_SOCK_NUM_   8   ///< The count of independant socket of @b WIZCHIP
  202. #else
  203.    #define _WIZCHIP_SOCK_NUM_   4   ///< The count of independant socket of @b WIZCHIP
  204. #endif      


  205. /********************************************************
  206. * WIZCHIP BASIC IF functions for SPI, SDIO, I2C , ETC.
  207. *********************************************************/
  208. /**
  209. * @ingroup DATA_TYPE
  210. * @brief The set of callback functions for W5500:@ref WIZCHIP_IO_Functions W5200:@ref WIZCHIP_IO_Functions_W5200
  211. */
  212. typedef struct __WIZCHIP
  213. {
  214.    uint16_t  if_mode;               ///< host interface mode
  215.    uint8_t   id[7];                 ///< @b WIZCHIP ID such as @b 5100, @b 5200, @b 5500, and so on.
  216.    /**
  217.     * The set of critical section callback func.
  218.     */
  219.    struct _CRIS
  220.    {
  221.       void (*_enter)  (void);       ///< crtical section enter
  222.       void (*_exit) (void);         ///< critial section exit  
  223.    }CRIS;  
  224.    /**
  225.     *  The set of @ref \_WIZCHIP_ select control callback func.
  226.     */
  227.    struct _CS
  228.    {
  229.       void (*_select)  (void);      ///< @ref \_WIZCHIP_ selected
  230.       void (*_deselect)(void);      ///< @ref \_WIZCHIP_ deselected
  231.    }CS;  
  232.    /**
  233.     * The set of interface IO callback func.
  234.     */
  235.    union _IF
  236.    {         
  237.       /**
  238.        * For BUS interface IO
  239.        */
  240.       //M20156501 : Modify the function name for integrating with W5300
  241.       //struct
  242.       //{
  243.       //   uint8_t  (*_read_byte)  (uint32_t AddrSel);
  244.       //   void     (*_write_byte) (uint32_t AddrSel, uint8_t wb);
  245.       //}BUS;      
  246.       struct
  247.       {
  248.          iodata_t  (*_read_data)   (uint32_t AddrSel);
  249.          void      (*_write_data)  (uint32_t AddrSel, iodata_t wb);
  250.       }BUS;      

  251.       /**
  252.        * For SPI interface IO
  253.        */
  254.       struct
  255.       {
  256.          uint8_t (*_read_byte)   (void);
  257.          void    (*_write_byte)  (uint8_t wb);
  258.          void    (*_read_burst)  (uint8_t* pBuf, uint16_t len);
  259.          void    (*_write_burst) (uint8_t* pBuf, uint16_t len);
  260.       }SPI;
  261.       // To be added
  262.       //
  263.    }IF;
  264. }_WIZCHIP;

  265. extern _WIZCHIP  WIZCHIP;

  266. /**
  267. * @ingroup DATA_TYPE
  268. *  WIZCHIP control type enumration used in @ref ctlwizchip().
  269. */
  270. typedef enum
  271. {
  272.    CW_RESET_WIZCHIP,   ///< Resets WIZCHIP by softly
  273.    CW_INIT_WIZCHIP,    ///< Initializes to WIZCHIP with SOCKET buffer size 2 or 1 dimension array typed uint8_t.
  274.    CW_GET_INTERRUPT,   ///< Get Interrupt status of WIZCHIP
  275.    CW_CLR_INTERRUPT,   ///< Clears interrupt
  276.    CW_SET_INTRMASK,    ///< Masks interrupt
  277.    CW_GET_INTRMASK,    ///< Get interrupt mask
  278.    CW_SET_INTRTIME,    ///< Set interval time between the current and next interrupt.
  279.    CW_GET_INTRTIME,    ///< Set interval time between the current and next interrupt.
  280.    CW_GET_ID,          ///< Gets WIZCHIP name.

  281. //D20150601 : For no modification your application code
  282. //#if _WIZCHIP_ ==  W5500
  283.    CW_RESET_PHY,       ///< Resets internal PHY. Valid Only W5500
  284.    CW_SET_PHYCONF,     ///< When PHY configured by internal register, PHY operation mode (Manual/Auto, 10/100, Half/Full). Valid Only W5000
  285.    CW_GET_PHYCONF,     ///< Get PHY operation mode in internal register. Valid Only W5500
  286.    CW_GET_PHYSTATUS,   ///< Get real PHY status on operating. Valid Only W5500
  287.    CW_SET_PHYPOWMODE,  ///< Set PHY power mode as normal and down when PHYSTATUS.OPMD == 1. Valid Only W5500
  288. //#endif
  289. //D20150601 : For no modification your application code
  290. //#if _WIZCHIP_ == W5200 || _WIZCHIP_ == W5500
  291.    CW_GET_PHYPOWMODE,  ///< Get PHY Power mode as down or normal, Valid Only W5100, W5200
  292.    CW_GET_PHYLINK      ///< Get PHY Link status, Valid Only W5100, W5200
  293. //#endif
  294. }ctlwizchip_type;

  295. /**
  296. * @ingroup DATA_TYPE
  297. *  Network control type enumration used in @ref ctlnetwork().
  298. */
  299. typedef enum
  300. {
  301.    CN_SET_NETINFO,  ///< Set Network with @ref wiz_NetInfo
  302.    CN_GET_NETINFO,  ///< Get Network with @ref wiz_NetInfo
  303.    CN_SET_NETMODE,  ///< Set network mode as WOL, PPPoE, Ping Block, and Force ARP mode
  304.    CN_GET_NETMODE,  ///< Get network mode as WOL, PPPoE, Ping Block, and Force ARP mode
  305.    CN_SET_TIMEOUT,  ///< Set network timeout as retry count and time.
  306.    CN_GET_TIMEOUT,  ///< Get network timeout as retry count and time.
  307. }ctlnetwork_type;

  308. /**
  309. * @ingroup DATA_TYPE
  310. *  Interrupt kind when CW_SET_INTRRUPT, CW_GET_INTERRUPT, CW_SET_INTRMASK
  311. *  and CW_GET_INTRMASK is used in @ref ctlnetwork().
  312. *  It can be used with OR operation.
  313. */
  314. typedef enum
  315. {
  316. #if   _WIZCHIP_ == W5500
  317.    IK_WOL               = (1 << 4),   ///< Wake On Lan by receiving the magic packet. Valid in W500.
  318. #elif _WIZCHIP_ == W5300
  319.    IK_FMTU              = (1 << 4),   ///< Received a ICMP message (Fragment MTU)   
  320. #endif   

  321.    IK_PPPOE_TERMINATED  = (1 << 5),   ///< PPPoE Disconnected

  322. #if _WIZCHIP_ != W5200
  323.    IK_DEST_UNREACH      = (1 << 6),   ///< Destination IP & Port Unreachable, No use in W5200
  324. #endif   

  325.    IK_IP_CONFLICT       = (1 << 7),   ///< IP conflict occurred

  326.    IK_SOCK_0            = (1 << 8),   ///< Socket 0 interrupt
  327.    IK_SOCK_1            = (1 << 9),   ///< Socket 1 interrupt
  328.    IK_SOCK_2            = (1 << 10),  ///< Socket 2 interrupt
  329.    IK_SOCK_3            = (1 << 11),  ///< Socket 3 interrupt
  330. #if _WIZCHIP_ > W5100S
  331.    IK_SOCK_4            = (1 << 12),  ///< Socket 4 interrupt, No use in 5100
  332.    IK_SOCK_5            = (1 << 13),  ///< Socket 5 interrupt, No use in 5100
  333.    IK_SOCK_6            = (1 << 14),  ///< Socket 6 interrupt, No use in 5100
  334.    IK_SOCK_7            = (1 << 15),  ///< Socket 7 interrupt, No use in 5100
  335. #endif   

  336. #if _WIZCHIP_ > W5100S
  337.    IK_SOCK_ALL          = (0xFF << 8) ///< All Socket interrupt
  338. #else
  339.    IK_SOCK_ALL          = (0x0F << 8) ///< All Socket interrupt
  340. #endif      
  341. }intr_kind;

  342. #define PHY_CONFBY_HW            0     ///< Configured PHY operation mode by HW pin
  343. #define PHY_CONFBY_SW            1     ///< Configured PHY operation mode by SW register   
  344. #define PHY_MODE_MANUAL          0     ///< Configured PHY operation mode with user setting.
  345. #define PHY_MODE_AUTONEGO        1     ///< Configured PHY operation mode with auto-negotiation
  346. #define PHY_SPEED_10             0     ///< Link Speed 10
  347. #define PHY_SPEED_100            1     ///< Link Speed 100
  348. #define PHY_DUPLEX_HALF          0     ///< Link Half-Duplex
  349. #define PHY_DUPLEX_FULL          1     ///< Link Full-Duplex
  350. #define PHY_LINK_OFF             0     ///< Link Off
  351. #define PHY_LINK_ON              1     ///< Link On
  352. #define PHY_POWER_NORM           0     ///< PHY power normal mode
  353. #define PHY_POWER_DOWN           1     ///< PHY power down mode


  354. #if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5500
  355. /**
  356. * @ingroup DATA_TYPE
  357. *  It configures PHY configuration when CW_SET PHYCONF or CW_GET_PHYCONF in W5500,  
  358. *  and it indicates the real PHY status configured by HW or SW in all WIZCHIP. \n
  359. *  Valid only in W5500.
  360. */
  361. typedef struct wiz_PhyConf_t
  362. {
  363.       uint8_t by;       ///< set by @ref PHY_CONFBY_HW or @ref PHY_CONFBY_SW
  364.       uint8_t mode;     ///< set by @ref PHY_MODE_MANUAL or @ref PHY_MODE_AUTONEGO
  365.       uint8_t speed;    ///< set by @ref PHY_SPEED_10 or @ref PHY_SPEED_100
  366.       uint8_t duplex;   ///< set by @ref PHY_DUPLEX_HALF @ref PHY_DUPLEX_FULL
  367.       //uint8_t power;  ///< set by @ref PHY_POWER_NORM or @ref PHY_POWER_DOWN
  368.       //uint8_t link;   ///< Valid only in CW_GET_PHYSTATUS. set by @ref PHY_LINK_ON or PHY_DUPLEX_OFF
  369.    }wiz_PhyConf;
  370. #endif   

  371. /**
  372. * @ingroup DATA_TYPE
  373. *  It used in setting dhcp_mode of @ref wiz_NetInfo.
  374. */
  375. typedef enum
  376. {
  377.    NETINFO_STATIC = 1,    ///< Static IP configuration by manually.
  378.    NETINFO_DHCP           ///< Dynamic IP configruation from a DHCP sever
  379. }dhcp_mode;

  380. /**
  381. * @ingroup DATA_TYPE
  382. *  Network Information for WIZCHIP
  383. */
  384. typedef struct wiz_NetInfo_t
  385. {
  386.    uint8_t mac[6];  ///< Source Mac Address
  387.    uint8_t ip[4];   ///< Source IP Address
  388.    uint8_t sn[4];   ///< Subnet Mask
  389.    uint8_t gw[4];   ///< Gateway IP Address
  390.    uint8_t dns[4];  ///< DNS server IP Address
  391.    dhcp_mode dhcp;  ///< 1 - Static, 2 - DHCP
  392. }wiz_NetInfo;

  393. /**
  394. * @ingroup DATA_TYPE
  395. *  Network mode
  396. */
  397. typedef enum
  398. {
  399. #if _WIZCHIP_ == W5500
  400.    NM_FORCEARP    = (1<<1),  ///< Force to APP send whenever udp data is sent. Valid only in W5500
  401. #endif   
  402.    NM_WAKEONLAN   = (1<<5),  ///< Wake On Lan
  403.    NM_PINGBLOCK   = (1<<4),  ///< Block ping-request
  404.    NM_PPPOE       = (1<<3),  ///< PPPoE mode
  405. }netmode_type;

  406. /**
  407. * @ingroup DATA_TYPE
  408. *  Used in CN_SET_TIMEOUT or CN_GET_TIMEOUT of @ref ctlwizchip() for timeout configruation.
  409. */
  410. typedef struct wiz_NetTimeout_t
  411. {
  412.    uint8_t  retry_cnt;     ///< retry count
  413.    uint16_t time_100us;    ///< time unit 100us
  414. }wiz_NetTimeout;

  415. /**
  416. *@brief Registers call back function for critical section of I/O functions such as
  417. *\ref WIZCHIP_READ, @ref WIZCHIP_WRITE, @ref WIZCHIP_READ_BUF and @ref WIZCHIP_WRITE_BUF.
  418. *@param cris_en : callback function for critical section enter.
  419. *@param cris_ex : callback function for critical section exit.
  420. *@todo Describe @ref WIZCHIP_CRITICAL_ENTER and @ref WIZCHIP_CRITICAL_EXIT marco or register your functions.
  421. *@note If you do not describe or register, default functions(@ref wizchip_cris_enter & @ref wizchip_cris_exit) is called.
  422. */
  423. void reg_wizchip_cris_cbfunc(void(*cris_en)(void), void(*cris_ex)(void));


  424. /**
  425. *@brief Registers call back function for WIZCHIP select & deselect.
  426. *@param cs_sel : callback function for WIZCHIP select
  427. *@param cs_desel : callback fucntion for WIZCHIP deselect
  428. *@todo Describe @ref wizchip_cs_select and @ref wizchip_cs_deselect function or register your functions.
  429. *@note If you do not describe or register, null function is called.
  430. */
  431. void reg_wizchip_cs_cbfunc(void(*cs_sel)(void), void(*cs_desel)(void));

  432. /**
  433. *@brief Registers call back function for bus interface.
  434. *@param bus_rb   : callback function to read byte data using system bus
  435. *@param bus_wb   : callback function to write byte data using system bus
  436. *@todo Describe @ref wizchip_bus_readbyte and @ref wizchip_bus_writebyte function
  437. *or register your functions.
  438. *@note If you do not describe or register, null function is called.
  439. */
  440. //M20150601 : For integrating with W5300
  441. //void reg_wizchip_bus_cbfunc(uint8_t (*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, uint8_t wb));
  442. void reg_wizchip_bus_cbfunc(iodata_t (*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, iodata_t wb));

  443. /**
  444. *@brief Registers call back function for SPI interface.
  445. *@param spi_rb : callback function to read byte using SPI
  446. *@param spi_wb : callback function to write byte using SPI
  447. *@todo Describe \ref wizchip_spi_readbyte and \ref wizchip_spi_writebyte function
  448. *or register your functions.
  449. *@note If you do not describe or register, null function is called.
  450. */
  451. void reg_wizchip_spi_cbfunc(uint8_t (*spi_rb)(void), void (*spi_wb)(uint8_t wb));

  452. /**
  453. *@brief Registers call back function for SPI interface.
  454. *@param spi_rb : callback function to burst read using SPI
  455. *@param spi_wb : callback function to burst write using SPI
  456. *@todo Describe \ref wizchip_spi_readbyte and \ref wizchip_spi_writebyte function
  457. *or register your functions.
  458. *@note If you do not describe or register, null function is called.
  459. */
  460. void reg_wizchip_spiburst_cbfunc(void (*spi_rb)(uint8_t* pBuf, uint16_t len), void (*spi_wb)(uint8_t* pBuf, uint16_t len));

  461. /**
  462. * @ingroup extra_functions
  463. * @brief Controls to the WIZCHIP.
  464. * @details Resets WIZCHIP & internal PHY, Configures PHY mode, Monitor PHY(Link,Speed,Half/Full/Auto),
  465. * controls interrupt & mask and so on.
  466. * @param cwtype : Decides to the control type
  467. * @param arg : arg type is dependent on cwtype.
  468. * [url=home.php?mod=space&uid=266161]@return[/url]  0 : Success \n
  469. *         -1 : Fail because of invalid \ref ctlwizchip_type or unsupported \ref ctlwizchip_type in WIZCHIP
  470. */         
  471. int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg);

  472. /**
  473. * @ingroup extra_functions
  474. * @brief Controls to network.
  475. * @details Controls to network environment, mode, timeout and so on.
  476. * @param cntype : Input. Decides to the control type
  477. * @param arg : Inout. arg type is dependent on cntype.
  478. * @return -1 : Fail because of invalid \ref ctlnetwork_type or unsupported \ref ctlnetwork_type in WIZCHIP \n
  479. *          0 : Success      
  480. */         
  481. int8_t ctlnetwork(ctlnetwork_type cntype, void* arg);


  482. /*
  483. * The following functions are implemented for internal use.
  484. * but You can call these functions for code size reduction instead of ctlwizchip() and ctlnetwork().
  485. */

  486. /**
  487. * @ingroup extra_functions
  488. * @brief Reset WIZCHIP by softly.
  489. */
  490. void   wizchip_sw_reset(void);

  491. /**
  492. * @ingroup extra_functions
  493. * @brief Initializes WIZCHIP with socket buffer size
  494. * @param txsize Socket tx buffer sizes. If null, initialized the default size 2KB.
  495. * @param rxsize Socket rx buffer sizes. If null, initialized the default size 2KB.
  496. * @return 0 : succcess \n
  497. *        -1 : fail. Invalid buffer size
  498. */
  499. int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize);

  500. /**
  501. * @ingroup extra_functions
  502. * @brief Clear Interrupt of WIZCHIP.
  503. * @param intr : @ref intr_kind value operated OR. It can type-cast to uint16_t.
  504. */
  505. void wizchip_clrinterrupt(intr_kind intr);

  506. /**
  507. * @ingroup extra_functions
  508. * @brief Get Interrupt of WIZCHIP.
  509. * @return @ref intr_kind value operated OR. It can type-cast to uint16_t.
  510. */
  511. intr_kind wizchip_getinterrupt(void);

  512. /**
  513. * @ingroup extra_functions
  514. * @brief Mask or Unmask Interrupt of WIZCHIP.
  515. * @param intr : @ref intr_kind value operated OR. It can type-cast to uint16_t.
  516. */
  517. void wizchip_setinterruptmask(intr_kind intr);

  518. /**
  519. * @ingroup extra_functions
  520. * @brief Get Interrupt mask of WIZCHIP.
  521. * @return : The operated OR vaule of @ref intr_kind. It can type-cast to uint16_t.
  522. */
  523. intr_kind wizchip_getinterruptmask(void);

  524. //todo
  525. #if _WIZCHIP_ > W5100
  526.    int8_t wizphy_getphylink(void);              ///< get the link status of phy in WIZCHIP. No use in W5100
  527.    int8_t wizphy_getphypmode(void);             ///< get the power mode of PHY in WIZCHIP. No use in W5100
  528. #endif

  529. #if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5500
  530.    void   wizphy_reset(void);                   ///< Reset phy. Vailid only in W5500
  531. /**
  532. * @ingroup extra_functions
  533. * @brief Set the phy information for WIZCHIP without power mode
  534. * @param phyconf : @ref wiz_PhyConf
  535. */
  536.    void   wizphy_setphyconf(wiz_PhyConf* phyconf);  
  537. /**
  538. * @ingroup extra_functions
  539. * @brief Get phy configuration information.
  540. * @param phyconf : @ref wiz_PhyConf
  541. */
  542.    void   wizphy_getphyconf(wiz_PhyConf* phyconf);
  543. /**
  544. * @ingroup extra_functions
  545. * @brief Get phy status.
  546. * @param phyconf : @ref wiz_PhyConf
  547. */
  548.    void   wizphy_getphystat(wiz_PhyConf* phyconf);
  549. /**
  550. * @ingroup extra_functions
  551. * @brief set the power mode of phy inside WIZCHIP. Refer to @ref PHYCFGR in W5500, @ref PHYSTATUS in W5200
  552. * @param pmode Settig value of power down mode.
  553. */   
  554.    int8_t wizphy_setphypmode(uint8_t pmode);   
  555. #endif

  556. /**
  557. * @ingroup extra_functions
  558. * @brief Set the network information for WIZCHIP
  559. * @param pnetinfo : @ref wizNetInfo
  560. */
  561. void wizchip_setnetinfo(wiz_NetInfo* pnetinfo);

  562. /**
  563. * @ingroup extra_functions
  564. * @brief Get the network information for WIZCHIP
  565. * @param pnetinfo : @ref wizNetInfo
  566. */
  567. void wizchip_getnetinfo(wiz_NetInfo* pnetinfo);

  568. /**
  569. * @ingroup extra_functions
  570. * @brief Set the network mode such WOL, PPPoE, Ping Block, and etc.
  571. * @param pnetinfo Value of network mode. Refer to @ref netmode_type.
  572. */
  573. int8_t wizchip_setnetmode(netmode_type netmode);

  574. /**
  575. * @ingroup extra_functions
  576. * @brief Get the network mode such WOL, PPPoE, Ping Block, and etc.
  577. * @return Value of network mode. Refer to @ref netmode_type.
  578. */
  579. netmode_type wizchip_getnetmode(void);

  580. /**
  581. * @ingroup extra_functions
  582. * @brief Set retry time value(@ref _RTR_) and retry count(@ref _RCR_).
  583. * @details @ref _RTR_ configures the retransmission timeout period and @ref _RCR_ configures the number of time of retransmission.  
  584. * @param nettime @ref _RTR_ value and @ref _RCR_ value. Refer to @ref wiz_NetTimeout.
  585. */
  586. void wizchip_settimeout(wiz_NetTimeout* nettime);

  587. /**
  588. * @ingroup extra_functions
  589. * @brief Get retry time value(@ref _RTR_) and retry count(@ref _RCR_).
  590. * @details @ref _RTR_ configures the retransmission timeout period and @ref _RCR_ configures the number of time of retransmission.  
  591. * @param nettime @ref _RTR_ value and @ref _RCR_ value. Refer to @ref wiz_NetTimeout.
  592. */
  593. void wizchip_gettimeout(wiz_NetTimeout* nettime);
  594. #ifdef __cplusplus
  595. }
  596. #endif

  597. void w5500_regFunc(void);
  598. #endif   // _WIZCHIP_CONF_H_

 楼主| 自动化陈稳 发表于 2023-2-28 01:51 | 显示全部楼层
这边IO库适配完毕
主函数还要再写写初始化W5500的代码
 楼主| 自动化陈稳 发表于 2023-2-28 01:51 | 显示全部楼层
main.c
  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * [url=home.php?mod=space&uid=288409]@file[/url]           : main.c
  5.   * @brief          : Main program body
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  10.   * All rights reserved.</center></h2>
  11.   *
  12.   * This software component is licensed by ST under BSD 3-Clause license,
  13.   * the "License"; You may not use this file except in compliance with the
  14.   * License. You may obtain a copy of the License at:
  15.   *                        opensource.org/licenses/BSD-3-Clause
  16.   *
  17.   ******************************************************************************
  18.   */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22. #include "spi.h"
  23. #include "gpio.h"
  24. #include "w5500.h"
  25. #include "wizchip_conf.h"
  26. #include "string.h"
  27. #include "socket.h"

  28. /* Private includes ----------------------------------------------------------*/
  29. /* USER CODE BEGIN Includes */

  30. /* USER CODE END Includes */

  31. /* Private typedef -----------------------------------------------------------*/
  32. /* USER CODE BEGIN PTD */

  33. /* USER CODE END PTD */

  34. /* Private define ------------------------------------------------------------*/
  35. /* USER CODE BEGIN PD */
  36. /* USER CODE END PD */

  37. /* Private macro -------------------------------------------------------------*/
  38. /* USER CODE BEGIN PM */

  39. /* USER CODE END PM */

  40. /* Private variables ---------------------------------------------------------*/

  41. /* USER CODE BEGIN PV */

  42. /* USER CODE END PV */

  43. /* Private function prototypes -----------------------------------------------*/
  44. void SystemClock_Config(void);
  45. /* USER CODE BEGIN PFP */

  46. /* USER CODE END PFP */

  47. /* Private user code ---------------------------------------------------------*/
  48. /* USER CODE BEGIN 0 */
  49. static void w5500_hard_rst(void)
  50. {
  51.         HAL_GPIO_WritePin(W5500_RST_GPIO_Port, W5500_RST_Pin, GPIO_PIN_RESET);
  52.         HAL_Delay(50);
  53.         HAL_GPIO_WritePin(W5500_RST_GPIO_Port, W5500_RST_Pin, GPIO_PIN_SET);
  54.         HAL_Delay(10);
  55. }


  56. static int w5500_chip_init(void)
  57. {
  58.         return wizchip_init(NULL, NULL);
  59. }

  60. static void w5500_phy_init(void)
  61. {
  62.     wiz_PhyConf conf;

  63.     conf.by = PHY_CONFBY_SW;
  64.     conf.mode = PHY_MODE_MANUAL;
  65.     conf.speed = PHY_SPEED_10;
  66.     conf.duplex = PHY_DUPLEX_FULL;
  67.     wizphy_setphyconf(&conf);
  68. }

  69. static void w5500_network_init(void)
  70. {
  71.     wiz_NetInfo info;

  72.     uint8_t mac[6] = {0x02,0x00,0x00,0x01,0x02,0x03};
  73.     uint8_t ip[4] = {192,168,10,100};
  74.     uint8_t sn[4] = {255,255,255,0};
  75.     uint8_t gw[4] = {192,168,10,1};
  76.     uint8_t dns[4] = {0,0,0,0};

  77.     memcpy(info.mac, mac, 6);
  78.     memcpy(info.ip, ip, 4);
  79.     memcpy(info.sn, sn, 4);
  80.     memcpy(info.gw, gw, 4);
  81.     memcpy(info.dns, dns, 4);

  82.     info.dhcp = NETINFO_STATIC;


  83.     wizchip_setnetinfo(&info);
  84. }

  85. void w5500_init(void)
  86. {
  87.         w5500_hard_rst();//硬件复位W5500
  88.         w5500_regFunc();//绑定SPI函数
  89.         if(w5500_chip_init()!=0)//芯片初始化
  90.         {
  91.                 while(1);
  92.         }
  93.         w5500_phy_init();//物理层初始化
  94.         w5500_network_init();//网络初始化

  95.     wiz_NetInfo info;

  96.     wizchip_getnetinfo(&info);//信息回读
  97. }

  98. /* USER CODE END 0 */

  99. /**
  100.   * @brief  The application entry point.
  101.   * @retval int
  102.   */
  103. uint8_t rxBuf[20]={0};
  104. uint8_t rxBuf1[20]={0};
  105. uint8_t rxBuf2[20]={0};
  106. int main(void)
  107. {
  108.   /* USER CODE BEGIN 1 */
  109.   /* USER CODE END 1 */

  110.   /* Enable I-Cache---------------------------------------------------------*/
  111.   SCB_EnableICache();

  112.   /* Enable D-Cache---------------------------------------------------------*/
  113.   SCB_EnableDCache();

  114.   /* MCU Configuration--------------------------------------------------------*/

  115.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  116.   HAL_Init();

  117.   /* USER CODE BEGIN Init */

  118.   /* USER CODE END Init */

  119.   /* Configure the system clock */
  120.   SystemClock_Config();

  121.   /* USER CODE BEGIN SysInit */

  122.   /* USER CODE END SysInit */

  123.   /* Initialize all configured peripherals */
  124.   MX_GPIO_Init();
  125.   MX_SPI3_Init();
  126.   /* USER CODE BEGIN 2 */
  127.   w5500_init();//初始化W5500
  128.   /* USER CODE END 2 */

  129.         uint8_t remote_ip[4]={192,168,10,37};
  130.         uint16_t remote_port=6000;
  131.         uint16_t local_port=5000;

  132.         uint8_t remote_ip1[4]={192,168,10,38};
  133.         uint16_t remote_port1=6001;
  134.         uint16_t local_port1=5000;

  135.         uint16_t len=0;
  136.         uint16_t len1=0;


  137.   /* Infinite loop */
  138.   /* USER CODE BEGIN WHILE */
  139.   uint8_t buffff[]="Tx Via UDP0";
  140.   uint8_t buffff1[]="Tx Via UDP1";

  141.         while (1)
  142.   {
  143.           socket(0, Sn_MR_UDP, local_port, 0);//设置Socket0
  144.           socket(1, Sn_MR_UDP, local_port1, 0);//设置Socket1
  145.           /*如果是两个Socket本地端口号一样的应用,需用户自己判断远端端口号区分处理收到的数据*/
  146.           /*如果是两个独立的端口号那种就是正常两个Socket*/
  147.           sendto(0, buffff, sizeof(buffff), remote_ip, remote_port);//Socket0发送
  148.           sendto(0, buffff1, sizeof(buffff), remote_ip1, remote_port1);//Socket1发送
  149. //          sendto(1, buffff1, sizeof(buffff1), remote_ip1, remote_port1);
  150.           HAL_Delay(500);
  151.           switch(getSn_SR(0))//查询socket0状态
  152.           {
  153.                     case SOCK_UDP:
  154.                   {

  155.                                 if(getSn_IR(0) & Sn_IR_RECV)
  156.                                 {
  157.                                         setSn_IR(0, Sn_IR_RECV);
  158.                                 }
  159.                                 if((len=getSn_RX_RSR(0))>0)//收到了UDP数据
  160.                                 {
  161.                                         memset(rxBuf,0,sizeof(rxBuf));
  162.                                         len = recvfrom(0,rxBuf, len, remote_ip,&remote_port);//数据回收
  163.                                         if(remote_port==6000)//如果来自6000
  164.                                         {
  165.                                                 memset(rxBuf1,0,sizeof(rxBuf1));
  166.                                                 memcpy(rxBuf1,rxBuf,len);
  167.                                         }

  168.                                         if(remote_port==6001)//如果来自6001
  169.                                         {
  170.                                                 memset(rxBuf2,0,sizeof(rxBuf2));
  171.                                                 memcpy(rxBuf2,rxBuf,len);
  172.                                         }
  173.                                 }
  174.                   }
  175.           }

  176.       //类似前面,不写注释了
  177.           switch(getSn_SR(1))
  178.           {
  179.                     case SOCK_UDP:
  180.                   {

  181.                                 if(getSn_IR(1) & Sn_IR_RECV)
  182.                                 {
  183.                                         setSn_IR(1, Sn_IR_RECV);
  184.                                 }
  185.                                 if((len1=getSn_RX_RSR(1))>0)
  186.                                 {
  187.                                         memset(rxBuf,0,sizeof(rxBuf));
  188.                                         len1 = recvfrom(1,rxBuf, len1, remote_ip1,&remote_port1);
  189.                                 }
  190.                   }
  191.           }

  192.   }
  193.   /* USER CODE END 3 */
  194. }

  195. /**
  196.   * @brief System Clock Configuration
  197.   * @retval None
  198.   */
  199. void SystemClock_Config(void)
  200. {
  201.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  202.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  203.   RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};

  204.   /** Supply configuration update enable
  205.   */
  206.   HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
  207.   /** Configure the main internal regulator output voltage
  208.   */
  209.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);

  210.   while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
  211.   /** Initializes the RCC Oscillators according to the specified parameters
  212.   * in the RCC_OscInitTypeDef structure.
  213.   */
  214.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  215.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  216.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  217.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  218.   RCC_OscInitStruct.PLL.PLLM = 5;
  219.   RCC_OscInitStruct.PLL.PLLN = 192;
  220.   RCC_OscInitStruct.PLL.PLLP = 2;
  221.   RCC_OscInitStruct.PLL.PLLQ = 12;
  222.   RCC_OscInitStruct.PLL.PLLR = 2;
  223.   RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
  224.   RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
  225.   RCC_OscInitStruct.PLL.PLLFRACN = 0;
  226.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  227.   {
  228.     Error_Handler();
  229.   }
  230.   /** Initializes the CPU, AHB and APB buses clocks
  231.   */
  232.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  233.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
  234.                               |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
  235.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  236.   RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
  237.   RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
  238.   RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
  239.   RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
  240.   RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
  241.   RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;

  242.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
  243.   {
  244.     Error_Handler();
  245.   }
  246.   PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SPI3;
  247.   PeriphClkInitStruct.Spi123ClockSelection = RCC_SPI123CLKSOURCE_PLL;
  248.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  249.   {
  250.     Error_Handler();
  251.   }
  252. }

  253. /* USER CODE BEGIN 4 */

  254. /* USER CODE END 4 */

  255. /**
  256.   * @brief  This function is executed in case of error occurrence.
  257.   * @retval None
  258.   */
  259. void Error_Handler(void)
  260. {
  261.   /* USER CODE BEGIN Error_Handler_Debug */
  262.   /* User can add his own implementation to report the HAL error return state */

  263.   /* USER CODE END Error_Handler_Debug */
  264. }

  265. #ifdef  USE_FULL_ASSERT
  266. /**
  267.   * @brief  Reports the name of the source file and the source line number
  268.   *         where the assert_param error has occurred.
  269.   * @param  file: pointer to the source file name
  270.   * @param  line: assert_param error line source number
  271.   * @retval None
  272.   */
  273. void assert_failed(uint8_t *file, uint32_t line)
  274. {
  275.   /* USER CODE BEGIN 6 */
  276.   /* User can add his own implementation to report the file name and line number,
  277.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  278.   /* USER CODE END 6 */
  279. }
  280. #endif /* USE_FULL_ASSERT */

  281. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

 楼主| 自动化陈稳 发表于 2023-2-28 01:51 | 显示全部楼层
main.h
  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.h
  5.   * @brief          : Header for main.c file.
  6.   *                   This file contains the common defines of the application.
  7.   ******************************************************************************
  8.   * @attention
  9.   *
  10.   * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  11.   * All rights reserved.</center></h2>
  12.   *
  13.   * This software component is licensed by ST under BSD 3-Clause license,
  14.   * the "License"; You may not use this file except in compliance with the
  15.   * License. You may obtain a copy of the License at:
  16.   *                        opensource.org/licenses/BSD-3-Clause
  17.   *
  18.   ******************************************************************************
  19.   */
  20. /* USER CODE END Header */

  21. /* Define to prevent recursive inclusion -------------------------------------*/
  22. #ifndef __MAIN_H
  23. #define __MAIN_H

  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif

  27. /* Includes ------------------------------------------------------------------*/
  28. #include "stm32h7xx_hal.h"

  29. /* Private includes ----------------------------------------------------------*/
  30. /* USER CODE BEGIN Includes */

  31. /* USER CODE END Includes */

  32. /* Exported types ------------------------------------------------------------*/
  33. /* USER CODE BEGIN ET */

  34. /* USER CODE END ET */

  35. /* Exported constants --------------------------------------------------------*/
  36. /* USER CODE BEGIN EC */

  37. /* USER CODE END EC */

  38. /* Exported macro ------------------------------------------------------------*/
  39. /* USER CODE BEGIN EM */

  40. /* USER CODE END EM */

  41. /* Exported functions prototypes ---------------------------------------------*/
  42. void Error_Handler(void);

  43. /* USER CODE BEGIN EFP */

  44. /* USER CODE END EFP */

  45. /* Private defines -----------------------------------------------------------*/


  46. #define W5500_INIT_Pin GPIO_PIN_1
  47. #define W5500_INIT_Port GPIOD

  48. #define W5500_RST_Pin GPIO_PIN_0
  49. #define W5500_RST_GPIO_Port GPIOD
  50. #define W5500_CS_Pin GPIO_PIN_9
  51. #define W5500_CS_GPIO_Port GPIOB
  52. /* USER CODE BEGIN Private defines */
  53. typedef int32_t  s32;
  54. typedef int16_t s16;
  55. typedef int8_t  s8;

  56. typedef const int32_t sc32;  
  57. typedef const int16_t sc16;  
  58. typedef const int8_t sc8;  

  59. typedef __IO int32_t  vs32;
  60. typedef __IO int16_t  vs16;
  61. typedef __IO int8_t   vs8;

  62. typedef __I int32_t vsc32;  
  63. typedef __I int16_t vsc16;
  64. typedef __I int8_t vsc8;   

  65. typedef uint32_t  u32;
  66. typedef uint16_t u16;
  67. typedef uint8_t  u8;

  68. typedef const uint32_t uc32;  
  69. typedef const uint16_t uc16;  
  70. typedef const uint8_t uc8;

  71. typedef __IO uint32_t  vu32;
  72. typedef __IO uint16_t vu16;
  73. typedef __IO uint8_t  vu8;

  74. typedef __I uint32_t vuc32;  
  75. typedef __I uint16_t vuc16;
  76. typedef __I uint8_t vuc8;
  77. /* USER CODE END Private defines */

  78. #ifdef __cplusplus
  79. }
  80. #endif

  81. #endif /* __MAIN_H */

  82. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

 楼主| 自动化陈稳 发表于 2023-2-28 01:52 | 显示全部楼层
main.h
  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.h
  5.   * @brief          : Header for main.c file.
  6.   *                   This file contains the common defines of the application.
  7.   ******************************************************************************
  8.   * @attention
  9.   *
  10.   * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  11.   * All rights reserved.</center></h2>
  12.   *
  13.   * This software component is licensed by ST under BSD 3-Clause license,
  14.   * the "License"; You may not use this file except in compliance with the
  15.   * License. You may obtain a copy of the License at:
  16.   *                        opensource.org/licenses/BSD-3-Clause
  17.   *
  18.   ******************************************************************************
  19.   */
  20. /* USER CODE END Header */

  21. /* Define to prevent recursive inclusion -------------------------------------*/
  22. #ifndef __MAIN_H
  23. #define __MAIN_H

  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif

  27. /* Includes ------------------------------------------------------------------*/
  28. #include "stm32h7xx_hal.h"

  29. /* Private includes ----------------------------------------------------------*/
  30. /* USER CODE BEGIN Includes */

  31. /* USER CODE END Includes */

  32. /* Exported types ------------------------------------------------------------*/
  33. /* USER CODE BEGIN ET */

  34. /* USER CODE END ET */

  35. /* Exported constants --------------------------------------------------------*/
  36. /* USER CODE BEGIN EC */

  37. /* USER CODE END EC */

  38. /* Exported macro ------------------------------------------------------------*/
  39. /* USER CODE BEGIN EM */

  40. /* USER CODE END EM */

  41. /* Exported functions prototypes ---------------------------------------------*/
  42. void Error_Handler(void);

  43. /* USER CODE BEGIN EFP */

  44. /* USER CODE END EFP */

  45. /* Private defines -----------------------------------------------------------*/


  46. #define W5500_INIT_Pin GPIO_PIN_1
  47. #define W5500_INIT_Port GPIOD

  48. #define W5500_RST_Pin GPIO_PIN_0
  49. #define W5500_RST_GPIO_Port GPIOD
  50. #define W5500_CS_Pin GPIO_PIN_9
  51. #define W5500_CS_GPIO_Port GPIOB
  52. /* USER CODE BEGIN Private defines */
  53. typedef int32_t  s32;
  54. typedef int16_t s16;
  55. typedef int8_t  s8;

  56. typedef const int32_t sc32;  
  57. typedef const int16_t sc16;  
  58. typedef const int8_t sc8;  

  59. typedef __IO int32_t  vs32;
  60. typedef __IO int16_t  vs16;
  61. typedef __IO int8_t   vs8;

  62. typedef __I int32_t vsc32;  
  63. typedef __I int16_t vsc16;
  64. typedef __I int8_t vsc8;   

  65. typedef uint32_t  u32;
  66. typedef uint16_t u16;
  67. typedef uint8_t  u8;

  68. typedef const uint32_t uc32;  
  69. typedef const uint16_t uc16;  
  70. typedef const uint8_t uc8;

  71. typedef __IO uint32_t  vu32;
  72. typedef __IO uint16_t vu16;
  73. typedef __IO uint8_t  vu8;

  74. typedef __I uint32_t vuc32;  
  75. typedef __I uint16_t vuc16;
  76. typedef __I uint8_t vuc8;
  77. /* USER CODE END Private defines */

  78. #ifdef __cplusplus
  79. }
  80. #endif

  81. #endif /* __MAIN_H */

  82. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

 楼主| 自动化陈稳 发表于 2023-2-28 01:52 | 显示全部楼层
效果展示
ping通啦 1145663fcede0e3d68.png
 楼主| 自动化陈稳 发表于 2023-2-28 01:53 | 显示全部楼层
UDP通信OK 2202663fcedff4962a.png
 楼主| 自动化陈稳 发表于 2023-2-28 01:53 | 显示全部楼层
W5500对常见UDP端口号与IP绑定的实现效果
这种场景要开两个socket
 楼主| 自动化陈稳 发表于 2023-2-28 01:53 | 显示全部楼层
 楼主| 自动化陈稳 发表于 2023-2-28 01:53 | 显示全部楼层
这种场景也是要开两个socket

3725063fcee2e0f970.png
 楼主| 自动化陈稳 发表于 2023-2-28 01:54 | 显示全部楼层
这种开1个Socket就可以,但是对接收的UDP数据的IP端口号要判断下,分别处理,因为相同本地端口号一样,远端IP端口号不一样,可能如果远端IP不一样,端口一样,这种也是适用的

425163fcee40de8a2.png
 楼主| 自动化陈稳 发表于 2023-2-28 01:54 | 显示全部楼层
W5500的网络设置
同一局域网内,网关可以不设置,W5500对应的设置网关那个参数不管就可,DNS也是
您需要登录后才可以回帖 登录 | 注册

本版积分规则

106

主题

1380

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部