STM32F107-FATFS demo lands in unhandled exception

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

hazelnusse
Posts: 77
Joined: Thu May 24, 2012 8:01 am

STM32F107-FATFS demo lands in unhandled exception

Post by hazelnusse »

I'm running the ARMCM3-STM32F107-FATFS. It builds fine and when I flash it, all the shell commands (help, info, systime, mem, threads, test) work except the tree command. I have a microSD card inserted, and the LED is blinking fast, indicating that fs_ready==TRUE. When I pull the sd card out, the LED blinks slowly, indicating that fs_ready==FALSE, so at the very least the card detect is working properly. When I type the tree shell command, I get:

Code: Select all

ch> tree
FS: 60021 free clusters, 64 sectors per cluster, 196676812

and the system becomes unresponsive. If I halt execution in the debugger and try to do a backtrace, I see:

Code: Select all

_unhandled_exception () at ../../os/ports/GCC/ARMCMx/STM32F1xx/vectors.c:194
(gdb) bt
#0  _unhandled_exception () at ../../os/ports/GCC/ARMCMx/STM32F1xx/vectors.c:194
#1  0xfffffffc in ?? ()
#2  0xfffffffc in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

If I put a breakpoint in cmd_tree, then issue the tree command in the shell, and try to step through that function, I am able to determine that this is occurring in the scan_files(). It seems like the call to f_opendir() in the beginning of scan_files() is the cluprit because even single stepping into that function lands me in _uhandled_exception(). Anybody have any idea why this would be happening?

Thanks,
Luke
hazelnusse
Posts: 77
Joined: Thu May 24, 2012 8:01 am

Re: STM32F107-FATFS demo lands in unhandled exception

Post by hazelnusse »

This is the instruction that causes the _unhandled_exception. If I step one more instruction (si), it lands in _unhandled_exception(). I have no idea why.

Image

Luke
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F107-FATFS demo lands in unhandled exception

Post by Giovanni »

Hi,

I assume FatFS is the one included in ChibiOS.

Crashing on "cmp r3,#0" makes no sense, it does not even access memory. Are you sure the device is correctly flashed?

I would also check for stack overflows, that backtrace is suspect, try enabling all the debug options in chconf.h and see if some problem is trapped.

Please also state compiler and ChibiOS versions or I will be unable to test.

Giovanni
hazelnusse
Posts: 77
Joined: Thu May 24, 2012 8:01 am

Re: STM32F107-FATFS demo lands in unhandled exception

Post by hazelnusse »

I assume FatFS is the one included in ChibiOS.

Yes.
Crashing on "cmp r3,#0" makes no sense, it does not even access memory. Are you sure the device is correctly flashed?

I agree. As far I know, it is flashed correctly. I use OpenOCD to flash it and have never had any issues with flashing (as far as I know).

I will try enabling debug options in chconf.h and see what happens.

I am using the latest Linaro toolchain (gcc/g++):
arm-none-eabi-gcc (Linaro GCC 4.7-2012.07) 4.7.2 20120701 (prerelease)

ChibiOS version is from git master, commit 74008e0ff26a56896842479730a97e5c637a81a8. I guess this is version 2.5.0.

Luke
hazelnusse
Posts: 77
Joined: Thu May 24, 2012 8:01 am

Re: STM32F107-FATFS demo lands in unhandled exception

Post by hazelnusse »

I enabled all the debug related options in chconf.h. I built it and flashed it and tried again and it still lands in _unhandled_exception, this time however it is at a slightly different instruction, but still inside the validate() function. My guess is that the instruction is fine but that there is some sort of corruption of something somewhere? The binary size is 44076 bytes without the debug options on, and 52044 bytes with all of them on, in case this is relevant. How do I go about debugging this?

Has anybody else tried the tree command with this demo? If so, it would be great to know if it is perhaps something just related to my toolchain.

My build environment is:
arm-none-eabi-gcc (Linaro GCC 4.7-2012.07)
newlib-1.20
binutils-2.22.90

I tried building with -O2 and with -O0, and both still land in unhandled_exception when I call tree, and in both cases, it occurs in validate() and the backtrace is suspect. Not sure how to proceed from here.

Luke
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F107-FATFS demo lands in unhandled exception

Post by Giovanni »

It works here, probably it is a toolchain problem, you could try to download "Chibi Studio" from SF and see if the toolchain makes any difference, it includes everything required.

Giovanni
hazelnusse
Posts: 77
Joined: Thu May 24, 2012 8:01 am

Re: STM32F107-FATFS demo lands in unhandled exception

Post by hazelnusse »

Ok, I'll give that a try and report back.
hazelnusse
Posts: 77
Joined: Thu May 24, 2012 8:01 am

Re: STM32F107-FATFS demo lands in unhandled exception

Post by hazelnusse »

It must have been something related to my toolchain. I switched to the GNU Tools for ARM Embedded Processors at https://launchpad.net/gcc-arm-embedded/, and now the demo runs perfectly.

Thanks for the feedback and for pointing me in the right direction.

Luke
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: STM32F107-FATFS demo lands in unhandled exception

Post by Tectu »

I know, this is a bit late, but I can confirm that I had the same issues and switchting to the toolchain you mentioned above did the job :)


~ Tectu
bsteinsbo
Posts: 2
Joined: Sat Aug 11, 2012 8:18 am

Re: STM32F107-FATFS demo lands in unhandled exception

Post by bsteinsbo »

I've also been struggling with this problem, for the ARMCM4-STM32F407-LWIP-FATFS-USB demo. I think there is a bug in the demo code. The way I understand it, when long file name support is enabled in FFS, the lfname and lfsize members must be initialized to a buffer receiving the long file name. Also, when returning from the recursive scan of a sub-directory, there will be an extra / for any files listed after the sub-directory files. Please see patch below. I have not tried the STM32F107-FATFS demo, but it's using similar code, and I believe similar changes are necessary there also.

- Bjarne

Code: Select all

--- C:/Users/bjarne/AppData/Local/Temp/main.c-revBASE.svn000.tmp.c   Sat Aug 11 09:22:53 2012
+++ C:/stm32/chibios/trunk/demos/ARMCM4-STM32F407-LWIP-FATFS-USB/main.c   Sat Aug 11 09:22:32 2012
@@ -125,6 +125,10 @@
   int i;
   char *fn;
 
+#if _USE_LFN
+  fno.lfname = 0;
+  fno.lfsize = 0;
+#endif
   res = f_opendir(&dir, path);
   if (res == FR_OK) {
     i = strlen(path);
@@ -141,7 +145,7 @@
         res = scan_files(chp, path);
         if (res != FR_OK)
           break;
-        path[i] = 0;
+        path[--i] = 0;
       }
       else {
         chprintf(chp, "%s/%s\r\n", path, fn);


-- edited: learning to use code instead of quote tags
-- edited again: pointing out that this patch is for the E407, not E107, but I think the code for E107 contains the same bug.
Last edited by bsteinsbo on Sat Aug 11, 2012 9:55 am, edited 2 times in total.
Post Reply