ErichStyger / McuOnEclipse_PEx

McuOnEclipse Processor Expert Source Files and Components
Other
66 stars 30 forks source link

SD Card SPI disable on speed change #8

Closed MattGeerts closed 9 years ago

MattGeerts commented 9 years ago

In SD1.c the function SD1_SetFastMode contains:

void SD1_SetFastMode(void) { SD1_SPI_Disable(); SD1_SPI_SetFastMode(); /* the SPI clock is set to the maximum supported by the MCU and allowed by the SD card */ speedMode = SD1_ACTIVATE_MODE_FAST; SD1_SPI_Enable(); }

The SD1_SPI_Disable function sets the enable flag to false: ((SM1_TDeviceDataPtr)DeviceDataPtr)->EnUser = FALSE;

Then the SD1_SPI_SetFastMode() function checks to see if it is false and throws an error: if (!((SM1TDeviceDataPtr)DeviceDataPtr)->EnUser) { /* Is the device disabled by user? / return ERRDISABLED; / If yes then error */ }

So the SD1_SetFAstMode sets itself up to fail, the result being that it never goes to fast mode. The same is true of SetSlowMode, but it doesn't matter because it defaults to slow mode on startup.

I see a comment in SM1_SelectConfiguration (which is the aliased call from SD1_SPI_SetFastMode) that says this can be ignored, but I can't find a place in PE with the ignore setting mentioned: /* Device state test - this test can be disabled by setting the "Ignore enable test" property to the "yes" value in the "Configuration inspector" */

ErichStyger commented 9 years ago

Hi Matt, thanks for reporting this. Indeed, this is an issue if using the LDD drivers. I'm working on a fix. Erich

MattGeerts commented 9 years ago

Erich,

The "thanks" is all yours. Your website and drivers are making my life much easier.

-Matt

ErichStyger commented 9 years ago

Hi Matt, thank you for that, feeling a little bit better now :-) I have implemented a fix and committed it: https://github.com/ErichStyger/McuOnEclipse_PEx/commit/5b1212d0533c5456471fe7677f39d9ea7ff203fc

The only problem I have is: I'm not sure any more why I had to disable the SPI around changing the speed. I have tested it now on two Kinetis boards, one with LDD SPI and one normal SPI, and it works fine with that change. As a bonus, the LDD version is now about 3 times faster than before (FRDM-K64F with microSD card): 'old version': CMD> Benchmark: open file, write 10k times 10 bytes (100'000 bytes), close file: Deleting existing benchmark files... Creating benchmark file... 3100 ms needed for creating. Reading benchmark file... 2810 ms needed for reading. Copy file (100'000 bytes)... 6070 ms needed for copy. done!

New version: FAT1 benchmark Benchmark: open file, write 10k times 10 bytes (100'000 bytes), close file: Deleting existing benchmark files... Creating benchmark file... 1220 ms needed for creating. Reading benchmark file... 980 ms needed for reading. Copy file (100'000 bytes)... 2030 ms needed for copy. done!

Erich

ErichStyger commented 9 years ago

Let me know if you need the .bean file. Simply reopen the ticket if there is still a problem.

Thanks again!

MattGeerts commented 9 years ago

Thanks Erich!

I have not yet learned to change source into beans, so if you can send the bean to [email removed]" I'll test it out on Monday!

ErichStyger commented 9 years ago

Maybe easier than email: I have uploaded the .peupd file of the SD_Card component: sd_card_08 08 2015 peupd As GitHub only allows image files: remove the .png extension before using it.

Let me know if you see any issues, Erich

MattGeerts commented 9 years ago

Downloaded, installed, tested, working.

Thanks again, Erich.