2017-03-25 01:09 PM
Hi,
Something is driving me crazy.
Actually I have written a program that
it:
receive 100chars each 60ms from USART1 and 2 with RXNE interrupt(baudrate 57600)
receive100chars each 100ms from Ethernet with PHY and after processing it sends to USARTs port with TXNE interrupt
sends 120 chars to PC via Ethernet each 100ms with Timer.
it works fine when I connect my board via st-link in debug mode but when I get off out of debug mode it works for 1-2 hours and suddenly hangs and disables Ethernet communication.In this states I can't realize what my problem is.
what is your idea about this strange states? why it works fine in debug mode?
Thanks in advance
2017-04-02 11:29 PM
Thanks a lot for your kindness, I will check and let you know
2017-04-03 12:55 AM
1 - Download - 4shared - Parisa Mohamadi
Requires a Social Media account for download, which I do not have.
Are your interrupts prioritized (different priorities) or are both (ETH, UART) on the same level ?
2017-04-03 01:27 AM
But I didn't set anything for ETH , doesn't SPL library set it correctly at high priority?
I think the SPL never does. You need to prioritize the interrupts according to your requirements.
2017-04-03 03:50 AM
The UART interrupts look ok to me.
I can't see any interrupt handler for the ethernet peripheral, probably in some middleware.
What looks suspicious to me - you call that EtherData() routine with its very long printf() from the timer interrupt context. I can imagine this causes trouble with overflows under heavier network load. I would rather set a flag in the timer.
You use a lot of global variables. this could be painful to view, and synchronize between synchronous main code and asynchronous interrupts.
I still recommend to instrument the code. For instance, you could toggle GPIOs in the interrupts, and trace them with a scope. When your application stops, the scope might reveal something useful.
2017-04-03 04:01 AM
Again, if it is related to initial register or global variable values after reset (missing startup or else), try to unplug the debug cable AFTER the code is running...
2017-04-04 06:03 AM
Thanks a lot for your contributions and help
Actually I have added ETH interrupt with the highest priority after netInitialize function and I just set a flag in Timer interrupt to fill the Ethernet packet via Sprintf function in out of interrupt function. it works better than before but when I send 10 packets in 1second I miss 2 of them. In addition I have seen that I lost my connection during sending and receiving but LEDs of USARTs were blinking (it means my MCU works fine without any hangs) and I can connect to my board again without any problem.But different things worry me
1)How can detect why I lost my connection?
2)why do I miss some packets when I send them via PC ?
and if there is no problem
1)coud you explain how can define minimum time between sending packet according to their length?
2)did I define well the Heap and Stack size for my MCU and Ethernet threads?
2017-04-04 07:14 AM
1)How can detect why I lost my connection?
Not sure why you think you lose the connection.
From your netInitialize() call, I cannot see if you acquire a TCP or UDP socket.
But TCP connections do not close immediately, if not explicitly done. And UDP is connection-less.
I guess the issue is the same as for question 2.
2)why do I miss some packets when I send them via PC ?
You might need to qualify your network environment, and test under controlled conditions.
'Normal' office networks involve a lot of 'irrelevant' traffic, directed to other PC nodes, switches, etc.
The STM32F4 simply does not have the performance resources to process all packets in an average office network environment.
I suggest the 'Wireshark' software to monitor and evaluate the network traffic you are dealing with.
And for test purposes, I suggest to connect the STM board to the 'PC' side to a separate network via a separate network adapter, unaffected by above mentioned 'office traffic'. A RNDIS device (USB to ethernet) is affordable and easy to install.
This way, you can easily add additional stress in a controlled way to test you application.
1)coud you explain how can define minimum time between sending packet according to their length?
Not sure if I understand that correctly, but this would depend on your application.
2)did I define well the Heap and Stack size for my MCU and Ethernet threads?
There are no fixed rules I know of. If your application runs properly, the sizes are o.k. This means you require proper testing, including stress tests / overload test. You application shall react in a defined manner (drop packages, return error codes ?), but not crash the system (Hardfault).
You can initialize the stack with a specific pattern, and inspect the stack memory after a test run. This will tell you a 'high water mark'.
RTOSs use to complicate things, every task use to have his own stack. Often, the RTOS documentation gives recommendations about stack sizes - at least FreeRTOS does ...
2017-04-05 02:52 AM
Dear Avatar
Thanks for your response.
Actually I have seen another states that I lost my connection (I couldn't receive anything and my socket in PC software show me an error and my board didn't response to any Ping request and I couldn't connect to it again.However my USART interrupt receiving LED was blinking. In addition I connect my PC through a switch ( without any other clients).
what are the most important parameters that a connection maybe lose or disable Ethernet communication ?
2017-04-05 07:39 AM
I think the term 'connection lost' is not a proper description, or not fully appropriate in this case.
The setup process of a TCP connection is a more complex and multi-staged process, as well as the clearing of an existing connection.
There is a vast amount of documentations and tutorials available on the net - check out the RFC (Request For Comment) to this topic.
From your description, I suspect there is a bug in the Ethernet reception flow, perhaps that part got stuck because of an unexpected condition. I would guess an uncleared error condition.
I did not deal much with STM32 and networking/ethernet yet, neither with other Cortex M.
In case I rather use one of my Linux boards with a Cortex A8/A9, with sufficient performance and network throughput.
IMHO the lower end of the IoT business is a non-starter ...
2017-04-05 10:46 AM
One would have to check several things, like has the PHY changed state due to a cable/connection issue. Does that need to be renegotiated? Does the ETH side flags some kind of error or status? Does the IP Stack leak memory, or fail to reset/retry when errors are detected, or connectivity changes, etc.