2017-09-08 03:21 PM
Function f_write doesn't work correctly to write on SD card. Actually it calls a series of other function and one of them is HAL_SD_WriteBlocks which puts the mcu into
Default_Handler:
Infinite_Loop: b Infinite_LoopThis is the code I have used to write a test string into a file:
FATFS fs;
FIL file;
uint8_t string[]='string';
UINT counter;
if(f_mount(&fs,SD_Path,1)==FR_OK){
if(f_open(&file,'root_f1',FA_WRITE|FA_CREATE_ALWAYS)==FR_OK){
f_write(&file,string,(UINT)sizeof(string),&counter);
}
}
f_close(&file);
f_mount(NULL,'0:',1);�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
I have tried enabling and disabling every interrupts or DMA, changing sd clock, bus width. Does not make difference.
This is while reading from the SD Card works.
CubeMX ver: 4.0
CubeF7 ver: 1.7.0
MCU: STM32F746
#bug #stm32 #fSolved! Go to Solution.
2017-09-14 01:23 PM
Merci !!! That was really helpful. I have placed FIL and FATFS outside of main function and as global and now it works!
Of course in my case, I had to place both of these declarations as global, not just FIL .
2017-09-08 04:29 PM
Ok, I have commented out Infinite_loop and then, debugger goes into this function:
HAL_StatusTypeDef SDMMC_WriteFIFO(SDMMC_TypeDef *SDMMCx, uint32_t *pWriteData)
{
/* Write data to FIFO */
SDMMCx->FIFO = *pWriteData;
return HAL_OK;
}�?�?�?�?�?�?�?
in the next step, it shows a message which says No source available for '__libc_init_array() at 0x8005332'. and the next step goes back to the SDMMC_WriteFIFO again.
2017-09-08 04:44 PM
update 2:
I can easily read and write raw data on sd card using only HAL_SD_WriteBlocks and HAL_SD_ReadBlocks
2017-09-09 03:10 PM
You'll need to determine what IRQ Handler isn't set up right. If you are using C++ remember that it mangles names.
Either you haven't got a Handler or it is miss named.
2017-09-09 11:18 PM
I have not enabled any additional interrupt so I don't expect any IRQ Handler to be set up. As I have explained, there must be a problem in FatFS because I can write data in raw mode.
Also, for setting up a project to work with fatfs, I have followed working tutorials available online which I expect them to work for me too, but they don't.
2017-09-10 01:50 PM
FATFS or more likely the layer below it.
No idea what tutorial you followed, or what code you created. Make sure you have allocated an adequate stack, and that FATFS isn't passing down buffers that don't have alignment suitable for DMA, etc.
Code in diskio.c would be where you look for interfacing into layers below.
2017-09-10 02:10 PM
I have followed this tutorial:
https://www.youtube.com/watch?v=FQ_8AmQbDgM
and alsoFat Filesystem - Mastering STM32 by Carmine Noviello. What I have done is following the tutorial step by step, but I could not reproduce expected results.
I just wanted to make sure there is no another new born bug in HAL.
2017-09-13 01:40 AM
I'm actually experiencing the same problem with some SD cards (ex. a 2GB Sandisk). I have an application that is compiled for both F4 and F2 uC that needs to read some files and write a log file to the SD card. I'm using the SDIO interface with the latest HAL (v1.16) for F4 and (v1.6) for F2 and FatFS 1.12c.
On the F2, the application has been migrated from Std Periheral Library to the HAL. The 'faultly' SD card is working fine with the old application (Std Periph Lib) but no longer with the newest HAL version.I tried to implement it with both DMA or polling, but in both cases the HAL_SD_WriteBlocks() or HAL_SD_WriteBlocks_DMA() are not working correctly.
I'm also taking into account the fact that the HAL might have a bug...2017-09-13 10:57 AM
Thanks for sharing your experience.
For me I don't think it's a bug related to HAL because I can write using HAL functions, but when it comes to integrating fatfs into work, program gets stuck into a infinite loop.
2017-09-14 05:48 AM
In my case, when FIL file; variable is placed as local, the CPU going to HardFault_Handler.
But when I place it as global, working very well.