Dhcp

I use W5500 with STM32F051R8T6, my IDE is Keil. I ported some part of code to this chip and communication by SPI works well. I also have succes with STM32F103X CooCox CoIDE Project Loopback Test - works perfect.
I have problem with DHCP client. When I run this project I have go HardFault. Here is my console output:

[code]=== W5500 NET CONF : DHCP ===
MAC: 00:08:DC:00:AB:CD
SIP: 192.168.1.123
GAR: 192.168.1.1
SUB: 255.255.255.0
DNS: 0.0.0.0

Send DHCP_DISCOVER
DHCP message : 192.168.1.1(67) 345 received.
Receive DHCP_OFFER
Send DHCP_REQUEST
DHCP message : 192.168.1.1(67) 345 received.
Receive DHCP_ACK
HardFault[/code]

during debug I have found that hardfault is occur in this line:

if(*((uint32_t*)addr) == 0) return SOCKERR_IPINVALID;

in function

int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port)

What could be the problem?

Hi,
addr address assigned in memory maybe not 32-bit address value. That is, The addr is not divided by 4.
ex) addr = 0x0003;
((uint32)addr) = 0x11223344; <— Maybe Hardfault.

Check addr value.

Thank you.

Hi,

I checked and addr = 0x2000016B - address of variable DHCP_allocated_ip.

You are right. This addr is not divied by 4.

I change code to:

if ((addr[0] | addr[1] | addr[2] | addr[3]) == 0) return SOCKERR_IPINVALID;

and now everything is OK.

Hi,
I’m glad to solve your problem, too.
Thank you.