Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

LPC2129 - DAbt Handler using FatFS

Posted by J.S. on July 25, 2012
Hi all,

I've inherited a project (I'm an ME, not CS/EE) running FreeRTOS and have been tasked with eliminating a few bugs.

Most have been simple, but never having used any RTOS before, some problems are more troubling. There's one thing in particular that I keep coming back to: data abort.

I had a function to stream a file over UART. The data transmitted fine, but at the end of every file when it came back to the "root" of the task, I got a stack overflow (checking was enabled). I couldn't figure out why, so I added a lot of debug prints.

Ok, that's interesting... it reinitializes all (already running) tasks and then overflows. But why would it reset? It turns out, all the exception handlers cascaded into the reset handler. I tried SUBS R15,R14,#8 to go back two instructions and resume, but it stays stuck. I guess printing R14 - 8 might tell me the value of the memory location that was accessed improperly, but I had no debugger and I'm no good with inline ASM. If someone can suggest how to read that to C, I can do a UART_puts or putc to see what it contains.

If I send a short string manually, it works fine. It's sort of an arbitrary cut off length. This runs in a task called Upload, and I have tried everything from portSAVE/RESTORE, task_ENTER_CRITICAL, vTaskSuspendAll, disabling interrupts... it still happens. Yes, FS_SHARE is enabled, but FS_REENTRANT is not as this is accessed from a single task. I have also tried declaring the file locally as well as globally.

The offending code is below, called within task 'Upload':


int SendFile(char* filetosend) {
taskDISABLE_INTERRUPTS();
vTaskSuspendAll();
FRESULT res;
FIL SD_File_Handle_2; // Can I use the same handle from SD_file_handle to reduce RAM use?
BYTE buffer[512]; //BYTE buffer[SD_BLOCK_SIZE];
uint32_t br;
int i;
int hadExtension;
hadExtension = 0;
if (strcmp(filetosend,"ACTIVE") == 0) { filetosend = filename; }
for (i = 0; i < 15; i ++) {
if (filetosend == '.') { hadExtension = 1; }
if (filetosend == '\r' || filetosend['i'] == '\n') { filetosend = '\0'; break; } // remove extra characters
}
if (hadExtension == 0 && i <= 11) { // Automagically add .TXT for things that have no extension
filetosend = '.';
filetosend[i+1] = 'T';
filetosend[i+2] = 'X';
filetosend[i+3] = 'T';
// This does not null-terminate, assuming that any /r/n would be overwritten by the first ".T"
}
gm862_upload("SENDING ",8); gm862_upload(filetosend,strlen(filetosend)); gm862_upload("...\r\n",5);
res = f_open(&SD_File_Handle_2, filetosend, FA_READ);
if (res != FR_OK) {
gm862_upload("OPEN FAILED\r\n",13);
taskENABLE_INTERRUPTS();
xTaskResumeAll();
return res;
}
else {
gm862_upload("\r\n***START***\r\n",15);
while (1) {
res = f_read(&SD_File_Handle_2, buffer, sizeof(buffer),(UINT *) &br);
if (res || br == 0) { gm862_upload("\r\n***END***\r\n",13); break; } // Error or EOF
int j;
for (j = 0; j < sizeof(buffer); j++) { gm862_addchar(buffer[j]); }
//if (br % 512 == 0) { debug_printf("\nSector edge\n"); }
}
f_close(&SD_File_Handle_2);
taskENABLE_INTERRUPTS();
xTaskResumeAll();
return res;
}
}


Frankly, I don't care a whole heck of a lot of this is blocking (I'd rather it not be) - I just want it to send a file and keep on trucking! It does something similar for f_write, but I imagine solving this will solve that...

Thanks!

RE: LPC2129 - DAbt Handler using FatFS

Posted by Richard on July 25, 2012
What architecture are you running on?
Is you task stack big enough to have 512 bytes on it?
You should not call taskDISABLE/ENABLE_INTERRUPTS() - only taskENTER/EXIT_CRITICAL().
There is no point suspending the scheduler if interrupts are disabled.

If you are using FatFS, then presumably you also have a diskio interface, and that is a whole load of code. I think you first need to work out how to debug the data abort, and how to do that depends on the architecture you are using.

Regards.

RE: LPC2129 - DAbt Handler using FatFS

Posted by J.S. on July 26, 2012
Hi Richard,

I am running an LPC2129 (ARM7TDMI) in ARM mode. The stack should be large enough - even if I change it to BYTE buffer[2], or even [1], it still fails.

Thanks for the note on taskENTER/EXIT. I will update my code accordingly.

As for FatFS, yes, I am using diskio.c and a home-grown SD driver that seems to work fairly reliably. I believe I could trace it if I could print the value of R14, but without knowledge of assembly or inline assembly, that may not be trivially easy for me to do.

RE: LPC2129 - DAbt Handler using FatFS

Posted by Richard on July 26, 2012
You should be able to view the value of R14 in the debugger. Make sure you are viewing the system mode R14 though, not the exception mode R14.

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists