Skip to main content
Visitor II
January 6, 2021
Question

How to port Azure Rtos NetX driver to an external spi controller?

  • January 6, 2021
  • 3 replies
  • 1666 views

Hi,

I'm having trouble understanding the function of NetX that reads data received from ethernet:

static VOID _nx_driver_hardware_packet_received(VOID)

{

NX_PACKET   *packet_ptr;

     NX_PACKET *received_packet_ptr;

INT      i;

  uint32_t framelength = 0;

  static ETH_BufferTypeDef RxBuff[NX_DRIVER_RX_DESCRIPTORS];

  memset(RxBuff, 0 , NX_DRIVER_RX_DESCRIPTORS*sizeof(ETH_BufferTypeDef));

  for(i = 0; i < NX_DRIVER_RX_DESCRIPTORS -1; i++)

    {

    RxBuff[i].next=&RxBuff[i+1];

      }

  while (HAL_ETH_GetRxDataBuffer(&heth, RxBuff) == HAL_OK)

      {

    HAL_ETH_GetRxDataLength(&heth, &framelength);

    ETH_RxDescListTypeDef *dmarxdesclist = &heth.RxDescList;

    uint32_t FirstAppDesc = dmarxdesclist->FirstAppDesc;

    /* This driver assumes the recieved packet size is 1536 bytes */

    received_packet_ptr = nx_driver_information.nx_driver_information_receive_packets[FirstAppDesc];

    received_packet_ptr->nx_packet_append_ptr = received_packet_ptr->nx_packet_prepend_ptr + framelength;

    received_packet_ptr->nx_packet_length = framelength;

    received_packet_ptr->nx_packet_next = NULL;

        if (nx_packet_allocate(nx_driver_information.nx_driver_information_packet_pool_ptr, &packet_ptr,

                     NX_RECEIVE_PACKET, NX_NO_WAIT) == NX_SUCCESS)

        {

      /* Adjust the packet. */

          packet_ptr -> nx_packet_prepend_ptr += 2;

          SCB_InvalidateDCache_by_Addr((uint32_t*)packet_ptr -> nx_packet_data_start, packet_ptr -> nx_packet_data_end - packet_ptr -> nx_packet_data_start);

      

           

      HAL_ETH_DescAssignMemory(&heth, FirstAppDesc, packet_ptr -> nx_packet_prepend_ptr, NULL);

      nx_driver_information.nx_driver_information_receive_packets[FirstAppDesc] = packet_ptr;

      /* Build Rx descriptor to be ready for next data reception */

      HAL_ETH_BuildRxDescriptors(&heth);

      /* Transfer the packet to NetX. */

        _nx_driver_transfer_to_netx(nx_driver_information.nx_driver_information_ip_ptr, received_packet_ptr);

      }

    else

    {

      HAL_ETH_BuildRxDescriptors(&heth);

  }

  }

}

I don't understand where RxBuff is used after the function HAL_ETH_GetRxDataBuffer(&heth, RxBuff).

How can I modify the funtion "static VOID _nx_driver_hardware_packet_received(VOID)" to use my custom ethernet controller read funtion:

Packet_Length = ReadPacket(pBuf);

pBuf is a pointer where the packet will be transfered to, and the Packet_Length is the packet size.

    This topic has been closed for replies.

    3 replies

    ST Employee
    January 13, 2021

    Hello,

    You can refer to NetX Duo online documentation https://docs.microsoft.com/en-us/azure/rtos/netx-duo/chapter5, this chapter contains a description of network drivers to help developers write application-specific network drivers for NetX Duo..

    A template network driver is available on GitHub here https://github.com/azure-rtos/netxduo/blob/master/common/src/nx_ram_network_driver.c

    AsantosAuthor
    Visitor II
    January 13, 2021

    Thanks Raouf, but it still very difficult to port it for a external ethernet controller. The network driver template would be much more usefull if it was an example for an especific SPI Ethernet Controller. (KSZ8851SNL, ENC424J600, DM9051, AX88796C,W5500,etc)

    Graduate II
    January 16, 2021

    The level of the example code in original topic is the same as HAL H7 ETH driver - completely unusable broken bloatware. Don't take it seriously. Don't bother about RxBuff and other nonsense created by people, who don't know what they are doing. Focus only on the things you actually need:

    1. Read the frame from your Ethernet controller.
    2. Pack the frame in a format used by your IP stack.
    3. Pass the frame to IP stack.
    4. Repeat the points 1-3 until there are no new frames left.