• AVR Freaks

Helpful ReplyHot!How to run a simple example of SD Card with harmony v2?

Page: 123 > Showing page 1 of 3
Author
Nmaster88
Starting Member
  • Total Posts : 55
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: online
2019/06/25 08:24:11 (permalink)
0

How to run a simple example of SD Card with harmony v2?

 What i want to do is have an example that writes in the SD Card, it would be nice to create a .txt file with some info inside.
 
Looking at the examples of Harmony v2 i found, that it has some projects related to SD Card.
I found one that maybe is what i'm looking for in C:\microchip\harmony\v2_06\apps\fs\sdcard_fat_single_disk which is for PIC32MX795F512L.
 
Still it seems overwhelming to understand and to relate it to my setup.
 
What i have:
-PIC32MX470F512L
-DM3CS-SF (sdcard)
-Custom PCB(no BSP)
 
The connections are the following (from pic to sdcard):
RF3(SD_DI)     ->  CMD(MOSI)
RF5(SD_DO)    ->  DAT0(MISO)
RF12(SD_CS)   ->  DAT3(CS#)
RD10(SD_CLK) ->  CLK(SCK)
 
Looking at the Options from MPLAB Harmony Configurator i don't even understand how i can do these connection.
But i suppose that on
Harmony Framework Configuration -> Drivers -> SD Card -> Use SD Card Driver?
-> On Chip Select Port: PORT_CHANNEL_F
-> Chip Select Port But: PORTS_BIT_POS_12
 
Harmony Framework Configuration -> Drivers -> SD Card -> Use SD Card Driver? -> Enable Write Protect Check?
-> Write Protect Port: PORT_CHANNEL_F
-> Write Protect Port Bit: PORTS_BIT_POS_3
I removed this
 
The clock i have to do it, with the interrupt of a Timer, right?
At this time i have the processor running with FRC with PLL at 32MHz.
 
 
Is that correct?
And what about the remaining pins? RF3,RF5 and RD10?
 
 
post edited by Nmaster88 - 2019/07/05 02:53:30

Attached Image(s)

#1
tixmcprods
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2019/06/12 15:33:51
  • Location: 0
  • Status: offline
Re: How to run a simple example of SD Card with harmony? 2019/06/25 23:13:08 (permalink)
0
Hello,
Enable the corresponding SPI driver !
Then, you have to enable File System, and you can use automount feature.
This example you told is really great, but you can jump directly to create directory step when automount activated.
Try FAT FS with a FAT32 formatted SD Card.
Will tell you more if needed.
Best regards.
#2
TS9
Super Member
  • Total Posts : 732
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to run a simple example of SD Card with harmony? 2019/06/26 09:56:43 (permalink)
0
Hi,


Please go the below path(s) and open in MPLAB X .

C:\microchip\harmony\v2_06\apps\fs\sdcard_fat_single_disk\firmware 

C:\microchip\harmony\v2_06\apps\fs\sdcard_fat_single_disk\firmware\src\system_config\pic32mx470_pim_e16_int_dyn


It supports PIC32MX470 MCU.

Under the Microchip Harmony, Open MHC -> Pin Configuration and Drivers (Enable and Select Line)
change according to your hardware. 


Firstly ,Your SDCard should have the file with Name FILE_TOO_LONG_NAME_EXAMPLE_123.JPG from PC.Once the Demo will Run , It should creates a directory named Dir1 with

If the directory creation is successful, the application opens the file, FILE_TOO_LONG_NAME_EXAMPLE_123_1.JPG,
inside the directory Dir1.


If it works, Well you can create and file as per your requirement.


If not work , Check SD Card  pin by toggle that on DSO. 


Hope this helps...

--
TS9
post edited by TS9 - 2019/06/26 10:30:18
#3
TS9
Super Member
  • Total Posts : 732
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to run a simple example of SD Card with harmony? 2019/06/27 00:25:31 (permalink)
0
And what about the remaining pins? RF3,RF5 and RD10?

 
Please check attachment and change according ..

Attached Image(s)

#4
Nmaster88
Starting Member
  • Total Posts : 55
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: online
Re: How to run a simple example of SD Card with harmony? 2019/07/01 04:15:36 (permalink)
0
Thanks for answers. 
 
Still this doesn't seem to be running with my PIC (that is tested and working).
 
In the example sdcard_fat_single_disk, if i do a simple code:
 
#include <bsp.h>
 
int main ( void )
{
//__XC_UART = 1; // Code is configured to use UART1
/* Initialize all MPLAB Harmony modules, including application(s). */
BSP_LEDOn(APP_SUCCESS_LED);
//LATCbits.LATC1=1;

while ( true )
{
//printf("t\r\n");
/* Maintain state machines of all polled MPLAB Harmony modules. */
//SYS_Tasks ( );
}
/* Execution should not come here during normal operation */
return ( EXIT_FAILURE );
}
 
The LED doesn't turn on.
 
On Pin Settings i did the following:
 
Pin N   Pin ID  Voltage  Name
6         RC1     5V         APP_SUCCESS_LED 
8         RC3     5V         APP_FAILURE_LED 
38       RA1     5V         BSP_LED_2 (I have this pin unconnected)
41       RB12                BSP_SWITCH_12 (I have this pin unconnected)
42       RB13                BSP_SWITCH_13 (I have this pin unconnected)
50       RF5                  SDO1 (DAT0)
51       RF3                  SDI1 (CMD)
67       RA15                U1TX (connected to my ftdi)
70       RD10                SCK1 (CLK)
87       RF0     5V         BSP_SWITCH_CD (I have this pin unconnected)
88       RF1     5V         BSP_SWITCH_WP (I have this pin unconnected)
 
The SDCS (chip select) i suppose that is done through the Drivers configuration in:
Option -> Drivers -> SD Card -> Use SD Card Driver? ->
Chip Select Port: PORT_CHANNEL_F
Chip select Port Bit: PORT_BIT_POS_12
 
I don't know about Enable Write Protect Check? if this needs to be configured, in:
Option -> Drivers -> SD Card -> Use SD Card Driver? -> Enable Write Protect Check?
 
The example should run straightfoward? But not even a LED turns on with either BSP_LEDOn(APP_SUCCESS_LED); or LATCbits.LATC1=1; is it my fault?
 
Btw, in BSP Configuration, i guess i need to put Custom, as i build my own PCB.
 
As i user internal oscillator, i tried changing some configurations in DEVCFG1
Oscillator Selection Bits: FRCPLL
 
EDIT: The example now runs, it seems that on BSP Custom option needs to be selected or nothing works.
 
My app is getting stuck at: 
 
case APP_MOUNT_DISK:
if(SYS_FS_Mount("/dev/mmcblka1", "/mnt/myDrive", FAT, 0, NULL) != 0)
{
/* The disk could not be mounted. Try
* mounting again untill success. */
LATCbits.LATC2=1;
SYS_FS_ERROR err;
err = SYS_FS_Error();
 printf("e%c \r\n",err); //Gives error 3, (3) The physical drive cannot work 
appData.state = APP_MOUNT_DISK;
}
else
{
/* Mount was successful. Unmount the disk, for testing. */
LATCbits.LATC2=0;
appData.state = APP_UNMOUNT_DISK;
}
break;
 
After looking at the oscilloscope i see an oscillating signal on SDCS and SDCLK and its High on SDDI and SDDO.
post edited by Nmaster88 - 2019/07/01 09:32:59
#5
TS9
Super Member
  • Total Posts : 732
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to run a simple example of SD Card with harmony? 2019/07/01 08:52:22 (permalink)
0
Hi,


Post your schematic and Screenshot of MHC Pin Configuration..Here..

(Not Sure but seems , SDCard signal SDI,SDO Swapped?

Which Company's SDCard you are using ? and Capacity in terms of GB?

--
TS9
#6
TS9
Super Member
  • Total Posts : 732
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to run a simple example of SD Card with harmony? 2019/07/01 09:06:43 (permalink)
0
Also..

Btw, in BSP Configuration, i guess i need to put Custom, as i build my own PCB.

No need to change BSP Configuration , Just Leave it as it ..as in Demo.

I don't know about Enable Write Protect Check? if this needs to be configured, in:
Option -> Drivers -> SD Card -> Use SD Card Driver? -> Enable Write Protect Check?

 If you are not using this, you can uncheck this .
 
Did you chose SPI Channel 1 .. ?
in MHC as attachment ..
 
What about Clock Mode and Input Phase
Clock mode -> DRV_SPI_CLOCK_IDLE_LOW_EDGE_FALL  ?
Input Phase -> SPI_INPUT_SAMPLING_PHASE_AT_END    ?
 
 
--
TS9
 
post edited by TS9 - 2019/07/01 09:25:28

Attached Image(s)

#7
Nmaster88
Starting Member
  • Total Posts : 55
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: online
Re: How to run a simple example of SD Card with harmony? 2019/07/01 09:49:26 (permalink)
0
TS9
Hi,


Post your schematic and Screenshot of MHC Pin Configuration..Here..

(Not Sure but seems , SDCard signal SDI,SDO Swapped?

Which Company's SDCard you are using ? and Capacity in terms of GB?

--
TS9

Hi @TS9 i posted an image, about the micro SD i'm testing is one that is used with raspberry pi with 16gb, it has 4 partitions and i formatted them as FAT32.
If your asking about the SD Card connector its a DM3CS-SF
 
#8
Nmaster88
Starting Member
  • Total Posts : 55
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: online
Re: How to run a simple example of SD Card with harmony? 2019/07/01 09:59:12 (permalink)
0
TS9
Also..

Btw, in BSP Configuration, i guess i need to put Custom, as i build my own PCB.

No need to change BSP Configuration , Just Leave it as it ..as in Demo.

I don't know about Enable Write Protect Check? if this needs to be configured, in:
Option -> Drivers -> SD Card -> Use SD Card Driver? -> Enable Write Protect Check?

 If you are not using this, you can uncheck this .
 
Did you chose SPI Channel 1 .. ?
in MHC as attachment ..
 
What about Clock Mode and Input Phase
Clock mode -> DRV_SPI_CLOCK_IDLE_LOW_EDGE_FALL  ?
Input Phase -> SPI_INPUT_SAMPLING_PHASE_AT_END    ?
 
 
--
TS9
 


About the SPI Driver the only thing i had different was the Input Phase which was PHASE_AT_MIDDLE
 
 
#9
TS9
Super Member
  • Total Posts : 732
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to run a simple example of SD Card with harmony? 2019/07/01 10:16:23 (permalink)
0
Change

SPI_INPUT_SAMPLING_PHASE_AT_END then check
post edited by TS9 - 2019/07/01 11:10:12
#10
Nmaster88
Starting Member
  • Total Posts : 55
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: online
Re: How to run a simple example of SD Card with harmony? 2019/07/01 14:14:17 (permalink)
0
TS9
Change

SPI_INPUT_SAMPLING_PHASE_AT_END then check

@TS9 yes i tried changing to that, and it still keeps looping on the same state with same error.
I'm thinking that it could be related to the change in the configurations of the clock, i changed the one in the example to a FRCPLL that after divide/multiplication/etc runs at 32MHz, but i have to use the internal one because i don't have a primary oscillator.
post edited by Nmaster88 - 2019/07/01 14:18:02
#11
TS9
Super Member
  • Total Posts : 732
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to run a simple example of SD Card with harmony? 2019/07/01 17:42:25 (permalink)
0
Nmaster88
TS9
Change

SPI_INPUT_SAMPLING_PHASE_AT_END then check

@TS9 yes i tried changing to that, and it still keeps looping on the same state with same error.I'm thinking that it could be related to the change in the configurations of the clock, i changed the one in the example to a FRCPLL that after divide/multiplication/etc runs at 32MHz, but i have to use the internal one because i don't have a primary oscillator.


1) Did you able to Blink LED with your Internal Oscillator Setting?

2) Have you set POSC OFF ?

3) After Changing FRCPLL ? Have you done Auto Calculate of Frequency under Clock Diagram Tab in MHC ?

