STM32F4 FATFS f_open failure questions
Posted: Mon Jun 23, 2014 4:11 pm
Hello,
I am working with the STM32F4Discovery board and making a ChibiOS project which utilizes FATFS to write sectors of data to an SD card.
My SD card interface is 4 bit wide.
I have successfully used the FATFS with the Discovery board to read and write files before attempting to move the project to ChibiOS.
Basing my work on the demo project for the STM32F4, I have generated a simple program to open the files system, create a file and write some simple text to the file.
My function calls are all within main().
Each time I run the program f_getfree() fails.
Within f_getfree(), the function chk_mounted() always fails.
After commenting out f_getfree() f_open() always fails.
I wonder if I am missing something from my functions calls here. My main function is below.
Any advice would be greatly appreciated.
Thanks,
Forrest
int main(void) {
halInit();
chSysInit();
// Initialize the SDIO drivers.
sdcStart(&SDCD1, &sdccfg);
// Connect to the SD card:
sdcConnect(&SDCD1);
// Set up the file system:
chThdSleepMilliseconds(100);
// Mount the file system:
err = f_mount(0, &SDC_FS);
if (err != FR_OK){
chSysHalt();
}
else{
fs_ready = TRUE;
}
chThdSleepMilliseconds(100);
err = f_getfree("/", &clusters, &fsp);
if (err != FR_OK) {
chSysHalt();
}
chThdSleepMilliseconds(100);
// Create the test file:
err = f_open(&FileObject, "0:chtest.txt", FA_WRITE | FA_OPEN_ALWAYS);
if (err != FR_OK) {
chSysHalt();
}
// Write some text to the file:
err = f_write(&FileObject, teststring, sizeof(teststring), (void *)&bytes_written);
if (err != FR_OK) {
chSysHalt();
}
// Close the file:
err = f_close(&FileObject);
if (err != FR_OK) {
chSysHalt();
}
// Initialize the timer used for the ISR.
// Set up a general purpose timer structure.
static GPTConfig FiveMsTImerCfg =
{
1000000, // Timer Clock Freq in Hz
// TODO: look at this more indepth later to determine if we are using the
// most power efficient clock set up that we can use here.
FiveMsTimerCallBack // Timer callback function
};
// Start the 5ms timer and set it to run continuously:
// Timer triggers at 5000us (5ms) and calls the callback function FiveMsTImerCfg.
gptStart(&GPTD14, &FiveMsTImerCfg);
gptStartContinuous(&GPTD14, 5000);
/*
* Creates the example thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/*
* Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and check the button state, when the button is
* pressed the test procedure is launched with output on the serial
* driver 2.
*/
while (TRUE) {
if (palReadPad(GPIOA, GPIOA_BUTTON))
TestThread(&SD2);
chThdSleepMilliseconds(500);
}
}
I am working with the STM32F4Discovery board and making a ChibiOS project which utilizes FATFS to write sectors of data to an SD card.
My SD card interface is 4 bit wide.
I have successfully used the FATFS with the Discovery board to read and write files before attempting to move the project to ChibiOS.
Basing my work on the demo project for the STM32F4, I have generated a simple program to open the files system, create a file and write some simple text to the file.
My function calls are all within main().
Each time I run the program f_getfree() fails.
Within f_getfree(), the function chk_mounted() always fails.
After commenting out f_getfree() f_open() always fails.
I wonder if I am missing something from my functions calls here. My main function is below.
Any advice would be greatly appreciated.
Thanks,
Forrest
int main(void) {
halInit();
chSysInit();
// Initialize the SDIO drivers.
sdcStart(&SDCD1, &sdccfg);
// Connect to the SD card:
sdcConnect(&SDCD1);
// Set up the file system:
chThdSleepMilliseconds(100);
// Mount the file system:
err = f_mount(0, &SDC_FS);
if (err != FR_OK){
chSysHalt();
}
else{
fs_ready = TRUE;
}
chThdSleepMilliseconds(100);
err = f_getfree("/", &clusters, &fsp);
if (err != FR_OK) {
chSysHalt();
}
chThdSleepMilliseconds(100);
// Create the test file:
err = f_open(&FileObject, "0:chtest.txt", FA_WRITE | FA_OPEN_ALWAYS);
if (err != FR_OK) {
chSysHalt();
}
// Write some text to the file:
err = f_write(&FileObject, teststring, sizeof(teststring), (void *)&bytes_written);
if (err != FR_OK) {
chSysHalt();
}
// Close the file:
err = f_close(&FileObject);
if (err != FR_OK) {
chSysHalt();
}
// Initialize the timer used for the ISR.
// Set up a general purpose timer structure.
static GPTConfig FiveMsTImerCfg =
{
1000000, // Timer Clock Freq in Hz
// TODO: look at this more indepth later to determine if we are using the
// most power efficient clock set up that we can use here.
FiveMsTimerCallBack // Timer callback function
};
// Start the 5ms timer and set it to run continuously:
// Timer triggers at 5000us (5ms) and calls the callback function FiveMsTImerCfg.
gptStart(&GPTD14, &FiveMsTImerCfg);
gptStartContinuous(&GPTD14, 5000);
/*
* Creates the example thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/*
* Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and check the button state, when the button is
* pressed the test procedure is launched with output on the serial
* driver 2.
*/
while (TRUE) {
if (palReadPad(GPIOA, GPIOA_BUTTON))
TestThread(&SD2);
chThdSleepMilliseconds(500);
}
}