1 year ago
#69889
EserRose
Hard Fault when optimization level 1 is enabled (FreeRTOS)
I have the following function used to test the file system (yaffs2). It is called by a FreeRTOS task with a stack size of 65535. In debug mode, everything appears to work fine, but when I enable -O1, I get a hard fault immediately after printing "Testing filesystem...".
I tried changing the test size to a much lower value, thinking maybe there is a memory issue (note that the FreeRTOS heap is 7MB wide), but nothing changed. Any ideas what might be causing this?
#include <stdio.h>
#include "FreeRTOS.h"
#include "task.h"
#include "yaffs_trace.h"
#include "yaffsfs.h"
int fs_test(void)
{
int fd;
int test_size = 1000000;
const char path[] = "nand/testfile.dat";
int pattern = 0x55;
uint8_t *test;
uint8_t *test_read;
uint32_t start_time, stop_time;
DEBUG_PRINT("Testing filesystem...\n");
fd = yaffs_open(path, O_CREAT | O_EXCL | O_WRONLY, S_IREAD | S_IWRITE);
if(fd < 0) {
DEBUG_PRINT("cannot create test file\n");
return -1;
}
test = pvPortMalloc(test_size);
test_read = pvPortMalloc(test_size);
if(test == NULL || test_read == NULL) {
DEBUG_PRINT("not enough memory\n");
vPortFree(test);
vPortFree(test_read);
yaffs_close(fd);
yaffs_rm(path);
return -2;
}
memset(test, pattern, test_size);
start_time = xTaskGetTickCount();
yaffs_write(fd, test, test_size);
yaffs_close(fd);
stop_time = xTaskGetTickCount();
DEBUG_PRINTF("Average write speed = %d kB/s\n", test_size / (stop_time-start_time));
fd = yaffs_open(path, O_RDWR, S_IREAD | S_IWRITE);
if(fd < 0) {
DEBUG_PRINT("cannot open test file\n");
vPortFree(test);
vPortFree(test_read);
yaffs_close(fd);
yaffs_rm(path);
return -1;
}
start_time = xTaskGetTickCount();
yaffs_read(fd, test_read, test_size);
yaffs_close(fd);
stop_time = xTaskGetTickCount();
DEBUG_PRINTF("Average read speed = %d kB/s\n", test_size / (stop_time-start_time));
if (!memcmp(test, test_read, test_size))
DEBUG_PRINT("file integrity test successful\n");
else
DEBUG_PRINT("file integrity test failed!\n");
yaffs_rm(path);
vPortFree(test);
vPortFree(test_read);
return 0;
}
c
embedded
freertos
0 Answers
Your Answer