kiwi Posted February 27, 2015 Report Share Posted February 27, 2015 Hello guys,I have a Stm32f429 with an sd card connect via SDIO, using GFILE to access the card works like a charm but it seems there is a initialization order problem when I try to save calibration data for my touch display on the card.Here is the relevant part of my main.c.If I run the code like this gFileOpen() in the SaveMouseCalibration() method returns 0, even though I can read/write to the sd card after sdcConnect. I guess this is due to gfxInit() being run before the SDCard is ready.So I moved the SDCard init, start and connect calls in between gfxInit() and chSysInit(), but this leads to a failing gfxInit().As far as I could debug it it hangs on _gfxdispInit() in gdriver.c:48. From there on gdb just prints in ../../../../../../newlib/libc/string/memset.c.Any ideas?btw: I have #define GFX_NO_OS_INIT TRUE in my gfxconf.hthanks,kiwibool_t SaveMouseCalibration(unsigned instance, const void *data, size_t sz){ (void)instance; GFILE* f; uint8_t bsize; bsize = (uint8_t)sz; if((f = gfileOpen("calib.gfx", "w")) == 0) return false; if(gfileWrite(f, (void*)&bsize, 1) != 1) goto fail; if(gfileWrite(f, data, bsize) != bsize) goto fail; gfileClose(f); return true; fail: gfileClose(f); return false;}bool_t LoadMouseCalibration(unsigned instance, void *data, size_t sz){ (void)instance; GFILE* f; if((f = gfileOpen("calib.gfx", "r")) == 0) return false; if(gfileRead(f, (void*)&sz, 1) != 1) goto fail; if((data = gfxAlloc(sz)) == NULL) return false; if(gfileRead(f, (void*)data, sz) != sz) goto fail; gfileClose(f); return true; fail: gfileClose(f); return false;}int main(void){ GEvent* pe; /* Init ChibiOS */ halInit(); chSysInit(); /* Init Display and uGFX */ gfxInit(); gdispSetBacklight(100); gdispSetContrast(100); /* Initialize SDCard over SDIO */ sdcObjectInit(&SDCD1); sdcStart(&SDCD1, &sdccfg); /* If SDCard not connected exit */ //TODO: enable card insertion monitor. if(sdcConnect(&SDCD1) != CH_SUCCESS) return 0; /* Attach events */ geventListenerInit(&gl); gwinAttachListener(&gl); /* Insert other threads hear */ /* Create widgets */ createGUI(); /* Listen for events */ while(true) { pe = geventEventWait(&gl, TIME_INFINITE); switch(pe->type) { } } /* Return success */ return 1;} Link to comment Share on other sites More sharing options...
kiwi Posted February 27, 2015 Author Report Share Posted February 27, 2015 Hello,I investigated my issue further and found out that this does work:/* uGFX */#include /* ChibiOS */#include "ch.h"#include "hal.h"#include "main.h"/* SDCDriver config. */static SDCConfig sdccfg = {0};int main(void){ halInit(); chSysInit(); /* Initialize SDCard over SDIO */ sdcObjectInit(&SDCD1); sdcStart(&SDCD1, &sdccfg); if(sdcConnect(&SDCD1) != CH_SUCCESS) return 0; GFILE* file; file = gfileOpen("test.txt", "w"); gfileWrite(file, (void*) "main1", 5); gfileClose(file); while(TRUE) { chThdSleepMilliseconds(500); } return 1;}but this does not work (this time I let gfxInit() take care of ChibiOS init)/* uGFX */#include /* ChibiOS */#include "ch.h"#include "hal.h"#include "main.h"/* SDCDriver config. */static SDCConfig sdccfg = {0};int main(void){ gfxInit(); /* Initialize SDCard over SDIO */ sdcObjectInit(&SDCD1); sdcStart(&SDCD1, &sdccfg); if(sdcConnect(&SDCD1) != CH_SUCCESS) return 0; GFILE* file; file = gfileOpen("test.txt", "w"); gfileWrite(file, (void*) "main2", 5); gfileClose(file); while(TRUE) { chThdSleepMilliseconds(500); } return 1;}Do I have to initialize Gfx in a different way?thanks,kiwi Link to comment Share on other sites More sharing options...
inmarket Posted February 27, 2015 Report Share Posted February 27, 2015 I will do some testing today and get back to you.Hmm, it's a nasty initialisation order issue of some kind. Link to comment Share on other sites More sharing options...
inmarket Posted February 28, 2015 Report Share Posted February 28, 2015 I have added a feature which should solve this problem.You will be able to allow gfxInit() to initialise the operating system and just define a routine with your extra initialisation code that needs to happen before anything else.Read this article: viewtopic.php?f=9&t=169&p=1284#p1284It also contains simpler load and save routines for the calibration data and fixes an allocation fault in your load routine.\Let me know if you have any problems with the new method of fixing this problem. Link to comment Share on other sites More sharing options...
kiwi Posted March 2, 2015 Author Report Share Posted March 2, 2015 Thanks for the feature!But it does not fix the problem. I don't think it is a software issue anymore, but rather a conflict in the pin setup according to http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00071990.pdf the Pin PC10 is used for LCD_R2 (standard config in ChibiOS) but I reconfigured it to be used as SDIO_D2. So I think configuring the SDCard before the LCD breaks the LCD init of GFX and the other way around.To verify this I will connect the SDCard with SPI Mode.I will let you know about the outcome. Link to comment Share on other sites More sharing options...
inmarket Posted March 2, 2015 Report Share Posted March 2, 2015 Yes the stm32429-idiscovery board uses SPI during initialization of the graphics controller. It is however only used during initialisation.The trick to being able to do both comes down to the chip selects associated with the two peripherals. I am not looking at the code now but typically we use an aquire_bus() and release_bus() call in each board file to arbitrate between 2 devices on the same bus.Examine those routines in the graphics controller board file and the corresponding code in the fatfs wrapper and you should be able to get them both to work.From memory the touch initialisation occurs after the lcd initialisation. Link to comment Share on other sites More sharing options...
kiwi Posted March 2, 2015 Author Report Share Posted March 2, 2015 I connected the SDcard via SPI4 now and it worked immediately.Since I don't depend on SDIO yet I will eventually looked into getting it to work with the LCD later.thanks a lot,kiwi Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now