FreeRTOS+TCP port to Kinetis K60F

gsocker wrote on Thursday, July 19, 2018:

I’ve sucessfully created a zero-copy Ethernet driver for the NXP K60F, using BufferAllocation scheme #2.
Unfortunately, it was for a work project, and I can’t post it.
Some notes - hopefully they will be helpful for someone.

MAC address load: The HW registers seem to have a strange format. Given a mac address of 11:22:33:44:55:66, the address is loaded as:

ENET->PALR = 11 << 24 | 22 << 16 | 33 << 8 | 44;
ENET->PAUR = 55 << 8 | 66;

This produces the correct MAC address on the wire when setting the Ethernet MAC to insert the device MAC address on transmit.
The unicast hash table must be loaded per the reference manual procedure with the device’s MAC address. Failure to do so will result in no packets being received, despite the address already being in the PALR/PAUR registers, unless promiscuous mode is enabled.

Accelerator configuration:
Like a few other chips I’ve seen mentioned, the checksum fields must be zeroed for the Ethernet MAC to insert IP or protocol checksums on transmit. Also, the FIFO must be set to “store & forward” mode for any of the accelerator options to function, according to the reference manual.

Network buffer alignment:
While the TX DMA works fine with the 8-byte aligned address that pvPortMalloc returns, RX DMA requires 16-byte alignment of the buffer. This is mentioned as a footnote in the buffer descriptor diagram. To handle this, I tweaked the buffer allocation code to allocate an extra 8 bytes on the end and shift the buffer position by 8 bytes if the address returned by pvPortMalloc is not aligned on a 16-byte boundary.

DMA Descriptors: At least when using the enhanced descriptors, pay careful attention to the memory layout shown in the reference manual, as the addresses increase from right to left on the diagrams. I missed this at first when defining the buffer descriptor structures (assuming that the field on the left side would have the lower address) and was setting the wrong bits. Both RX and TX descriptors have a minimum alignment requirement of 8 bytes.

I was also able to reuse the PHY handling code from the LPC demos as the board being used has a KSZ8081 PHY.

Transmit: The ENET MAC on the K60F has an errata: e6358.

I’m still not quite sure I have the relation between the MTU/TCP MSS values correct in the config file. I had to drop them from the default as the device at the other end has a hard limit of ~470 bytes, above which packets get lost.


rtel wrote on Friday, July 20, 2018:

Thanks for sharing.