This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RL-FLASHFS fwrite() causing Hard Fault !

Hi Everyone

I am hoping someone might be able provide me with some inspiration or something !!

I have a problem within the application I am developing and am struggling to work out what is going wrong !

Development environment details!

1. Processor STM32F103RCT6
2. Keil ARM-MDK, RealView etc...
3. Running RL-ARM (RTOS) with RL-FLASHFS configured to run using SDIO connected micro sd-card.

There are a number for tasks with in my system. One receives mail box messages. The messages contain data that is to be logged to files on the micro-SD card.

The code that performs the logging is below. It is self contained. That is to say it performs the Open, write to disk and Close operations.

The code runs quite happily for sometime but then suddenly stops. If I then stop the code running, it is stuck in never ending loop in the HardFault interrupt handler. (That is shown below as well)

I can see from the value of variable ul_Task_Debug_Count that it fails at the first fwrite() call. (highlighted below with // **** FAILS HERE **** comment)

I know this because ul_Task_Debug_Count = 0x50000000. (although the example shown uses fwrite() it does exactly the same even if I just use a plain and simple fputc(‘A’,f) instead.

Just to be clear â€" it does not fail every time. Just after some extended running.

Any ideas you might have for things to try mill be welcome!!

LOGGING ROUTINE !!

void AS_Logger_LogEvent(LOG_MESSAGE *Message)
{ char FileName[MAX_FILENAME_SIZE]; FILE *f;

unsigned char uc_ChkSum = 0; unsigned short us_RecNum = 0;

ul_Task_Debug_Count = 0x10000000;

// get filename if (AS_Logger_GetFileName(Message, FileName)) {

ul_Task_Debug_Count = 0x20000000;

f = fopen (FileName, "a"); // open file for append - add new record to end

ul_Task_Debug_Count = 0x30000000;

if (f) { // write record to disk

ul_Task_Debug_Count = 0x40000000;

// recnum us_RecNum = AS_Logger_GetNextRecordNumber(Message);

ul_Task_Debug_Count = 0x50000000; fwrite (&us_RecNum, sizeof (us_RecNum), 1, f); // **** FAILS HERE ****

ul_Task_Debug_Count = 0x60000000;

// ErrType fwrite (&Message->uc_ErrorType, sizeof(Message->uc_ErrorType), 1, f);

ul_Task_Debug_Count = 0x70000000;

// ErrCode fwrite (&Message->uc_ErrorCode, sizeof(Message->uc_ErrorCode), 1, f);

ul_Task_Debug_Count = 0x80000000;

// Timestamp fwrite (&Message->ul_TimeStamp, sizeof(Message->ul_TimeStamp), 1, f);

ul_Task_Debug_Count = 0x90000000; // Size fwrite (&Message->uc_Size, sizeof(Message->uc_Size), 1, f);

ul_Task_Debug_Count = 0xa0000000; // data if (Message->uc_Size) // data to write ? { ul_Task_Debug_Count = 0xb0000000; fwrite (Message->uc_Data, 1, Message->uc_Size, f); }

ul_Task_Debug_Count = 0xc0000000;

// chksum uc_ChkSum = AS_Logger_GetRecordChkSum(us_RecNum, Message); fwrite (&uc_ChkSum, sizeof(uc_ChkSum), 1, f);

ul_Task_Debug_Count = 0xd0000000; // close it fclose (f);

ul_Task_Debug_Count = 0xe0000000;

} else { // failed to open file - do something ul_Task_Debug_Count = 0xf0000000; } }
}

HARD FAULT HANDLER

void AS_CTL_HardFault_Handler(void) __irq
{ BACKUP->ul_Hardfault_Count++; BACKUP->ul_Task_Debug_Count_Lo = ul_Task_Debug_Count & 0xFFFF; BACKUP->ul_Task_Debug_Count_Hi = ((ul_Task_Debug_Count >> 16 ) & 0xFFFF); while (1);
}

Thanks in advance