andylong0206 wrote on March 01, 2018:
Hi,
I just wanted to provide some feedback on this post. I have got the Wi-Fi working with a little help from that latest release 1.2.2 today 
However, when I switch back to Ethernet i.e. #Define PIC32_Use_ETHERNET it didn’t compile, it’s missing a bunch of PIC32 specific functions in BufferAllocation_2.c. No problem I thought I’ll just add them. This is what I added:
//
// PIC32 specific stuff
//
#ifdef PIC32_USE_ETHERNET
// MAC packet acknowledgment, once MAC is done with it
static bool PIC32_MacPacketAcknowledge(TCPIP_MAC_PACKET* pPkt, const void* param);
// allocates a MAC packet that holds a data buffer that can be used by both:
// - the FreeRTOSIP (NetworkBufferDescriptor_t->pucEthernetBuffer)
// - the Harmony MAC driver: TCPIP_MAC_PACKET->pDSeg->segLoad
// from the beginning of the buffer:
// - 4 bytes pointer to the network descriptor (FreeRTOS)
// - 4 bytes pointer to the MAC packet (pic32_NetworkInterface.c)
// - 2 bytes offset from the MAC packet (Harmony MAC driver: segLoadOffset)
//
// NOTE: segLoadLen should NOT include:
// - the TCPIP_MAC_FRAME_OFFSET (== ipBUFFER_PADDING which should be == 10!)
// - the sizeof(TCPIP_MAC_ETHERNET_HEADER)
// These are added by the MAC packet allocation!
//
static uint8_t* PIC32_PktAlloc(uint16_t pktLen, uint16_t segLoadLen, TCPIP_MAC_PACKET_ACK_FUNC ackF, TCPIP_MAC_PACKET** pPtrPkt)
{
uint8_t* pBuff = 0;
// allocate standard packet
TCPIP_MAC_PACKET* pPkt = TCPIP_PKT_PacketAlloc(pktLen, segLoadLen, 0);
// set the MAC packet pointer in the packet
if(pPkt != 0)
{
pBuff = pPkt->pDSeg->segLoad;
TCPIP_MAC_PACKET** ppkt = (TCPIP_MAC_PACKET**)(pBuff - PIC32_BUFFER_PKT_PTR_OFFSET);
configASSERT(((uint32_t)ppkt & (sizeof(uint32_t) - 1)) == 0 );
*ppkt = pPkt; // store the packet it comes from
pPkt->ackFunc = ackF;
pPkt->ackParam = 0;
}
if(pPtrPkt != 0)
{
*pPtrPkt = pPkt;
}
return pBuff;
}
// standard PIC32 MAC allocation function for a MAC packet
// this packet saves room for the FreeRTOS network descriptor
// at the beginning of the data buffer
// see NetworkBufferAllocate
// Note: flags parameter is ignored since that’s used in the Harmony stack only
TCPIP_MAC_PACKET* PIC32_MacPacketAllocate(uint16_t pktLen, uint16_t segLoadLen, TCPIP_MAC_PACKET_FLAGS flags)
{
TCPIP_MAC_PACKET* pPkt;
PIC32_PktAlloc(pktLen, segLoadLen, 0, &pPkt);
return pPkt;
}
// standard PIC32 MAC packet acknowledgment
// function called once MAC is done with it
static bool PIC32_MacPacketAcknowledge(TCPIP_MAC_PACKET* pPkt, const void* param)
{
configASSERT((pPkt != 0));
TCPIP_PKT_PacketFree(pPkt);
return false;
}
// associates the current MAC packet with a network descriptor
// mainly for RX packet
void PIC32_MacAssociate(TCPIP_MAC_PACKET* pRxPkt, NetworkBufferDescriptor_t* pxBufferDescriptor, size_t pktLength )
{
uint8_t* pPktBuff = pRxPkt->pDSeg->segLoad;
pxBufferDescriptor->pucEthernetBuffer = pPktBuff;
pxBufferDescriptor->xDataLength = pktLength;
// make sure this is a properly allocated packet
TCPIP_MAC_PACKET** ppkt = (TCPIP_MAC_PACKET**)(pPktBuff - PIC32_BUFFER_PKT_PTR_OFFSET);
configASSERT(((uint32_t)ppkt & (sizeof(uint32_t) - 1)) == 0 );
if(*ppkt != pRxPkt)
{
configASSERT(false);
}
// set the proper descriptor info
NetworkBufferDescriptor_t** ppDcpt = (NetworkBufferDescriptor_t**)(pPktBuff - ipBUFFER_PADDING);
configASSERT(((uint32_t)ppDcpt & (sizeof(uint32_t) - 1)) == 0 );
*ppDcpt = pxBufferDescriptor;
}
// debug functionality
void PIC32_MacPacketOrphan(TCPIP_MAC_PACKET* pPkt)
{
TCPIP_PKT_PacketFree(pPkt);
configASSERT(false);
}
// FreeRTOS allocation functions
// allocates a buffer that can be used by both:
// - the FreeRTOSIP (NetworkBufferDescriptor_t->pucEthernetBuffer)
// - the Harmony MAC driver: TCPIP_MAC_PACKET
// See PIC32_PktAlloc for details
//
// NOTE: reqLength should NOT include the ipBUFFER_PADDING (which should be == 10!)
// or the sizeof(TCPIP_MAC_ETHERNET_HEADER)
// These are added by the MAC packet allocation!
//
uint8_t* NetworkBufferAllocate(size_t reqLength)
{
return PIC32_PktAlloc(sizeof(TCPIP_MAC_PACKET), reqLength, PIC32_MacPacketAcknowledge, 0);
}
// deallocates a network buffer previously allocated
// with NetworkBufferAllocate
void NetworkBufferFree(uint8_t* pNetworkBuffer)
{
if(pNetworkBuffer != 0)
{
TCPIP_MAC_PACKET** ppkt = (TCPIP_MAC_PACKET**)(pNetworkBuffer - PIC32_BUFFER_PKT_PTR_OFFSET);
configASSERT(((uint32_t)ppkt & (sizeof(uint32_t) - 1)) == 0 );
TCPIP_MAC_PACKET* pPkt = *ppkt;
configASSERT((pPkt != 0));
if(pPkt->ackFunc != 0)
{
(*pPkt->ackFunc)(pPkt, pPkt->ackParam);
}
else
{ // ???
PIC32_MacPacketOrphan(pPkt);
}
}
}
#endif
This obviously resolved the compilation issue. However when it runs it falls over in NetworkInterface_eth.c line# 225 configASSERT( pTxPkt != 0 ); because pTxPkt is zero.
I’ve checked the value of PIC32_BUFFER_PKT_PTR_OFFSET in NetworkConfig.h (which was missing from 1.2.2 build btw), it’s 6 which as far as I can see is correct within the comments.
Am I missing something?
Andy