4) What frequency did you get on SPI Clock Pin on Scope ? Same as you set at MHC Driver tab?


5) What you are seeing on Serial Port?


6) For Demo , Have you
Copied
FILE_TOO_LONG_NAME_EXAMPLE_123.jpg first to SDCard
From PC.

--
TS9
post edited by TS9 - 2019/07/01 18:32:35
#12
Nmaster88
Starting Member
  • Total Posts : 55
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: online
Re: How to run a simple example of SD Card with harmony? 2019/07/02 01:55:46 (permalink)
0
TS9
Nmaster88
TS9
Change

SPI_INPUT_SAMPLING_PHASE_AT_END then check

@TS9 yes i tried changing to that, and it still keeps looping on the same state with same error.I'm thinking that it could be related to the change in the configurations of the clock, i changed the one in the example to a FRCPLL that after divide/multiplication/etc runs at 32MHz, but i have to use the internal one because i don't have a primary oscillator.


1) Did you able to Blink LED with your Internal Oscillator Setting?

2) Have you set POSC OFF ?

3) After Changing FRCPLL ? Have you done Auto Calculate of Frequency under Clock Diagram Tab in MHC ?

4) What frequency did you get on SPI Clock Pin on Scope ? Same as you set at MHC Driver tab?


5) What you are seeing on Serial Port?


