Skip to content

Instantly share code, notes, and snippets.

@tschiemer
Last active July 9, 2020 09:52
Show Gist options
  • Save tschiemer/5c4a46f33e853342f7cc199f9a265474 to your computer and use it in GitHub Desktop.
Save tschiemer/5c4a46f33e853342f7cc199f9a265474 to your computer and use it in GitHub Desktop.
NUCLEO-H743ZI2 multicast test
#include "mbed.h"
#include "stm32h743xx.h"
#include "stm32xx_emac.h"
#include "EthernetInterface.h"
EthernetInterface eth;
UDPSocket udpsock;
// main() runs in its own thread in the OS
int main()
{
printf("\nRESTART\n");
uint32_t reg;
reg = READ_REG(ETH->MACPFR);
printf("ETH_MACPFR 0x%x\n", reg);
// ipv4 link-local
//eth.set_network("169.254.13.37", "255.255.0.0", "0.0.0.0");
if (eth.connect()){
printf("connect failed\n");
while(1);
}
SocketAddress addr;
eth.get_ip_address(&addr);
printf("ip %s\n", addr.get_ip_address());
// NUCLEO_H743ZI2
// low-level: set MAC filter to pass multicast
// STM32_EMAC &emac = STM32_EMAC::get_instance();
// ETH_MACFilterConfigTypeDef pFilterConfig;
// HAL_ETH_GetMACFilterConfig(&emac.EthHandle, &pFilterConfig);
// pFilterConfig.PassAllMulticast = ENABLE;
// HAL_ETH_SetMACFilterConfig(&emac.EthHandle, &pFilterConfig);
reg = READ_REG(ETH->MACPFR);
printf("ETH_MACPFR 0x%x\n", reg);
// uncomment to enable multicast pass all
// WRITE_REG(ETH->MACPFR, reg | (1 << 4));
reg = READ_REG(ETH->MACPFR);
printf("ETH_MACPFR 0x%x\n", reg);
if (udpsock.open(&eth)){
printf("open failed\n");
while(1);
}
if (udpsock.bind(5353)){
printf("bind failed\n");
while(1);
}
if (udpsock.join_multicast_group("224.0.0.251")){
printf("ipv4 join fail\n");
while(1);
}
if (udpsock.join_multicast_group("ff02::fb")){
printf("ipv6 group join fail\n");
while(1);
}
uint8_t data[2048];
printf("starting recv\n");
while(1){
nsapi_size_or_error_t serr = udpsock.recv(data, sizeof(data));
if (serr > 0){
printf("rx packet\n");
} else if (serr < 0){
printf("err %d\n", serr);
}
}
}
void LWIP::Interface::emac_input(emac_mem_buf_t *buf)
{
struct pbuf *p = static_cast<struct pbuf *>(buf);
// add debug info to see which packets arrive from the emac
printf("%x:%x:%x:%x:%x:%x / %x:%x:%x:%x:%x:%x\n",
((uint8_t*)p->payload)[0], ((uint8_t*)p->payload)[1], ((uint8_t*)p->payload)[2], ((uint8_t*)p->payload)[3], ((uint8_t*)p->payload)[4], ((uint8_t*)p->payload)[5],
((uint8_t*)p->payload)[6], ((uint8_t*)p->payload)[7], ((uint8_t*)p->payload)[8], ((uint8_t*)p->payload)[9], ((uint8_t*)p->payload)[10], ((uint8_t*)p->payload)[11]
);
/* pass all packets to ethernet_input, which decides what packets it supports */
if (netif.input(p, &netif) != ERR_OK) {
LWIP_DEBUGF(NETIF_DEBUG, ("Emac LWIP: IP input error\n"));
pbuf_free(p);
}
}
{
"target_overrides": {
"*": {
"lwip.dhcp-timeout": 5,
"lwip.ipv6-enabled": 1
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment