Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 8 months ago.
HardFault occurs when fopen() is called after EthernetInterface.connect(); (with mbed OS 5.4~5.8)
Hi,
I'm trying to make a program with which to make LPC1768 a kind of a file server, which communicate with devices over Ethernet, and read/write text files in ther local drive of LPC1768.
I'm using :
- LPC1768
- mbed OS 5 (5.4.7 ~ 5.8.1)
- Online ARM compiler
- EthernetInterface (Class)
- LocalFileSystem (Class)
LPC1768 is conneting to:
- PC with USB
- A router with LAN cable
and I have found that my mbed freezes when fopen() after EthernetInterface-instance.connect(). I extrated the part which has something wrong from my program. Following code can reproduce the error I had:
Import programeth-filesystem-sample
This program is published for a question I throw at the forum (https://os.mbed.com/questions/80658/HardFault-occurs-when-fopen-is-called-af/). I will thank you for answering my question. Abstract: LPC1768 freezes while processing this program, especially when fopen() is called after EthernetInterface.connect() P.S.' This problem is discussed here: https://github.com/ARMmbed/mbed-os/issues/6578
main.cpp
#include "mbed.h" #include "EthernetInterface.h" LocalFileSystem local("local"); void func(); EthernetInterface *net; int main() { func(); net = new EthernetInterface(); func(); if(net->connect()) { printf("Error!@EthernetInterface::connect()\r\n"); } else { printf("IP Address is %s\r\n", net->get_ip_address()); } func(); } void func() { static int i = 1; printf("-------test of fopen()#%d----\r\n", i); if(fopen("/local/test.txt", "r")==NULL) printf("File could not open\r\n"); else printf("File was opened successfully.\r\n"); i++; }
When I connect the LPC1768 to a router with RJ45(LAN), and also to my PC with USB, and then I execute this program, I get following result on the console on my PC.
result
-------test of fopen()#1---- File was opened successfully. -------test of fopen()#2---- File was opened successfully. IP Address is 192.168.11.3 -------test of fopen()#3---- //printf() just before if-clause in func() does work //here, LPC1768 hang up @fopen() just before printf() in if-clause in func()
Can you reproduce the error? or Can you tell me what did I do wrong? or Do some libraries have bugs? or Is there another new API to handle the local drive of LPC1768?
I will appreciate any comment!!! Thanks!!!
Quote:
Before, I made such programs with mbed OS 2(classic) and it perfectly worked. Following is the code which was slightly modified for mbed OS 2. In this case, I used:
- LPC1768
- mbed OS 2(classic)
- Online ARM compiler
- mbed-rtos(lib; latest ver. @Mar22th,2018)
- EthernetInterface (lib)
- EhternetInterface (Class)
- LocalFileSystem (Class)
and then I got following result
Import programeth-filesystem-sample-mbed-classic
LPC1768 DOESN'T freeze while processing this program, even when fopen() is called after EthernetInterface.connect() (with MBED OS 2) see also https://os.mbed.com/users/aktk/code/eth-filesystem-sample/
result
-------test of fopen()#1---- File was opened successfully. -------test of fopen()#2---- File was opened successfully. IP Address is 192.168.11.3 -------test of fopen()#3---- File was opened successfully. //DOESN'T freeze
Quote:
Postscript
I found that the program can catch the error end show it on console like below when I use mbed OS 5.8.0.
result
-------test of fopen()#1---- File was opened successfully. -------test of fopen()#2---- File was opened successfully. IP Address is 192.168.11.3 -------test of fopen()#3---- ++ MbedOS Fault Handler ++ FaultType: HardFault Context: R0 : 00000001 R1 : 10002618 R2 : 00000000 R3 : 00003F00 R4 : 00000005 R5 : 1000263C R6 : 00000000 R7 : 10000B8C R8 : 00000000 R9 : FFFFFFFF R10 : 00000000 R11 : 00000000 R12 : 000041BD SP : 10002618 LR : 0000D0CB PC : 0000D0D0 xPSR : 01000000 PSP : 100025F8 MSP : 10007FD8 CPUID: 412FC230 HFSR : 80000000 MMFSR: 00000000 BFSR : 00000000 UFSR : 00000000 DFSR : 0000000A AFSR : 00000000 SHCSR: 00000000 Thread Info: Current: State: 00000002 EntryFn: 0000CDCD Stack Size: 00001000 Mem: 100016A8 SP: 10002550 Next: State: 00000002 EntryFn: 0000CDCD Stack Size: 00001000 Mem: 100016A8 SP: 10002550 Wait Threads: State: 00000083 EntryFn: 0000BFED Stack Size: 00000300 Mem: 10000610 SP: 100008A0 Delay Threads: State: 00000043 EntryFn: 000115C1 Stack Size: 000004B0 Mem: 10002C08 SP: 10003020 Idle Thread: State: 00000001 EntryFn: 0000B521 Stack Size: 00000200 Mem: 10000410 SP: 100005C8 -- MbedOS Fault Handler --
I cannot understand what the error means completely.
Quote:
Postscript #2
I found that it works when with mbed OS 5.3 as well as mbed OS 2!!!
I think that means the exception error is specific to mbed OS 5.4~5.8.1
posted by Akifumi Takahashi 27 Mar 2018-Tracking here: https://github.com/ARMmbed/mbed-os/issues/6578
posted by Jan Jongboom 09 Apr 2018OK. Thanks for your helping!
posted by Akifumi Takahashi 10 Apr 2018