6) For Demo , Have you
Copied
FILE_TOO_LONG_NAME_EXAMPLE_123.jpg first to SDCard
From PC.

--
TS9



1) Yes i can blink LED on and off if i want, right know, to know i'm turning on a LED in the first state (APP_MOUNT_DISK) where when it tries to SYS_FS_Mount.
 
SYS_FS_ERROR err;
err = SYS_FS_Error();
printf("e%c \r\n",err);
In termite i get: e[03] 
 
2) on DEVCFG1 -> Primary Oscillator Configuration (POSCMOD) -> OFF
 
3) I set the clock configuration in DEVCFG2 is it not same as doing in the clock diagram?
 
4) On the images i have on the bottom post, i didn't set a peripheral clock diviser (DIV_1) so i guess (the photo is not complete :() that it's 1/32MHz. Now i tried to use a Peripheral Clock Divisor of 8.
 
5) I provided some photos on initial post.
 
6) I only did it now. Btw this SD Card has 4 partitions, will that be a problem? Thanks.
#13
TS9
Super Member
  • Total Posts : 732
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to run a simple example of SD Card with harmony? 2019/07/02 03:54:38 (permalink)
0

6) I only did it now. Btw this SD Card has 4 partitions, will that be a problem? Thanks.

May be ..Could you please Format the Card in FAT32 .. Try without any partitions.
 
--
TS9
#14
Nmaster88
Starting Member
  • Total Posts : 55
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: online
Re: How to run a simple example of SD Card with harmony? 2019/07/02 09:22:39 (permalink)
0
TS9

6) I only did it now. Btw this SD Card has 4 partitions, will that be a problem? Thanks.

May be ..Could you please Format the Card in FAT32 .. Try without any partitions.
 
--
TS9


I know only have one partition which is: 
removable disk (D:) formated as FAT32. Doing that still haven't solved the problem.
#15
TS9
Super Member
  • Total Posts : 732
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to run a simple example of SD Card with harmony? 2019/07/02 09:59:24 (permalink)
0
Nmaster88
TS9
6) I only did it now. Btw this SD Card has 4 partitions, will that be a problem? Thanks.
May be ..Could you please Format the Card in FAT32 .. Try without any partitions. --TS9

I know only have one partition which is: 
removable disk (D:) formated as FAT32. Doing that still haven't solved the problem.


It's Strange... I have ported this demo to PIC32MX470,460,570
PIC32MK and PIC32MZ-100. On my various customised hardware with or without External Oscillator without any problems..

Not Sure...May be Hardware Issue...


Brand of your SDCard?

Try with different Sdcards..
post edited by TS9 - 2019/07/02 10:03:59
#16
Nmaster88
Starting Member
  • Total Posts : 55
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: online
Re: How to run a simple example of SD Card with harmony? 2019/07/02 12:34:01 (permalink)
0
TS9
Nmaster88
TS9
6) I only did it now. Btw this SD Card has 4 partitions, will that be a problem? Thanks.
May be ..Could you please Format the Card in FAT32 .. Try without any partitions. --TS9

I know only have one partition which is: 
removable disk (D:) formated as FAT32. Doing that still haven't solved the problem.


It's Strange... I have ported this demo to PIC32MX470,460,570
PIC32MK and PIC32MZ-100. On my various customised hardware with or without External Oscillator without any problems..

Not Sure...May be Hardware Issue...


Brand of your SDCard?

Try with different Sdcards..

Yes, but i might have a wrong config on MHC, if you have a little time, can you take a look at the images on my initial post? I will take a look at the soldering on the sd card connector and resistors, i got signal in SDCS and SDCLK pins. Thank you.
#17
TS9
Super Member
  • Total Posts : 732
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to run a simple example of SD Card with harmony? 2019/07/02 19:52:38 (permalink)
0
Uncheck ,
"Enable Write Protect Pin"

Then Check code.. It should work..
#18
Nmaster88
Starting Member
  • Total Posts : 55
  • Reward points : 0
  • Joined: 2019/06/04 03:30:36
  • Location: 0
  • Status: online
Re: How to run a simple example of SD Card with harmony? 2019/07/03 01:42:29 (permalink)
0
TS9
Uncheck ,
"Enable Write Protect Pin"

Then Check code.. It should work..

I think the problem is between the clock frequency, timer and sdcard/spi frequency.
 
About the sdcard/spi frequency i set it to 10000000, i think this number makes sense because a micro sdcard class 10 runs at a minimum of 10MHz.
The timer i havent changed and is with a prescale of 256. 
 
On the example we have a primary oscillator of 8 MHz then we have:
SYSCLK - 8MHz
PBCLK - 4MHz
REFCLKO - 8MHz
 
In my PIC32, i'm using FRCPLL and set it to 32MHz (because i will need this frequency for other things in future) what i have is:
SYSCLK - 32MHz
PBCLK - 32MHz
REFCLKO - 0MHz
 
What you guys think about this?
post edited by Nmaster88 - 2019/07/03 02:18:22
#19
TS9
Super Member
  • Total Posts : 732
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: How to run a simple example of SD Card with harmony? 2019/07/03 02:24:11 (permalink)
0
Hi,

I suggest..


Will it possible for you connect external Oscillator as mentioned in demo ? and Run it...


If it all works ? Then play with FRC and all...
#20
Page: 123 > Showing page 1 of 3
Jump to:
© 2019 APG vNext Commercial Version 4.5