2017-10-30 04:46 AM
Hi to everyone,
I just bought STM32F769 Disco Board as platform to develop SW for my next project. I'm using CubeMX 4.23, F7xx FW package 1.8.0 and latest SW4STM32. For the CubeMX I was choosing the processor type and not the Disco Board as later on it will be an own PCB and I wanted to be as much independent as possible.
As I tried to get SD Card and FAT FS running I realized that Disk Init and therefore Hardware init on the MCU seems to go wrong. I debugged it down and found 2 issues in the code generated by CubeMX:
First is very simple as the card detect pin needs to be inversed in the fatfs_platform.c file to fit the Disco Board.
Second issue is that the SD_initialize function of sd_diskio.c just does nothing (ok it calls CheckStatus but doesn't init anything)
Therefore I modified from original code:
/**
* @brief Initializes a Drive
* @
param
lun
: not used* @
retval
DSTATUS: Operation status*/
DSTATUS
SD_initialize(
BYTE
lun)
{
return
SD_CheckStatus(lun);
}
to:
/**
* @brief Initializes a Drive * @param lun : not used * @retval DSTATUS: Operation status */DSTATUS SD_initialize(BYTE lun){ Stat = STA_NOINIT;if(BSP_SD_Init() == MSD_OK)
{ return SD_CheckStatus(lun); }return Stat;
}So far it works all fine...
Now my questions:
1: Was this the right way to solve it or did I oversee something?
2: How/where can I Change the source files for the CubeMX so that after newly generating the Project files my changes are kept? I was looking for the .c files in the FW package but there are everywhere in the examples but nowhere seems to be a source Location for the cubeMX....
Thanks in advance
Stefan
2017-10-31 12:34 AM
Hello
s.mueller
,Thank you for your contribution. Your issue is raised internally to the appropriate teamfor further review.
We will come back to you as soon as possible.
Best Regards
Imen
2017-11-23 02:49 AM
Hello
s.mueller
,
The issue will be solved in the next official release (4.24).
Our apologies again for that regression impacting the series supporting FatFS R0.12c (F4, F7, H7 and L4).Back to your questions, in fact, modifying generated code is useless unless code is added in what we call 'user sections'.
You will find different places in some files (such as sd_diskio.c) looking like:/* USER CODE BEGIN sectionName */
/* place for user code */ /* USER CODE END sectionName */The user code added there will be kept when generating again the project.
As a workaround, in order to fix the current issue before the 4.24 is available, I can suggest you a patch, using the existing user sections:/* USER CODE BEGIN beforeFunctionSection */
/* can be used to modify / undefine following code or add new code */ #ifdef BROKEN_CODE /* Note: not defined, then following code will be ignored when preprocessing the C file */ /* USER CODE END beforeFunctionSection */ /* Private functions ---------------------------------------------------------*/ static DSTATUS SD_CheckStatus(BYTE lun) { Stat = STA_NOINIT;if(BSP_SD_GetCardState() == MSD_OK)
{ Stat &= ~STA_NOINIT; }return Stat;
}/**
* @brief Initializes a Drive * @param lun : not used * @retval DSTATUS: Operation status */ DSTATUS SD_initialize(BYTE lun) { return SD_CheckStatus(lun); }/**
* @brief Gets Disk Status * @param lun : not used * @retval DSTATUS: Operation status */ DSTATUS SD_status(BYTE lun) { return SD_CheckStatus(lun); }/* USER CODE BEGIN beforeReadSection */
#else static DSTATUS SD_CheckStatus(BYTE lun) { Stat = STA_NOINIT;if(BSP_SD_GetCardState() == MSD_OK)
{ Stat &= ~STA_NOINIT; }return Stat;
}/**
* @brief Initializes a Drive * @param lun : not used * @retval DSTATUS: Operation status */ DSTATUS SD_initialize(BYTE lun) { Stat = STA_NOINIT; if(BSP_SD_Init() == MSD_OK) { return SD_CheckStatus(lun); } return Stat; }/**
* @brief Gets Disk Status * @param lun : not used * @retval DSTATUS: Operation status */ DSTATUS SD_status(BYTE lun) { return SD_CheckStatus(lun); } #endif /* USER CODE END beforeReadSection */Not that beautiful, I agree, but should fix the issue (till the 4.2.4.0 solves it in a cleaner way).
Let us know if it does not.
Regards,
Fred
2018-01-05 03:53 AM
Hi Fred,
Do you also have a fix for fatfs in combination with FreeRTOS?
So far i found that the CubeMX generated code is also missing the code to create the SD_Queue. (I found it in another example)
/* Create SD operation Queue */
osMessageQDef(SD_Queue, QUEUE_SIZE, uint16_t); SDQueueID = osMessageCreate (osMessageQ(SD_Queue), NULL);That got me further with the debugging, but it is still not working so I am still missing something.
Board: STM32F769I-EVAL
Regards
Stefan
2018-01-10 07:03 AM
Hi Stefan,
watch out here:
https://community.st.com/0D50X00009bMM8bSAG
Best regards
Stefan