2017-05-09 02:18 AM
Dear community, I am using STM32F746 Discovery and the IDE is Keil C. I have a problem with Keil C Compiler.
My project have 2 parts:Part 1. Get pictures (BMP) from SD Card and print to LCD screen. It is working well.
Part 2. Measure analog signal by ADC, get and save data from/to RTC , External Flash, then print the data to LCD screen. It is working well too.
However, the problem is just only one part is working without the other part in my code. When i add both in my code, it is not work (just only SD Card is not work).
Example:
A. Only part 1:
int main(void)
{ System_Config(); // Configure the System SD_BMP_LCD(); // PART 1 -INIT -
then get bmp picture from sd card then show in LCD -WORK WELL
//
ADC_RTC_EXFLASH_LCD(); //
PART 2 -
INIT -
then ADC measure, get and save data f/t RTC and External Flash then show in LCD. NOT RUN, of course
}
Program Size: Code=31416 RO-data=49736 RW-data=256 ZI-data=104808
---------------------------------------------------------------------------------------------------------------------------------------
B. Only part 2:
int main(void)
{ System_Config(); // Configure the System// SD_BMP_LCD(); //
PART 1 - NOT RUN, of course
ADC_RTC_EXFLASH_LCD(); // PART 2 -WORK WELL
}
Program Size: Code=129840 RO-data=49784 RW-data=296 ZI-data=103360
---------------------------------------------------------------------------------------------------------------------------------------
C. Both part 1 and 2:
int main(void)
{ System_Config(); // Configure the System
SD_BMP_LCD(); // PART 1 -
NOT WORK !?
ADC_RTC_EXFLASH_LCD(); // PART 2 -WORK WELL
}
Program Size: Code=144036 RO-data=49980 RW-data=316 ZI-data=105020
In this case, the SD Card cannot interface. Fatfs not work. f_mount, f_open, f_read return error result. However, LCD and other peripherals still working very good. Just only SD Card peripheral has a problem.
---------------------------------------------------------------------------------------------------------------------------------------
In other case, i changed my code as follow:
int main(void)
{ System_Config(); // Configure the System SD_BMP_LCD(); // PART 1 -WORK WELL
while(1); // Add this forever loop to prevent program access to PART 2
ADC_RTC_EXFLASH_LCD(); // PART 2 - NOT RUN, of course
}
Program Size: Code=31416 RO-data=49736 RW-data=256 ZI-data=104808
>> Although i add both part 1 and 2 into the source code, the Code Size is only 31416 byte. It means
PART 2 is not built
into machine code. So i thought that the optimization setting have an affect to my code. The currently optimization is Level 3 (-O3) and Optimize for Time is checked.---------------------------------------------------------------------------------------------------------------------------------------
So that, i change my code as follow
:
int main(void)
{ System_Config(); // Configure the System SD_BMP_LCD(); // PART 1 -NOT WORK !?
int i = 0; // Add this function to prevent program access to PART 2, but focus to build PART 2
HAL_Delay(100);
if (i == 50)
{
ADC_RTC_EXFLASH_LCD(); // PART 2 - NOT RUN, of course
}
}
Program Size:
Code=144076RO-data=49980 RW-data=316 ZI-data=105020
Now the Code size is 144076. It seems that both part 1 and 2 were build. But only part 1 is accessable, part 2 can not accessed. However, part 1 now work in this situation. !?!?!???
---------------------------------------------------------------------------------------------------------------------------------------
Besides, i changed startup_stm32f746xx.s (currently):
Stack_Size EQU 0x10000
Heap_Size EQU 0x10000
The orginal is:
Stack_Size EQU 0x400
Heap_Size EQU 0x800
I don't know what is the means of stack and heap size. So i just change for fun, just try, but no any happening in both situation.
Now, I am deadlocking after many times to try in other to make both part 1 and 2 work well. So i thought that i should be ask here. Anyone have any idea?I would be very happy if someone could comment on this topic.
Duy Khanh#conflict #sd-card #stm32f7Solved! Go to Solution.
2017-05-09 10:16 AM
Thank you for your advice. I was debugs and tries all possible ways in my code, but i can't solve it. So I decided to remake all source code with STM32Cube. I was configure all necessary peripherals, then config the clock. I realized that the problem in my previous code is the clock was wrong config. The maxspeed of SDMMC is just 50MHz and got directly from SYSCLK. In my previous code, SYSCLK is 216Mhz, so SDMMC too, and of course it can not work because overclock of SDMMC. I was change SYSCLK from 216 MHz to 50 MHz. Now both SD card (part 1) and part 2 working well. I spent 3 weeks in this problem. And now, the problem solved!.
Thank you very much!
Duy Khanh
2017-05-09 05:33 AM
The issue is not with the code you are showing, you'll need to dig deeper and make sure the initialization code doesn't turn off peripheral clocks required, or interferes with pins the other peripheral uses.
You'll need to debug.
Changing the stack/heap to huge values is not a productive way to debug this. Review what the code is doing.
2017-05-09 10:16 AM
Thank you for your advice. I was debugs and tries all possible ways in my code, but i can't solve it. So I decided to remake all source code with STM32Cube. I was configure all necessary peripherals, then config the clock. I realized that the problem in my previous code is the clock was wrong config. The maxspeed of SDMMC is just 50MHz and got directly from SYSCLK. In my previous code, SYSCLK is 216Mhz, so SDMMC too, and of course it can not work because overclock of SDMMC. I was change SYSCLK from 216 MHz to 50 MHz. Now both SD card (part 1) and part 2 working well. I spent 3 weeks in this problem. And now, the problem solved!.
Thank you very much!
Duy Khanh
2017-05-11 02:00 AM
I have been having a similar problem. I use the IAR Compiler and I am using custom hardware (rather than the Discovery board). I have an external LCD controller chip, I use the USB and the SDMMC. I have times when my code works OK and I can read from the card and communicate via USB. If I add a small function but DO NOT call it from anywhere and recompile, the system fails and either the USB or SDMMC fails or at least behaves so erratic I can't use it.
It was comforting to see someone else with a similar problem but with different hardware and a different compiler.
I am using STMCubeMX. I took a closer look at my Clock Configuration, my SDMMC clock was 48MHz and derived from PLL48CLK not the SYSCLK, so changing my SYSCLK will have no effect. I did however increase my SYSCLK to 216MHz (I was using 168MHz). My SDMMC is now working a lot more reliably. I have yet to test my other peripherals.
Basically, you may have been lucky in that your code will stop working again as changing the SYSCLK to 50MHz may only temporarily fix the issue, assuming you have the same problem as I do. Secondly, you could try changing the source of the clock for your SDMMC so that you can pout the SYSCLK back up again, if you want to.
Many thanks!
Ian
2017-05-11 06:48 AM
You're 100% right!
In the first time, when i decrease the SYSCLK to 50MHz and the source of SDMMC clock got from SYSCLK directly, my code works again, except the LCD fails with many horizontal streaky. That is just temporarily fix the SDMMC issue.After that, I was changing the SYSCLK back up to 216MHz (in order to make the LCD works again), and reconfigure the source of SDMMC clock was 48MHz, derived from PLL48CLK, like your way. Now my system is working a lot more reliably, all the peripherals which is used in my system is working really good.
Thank you for your comment!
Duy Khanh