-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ch395): Add support for CH395Q(UART and SPI dual stack). (IDFGH-12408) #25
base: master
Are you sure you want to change the base?
Conversation
test(ch395): use SPI DMA transmission as default
@SergeyKharenko could you please consider distributing this driver also over your private repository on Component Registry? Unfortunately, we don't have resources to take it under our maintenance but it would be pity to be driver not published. |
@kostaond Thanks for your attention! It is okay to close this PR as I have mentioned #37. Although this driver initially make CH395 works on esp32, it is actually the same as W5500, the driver forces the chips working in MACRAW mode, which does not fully take advantage of these hardwired-stack chips(HWSC). So I have moved my work to hwss and I am glad to share it with you. This project aims to:
This framework has been initially established, protocols above L3 have not been implemented and I haven't had time to write the document yet~ A small demo is implemented in main |
Brief Introduction
CH395 is the first domestic Ethernet controller that supports 10M/100M and has a built-in TCP/IP protocol stack. It was designed by NanjingQinhengMicroelectronics CO LTD (abbreviated as WCH) and officially launched on March 1, 2013. In terms of functionality, ch395 is comparable to Wiznet W5500. In addition, this chip can also use UART to communicate, which has fewer lines than SPI.
However, WCH only provides sample code on 80C51. What's worse, sample code is more focus on hardware TCP/IP stack of the chip. Introductions about MAC Raw mode are pretty brief. This seriously hinders its compatibility with the lwip.
My work is to explore the functionality of the chip in MAC RAW mode and port it into the
esp-eth-drivers
. As far as I know, no one has ever done that.High Lights
Issue & Solution
Cannot accept continuous R/W in SPI Mode. R/W one byte per transaction.CMD01_GET_CMD_STATUS
before the CH395 init, the status is keepingCH395_ERR_BUSY
. Leave enough waiting time for some operations that require query to avoid queries.CMD40_SET_FUN_PARA
to disableSEND_OK
interrupt. Add additional delay(20 ms)CMD10_SET_PHY
to setup mode of PHY, within a short period of time, user would get unknow status of PHY(usingCMD01_GET_PHY_STATUS
). Add additional delay(350 ms)Performance Report
UART Mode
Both transmit and receive increase LINEARLY as the baudrate increases. That fully demonstrates that the system bottleneck is not in the driver layer, but in baudrate instead.
SPI Mode
The sending and receiving speed gradually becomes saturated after the SPI frequency is higher than 10MHz. This is mainly because the chip cannot support SPI continuous reading and writing, and a certain delay must be added between bytes, which makes DMA useless. I have already sent my questions to WCH engineers and hope to get a reply soon. On the other hand, someone could provide me with some valuable advice on SPI transmission if possible?
After Optimization
Optimization is based on the following "features":
ch395_rx_buffer
, packet reads are performed in 4-byte increments to improve efficiency. I guess this may be due to the SRAM's synchronization mechanism.ch395_tx_buffer
, packet writings are performed in one transmission. That's why TX Performance has been greatly improved.ch395_spi_io
operations are as legacy.PS:
Here is the introduction to this ethernet controller in detail:
CH395 is an Ethernet protocol stack management IC which provides Ethernet communication ability for MCU system. CH395 has built-in 10 / 100M Ethernet MAC and PHY and fully compatible with IEEE 802.3 protocol, it also has built-in protocol stack firmware such as PPPOE, IP, DHCP, ARP, ICMP, IGMP, UDP, TCP and etc. A MCU system can easily connect to Ethernet through CH395. CH395 supports 3 types of communication interfaces: 8-bit parallel port, SPI or USART. A MCU/DSP/MPU can use any of the above communication interfaces to operate CH395 for Ethernet communication.