Mounting LittleFS on MT29F1G01 Flash with STM32L083 Causes HardFault_Handler Error
Hi all,
I'm currently working on a project that involves reading data from an audio codec using I2S and storing it on flash memory. For this task, my setup includes an STM32L083, CS4265, and a MT29F1G01 flash.
In my initial approach, I attempted to mount the flash as a filesystem using LittleFS (LFS). However, each time I try to mount the flash, I'm directed to the HardFault_Handler error.
As someone new to programming the STM32, I have managed to set up my environment in VSCode with the necessary extensions, and I'm able to compile, flash, and debug my code. Moreover, I've successfully written an interface driver for the flash, which lets me read and write data to it without issues.
I'm under the impression that I've correctly configured LFS with the following:
const struct lfs_config cfg = {
.read = mt29f1g01_lfs_read,
.prog = mt29f1g01_lfs_prog,
.erase = mt29f1g01_lfs_erase,
.sync = mt29f1g01_lfs_sync,
.read_size = 2048,
.prog_size = 2048,
.block_size = 64 * 2048,
.block_count = 1024,
.lookahead_size = 2048,
.cache_size = 2048,
.block_cycles = -1
};
I've attempted to mount the LittleFS with this code:
int err = lfs_mount(&lfs, &cfg);
if (err)
{
err = lfs_format(&lfs, &cfg);
if (err)
{
SEGGER_RTT_printf(0, "Error formatting the filesystem\r\n");
return -1;
}
err = lfs_mount(&lfs, &cfg);
if (err)
{
SEGGER_RTT_printf(0, "Error mounting the filesystem\r\n");
return -1;
}
}
Upon observing the call stack, it seems to originate from bl __libc_init_array in startup_stm32l083xx.s. I'm unsure if I'm interpreting this correctly.
I'm left wondering whether something in the LFS libraries could be causing the hard fault. How can I trace the root cause of this problem? Any help would be appreciated.
Thank you!
