Hot![MicroSD] pic32mx795f512l with MicroSD

Author
luis.nascimento
Starting Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2015/11/20 08:32:27
  • Location: 0
  • Status: offline
2015/11/23 02:56:56 (permalink)
0

[MicroSD] pic32mx795f512l with MicroSD

Hello, 
 
I'm working on a project that requires that I store data every second on a MicroSD card. I have tried the example 'sdcard_fat_single_disk' on the example folders but with no luck. I hope someone here would help me, because it's already been 1 month of me trying to do this.
 
Some information:
  • I'm using Harmony version 1.06.
  • I'm using MPLAB X IDE v3.05.
  • I have a Pic32 Ethernet starter kit 2(  ) with an expansion board (  )
  • I have the Adafruit MicroSD Breakboard (  )
  • I'm using SPI2 and Clock2 of the Pic32 that connects like this: 
    MicroSD Breakboard---------->Pic32
    5V------------------------------->5V
    GND----------------------------->GND
    CLK------------------------------>SCK2
    DO------------------------------->SDI2
    DI-------------------------------->SDO2
    CS-------------------------------->SS2
  • The microSD is 4g in FAT32. 
 
Here's part of the code in that example, it never mounts the disk, and I know the board is working because I have tested with the Arduino and everything worked.


 
#include "app.h"

const uint8_t writeData[13] = "Hello World";

APP_DATA __attribute__ ((coherent, aligned(4))) appData;

void APP_Initialize ( void )
{
    appData.state = APP_MOUNT_DISK;
}

void APP_Tasks ( void )
{
    /* The application task state machine */
     BSP_LEDStateSet(BSP_LED_1, 1);
    switch(appData.state)
    {
        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. */

                appData.state = APP_MOUNT_DISK;
            }
            else
            {
                /* Mount was successful. Unmount the disk, for testing. */

                appData.state = APP_UNMOUNT_DISK;
            }
            break;

        case APP_UNMOUNT_DISK:
            if(SYS_FS_Unmount("/mnt/myDrive") != 0)
            {
                /* The disk could not be un mounted. Try
                 * un mounting again untill success. */

                appData.state = APP_UNMOUNT_DISK;
            }
            else
            {
                /* UnMount was successful. Mount the disk again */

                appData.state = APP_MOUNT_DISK_AGAIN;
            }
            break;

        case APP_MOUNT_DISK_AGAIN:
            if(SYS_FS_Mount("/dev/mmcblka1", "/mnt/myDrive", FAT, 0, NULL) != 0)
            {
                /* The disk could not be mounted. Try
                 * mounting again untill success. */

                appData.state = APP_MOUNT_DISK_AGAIN;
            }
            else
            {
                /* Mount was successful. Set current drive so that we do not have to use absolute path. */

                appData.state = APP_SET_CURRENT_DRIVE;
            }
            break;

        case APP_SET_CURRENT_DRIVE:
            if(SYS_FS_CurrentDriveSet("/mnt/myDrive") == SYS_FS_RES_FAILURE)
            {
                /* Error while setting current drive */
                appData.state = APP_ERROR;
            }
            else
            {
                /* Open a file for reading. */
                appData.state = APP_OPEN_FIRST_FILE;
            }

        case APP_OPEN_FIRST_FILE:
            appData.fileHandle = SYS_FS_FileOpen("FILE_TOO_LONG_NAME_EXAMPLE_123.JPG",
                    (SYS_FS_FILE_OPEN_READ));
            if(appData.fileHandle == SYS_FS_HANDLE_INVALID)
            {
                /* Could not open the file. Error out*/
                appData.state = APP_ERROR;
            }
            else
            {
                /* Create a directory. */
                appData.state = APP_CREATE_DIRECTORY;
            }
            break;

        case APP_CREATE_DIRECTORY:
            if(SYS_FS_DirectoryMake("Dir1") == SYS_FS_RES_FAILURE)
            {
                /* Error while setting current drive */
                appData.state = APP_ERROR;
            }
            else
            {
                /* Open a second file for writing. */
                appData.state = APP_OPEN_SECOND_FILE;
            }
            break;

        case APP_OPEN_SECOND_FILE:
            /* Open a second file inside "Dir1" */
            appData.fileHandle1 = SYS_FS_FileOpen("Dir1/FILE_TOO_LONG_NAME_EXAMPLE_123_1.JPG",
                    (SYS_FS_FILE_OPEN_WRITE));

            if(appData.fileHandle1 == SYS_FS_HANDLE_INVALID)
            {
                /* Could not open the file. Error out*/
                appData.state = APP_ERROR;
            }
            else
            {
                /* Read from one file and write to another file */
                appData.state = APP_READ_WRITE_TO_FILE;
            }

        case APP_READ_WRITE_TO_FILE:

            if(SYS_FS_FileRead(appData.fileHandle, (void *)appData.data, 512) == -1)
            {
                /* There was an error while reading the file.
                 * Close the file and error out. */

                SYS_FS_FileClose(appData.fileHandle);
                appData.state = APP_ERROR;
            }
            else
            {
                /* If read was success, try writing to the new file */
                if(SYS_FS_FileWrite(appData.fileHandle1, (const void *)appData.data, 512) == -1)
                {
                    /* Write was not successful. Close the file
                     * and error out.*/
                    SYS_FS_FileClose(appData.fileHandle1);
                    appData.state = APP_ERROR;
                }
                else if(SYS_FS_FileEOF(appData.fileHandle) == 1) /* Test for end of file */
                {
                    /* Continue the read and write process, untill the end of file is reached */

                    appData.state = APP_CLOSE_FILE;
                }
            }
            break;

        case APP_CLOSE_FILE:
            /* Close both files */
            SYS_FS_FileClose(appData.fileHandle);
            SYS_FS_FileClose(appData.fileHandle1);
             /* The test was successful. Lets idle. */
            appData.state = APP_IDLE;
            break;

        case APP_IDLE:
            /* The appliction comes here when the demo
             * has completed successfully. Switch on
             * green LED. */
            BSP_LEDStateSet(BSP_LED_1, 1);
            break;
        case APP_ERROR:
            /* The appliction comes here when the demo
             * has failed. Switch on the red LED.*/
            BSP_LEDStateSet(BSP_LED_3, 1);
            break;
        default:
            break;

    }

}

 
And here are the Harmony configuration that I'm using:

 

Attached Image(s)

#1
luis.nascimento
Starting Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2015/11/20 08:32:27
  • Location: 0
  • Status: offline
Re: [MicroSD] pic32mx795f512l with MicroSD 2015/11/27 01:24:02 (permalink)
0
up Smile: Smile
#2
Aiden.Morrison
Super Member
  • Total Posts : 729
  • Reward points : 0
  • Joined: 2005/02/25 11:18:31
  • Location: Canada
  • Status: offline
Re: [MicroSD] pic32mx795f512l with MicroSD 2015/11/27 13:28:17 (permalink)
3 (1)
SD cards are 3.3v devices, 5v is well out of spec and may have destroyed the card.  My mistake, just noticed you are using a carrier board that does the 5v 3.3v conversion.
post edited by Aiden.Morrison - 2015/11/27 13:30:23
#3
RISC
Super Member
  • Total Posts : 5355
  • Reward points : 0
  • Status: offline
Re: [MicroSD] pic32mx795f512l with MicroSD 2015/11/27 14:48:47 (permalink)
3 (1)
Hi,
I noticed you checked both Interrupt AND polled mode for SPI driver...
You must select only one mode...(I guess it is interrupt mode)
I recommend you check existing examples MHC setup against yours
Regards
post edited by RISC - 2015/11/27 15:17:35
#4
luis.nascimento
Starting Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2015/11/20 08:32:27
  • Location: 0
  • Status: offline
Re: [MicroSD] pic32mx795f512l with MicroSD 2015/11/30 04:38:09 (permalink)
0
Hello,
 
Thank for your responses, but still no luck. I;m using now SPI1 because I found that SPI2 pins are being used for the Ethernet cable. Also I'm not using now the polled mode. 
 
RISC where can i find the setup MHC examples ? I have altered this one but forgot to save the original one it some other place. Do i need to install all over again to get this examples or is there a place I can download it ?
 
Regards 
#5
Sarp
R&D Engineer
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2016/07/12 12:30:35
  • Location: 0
  • Status: offline
Re: [MicroSD] pic32mx795f512l with MicroSD 2018/03/13 06:43:11 (permalink)
0
I have the same problem. Do you have a solution?
#6
RISC
Super Member
  • Total Posts : 5355
  • Reward points : 0
  • Status: offline
Re: [MicroSD] pic32mx795f512l with MicroSD 2018/03/13 07:16:14 (permalink)
0
Hi,
 
There are various projects using file system :
 
1/ TCPIP projects which are webservers and store the webpages on an SDcard
c:\microchip\harmony\v2_05_01\apps\tcpip\web_server_sdcard_fatfs\
 
2/ File System projects
c:\microchip\harmony\v2_05_01\apps\fs\sdcard_fat_single_disk\
 
Regards
 
 
#7
Sarp
R&D Engineer
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2016/07/12 12:30:35
  • Location: 0
  • Status: offline
Re: [MicroSD] pic32mx795f512l with MicroSD 2018/03/15 00:35:59 (permalink)
0
However, I have PIC32MX795F512L ethernet starter kit II and the project configurations are:

pic32mx795_pim_e16_int_dyn (for PIC32MX devices)
pic32mx795_pim_e16_int_dyn_freertos (for PIC32MX devices)
pic32mx470_pim_e16_int_dyn (for PIC32MX devices)
pic32mz_ec_sk_int_dyn (for PIC32MZ EC devices)
pic32mz_ef_sk_int_dyn (for PIC32MZ EF devices)
pic32mz_ef_sk_int_dyn_freertos (for PIC32MZ EF devices)
pic32mz_da_sk_adma (for PIC32MZ DA devices)

So I did my best on harmony configurator, but no luck.. Please Help
#8
BillP
Super Member
  • Total Posts : 277
  • Reward points : 0
  • Joined: 2014/09/28 07:53:35
  • Location: CA
  • Status: offline
Re: [MicroSD] pic32mx795f512l with MicroSD 2018/03/15 09:25:23 (permalink)
0
This thread deals with the MicroSD card and the Harmony setup.  Your post shows the Ethernet Starter Kit II as your hardware.  I believe none of the MCHP starter kits have a MicroSD card.  Need more information to help.
#9
RISC
Super Member
  • Total Posts : 5355
  • Reward points : 0
  • Status: offline
Re: [MicroSD] pic32mx795f512l with MicroSD 2018/03/15 15:57:40 (permalink)
0
Hi Sarp,
 
As you can understand, Harmony cannot include Out Of the Box examples for the tenths of boards and hardware options combinations.
If the kit you selected is not directly supported, you have 2 options which basically depend upon your experience and time you have to develop :
 
1/ You buy a kit which is supported OOB by the Harmony example you need
 
2/ You adapt an existing example for a different board to your own board. That is what most people do when they develop their own board. How fast you'll do that mostly depend upon your general microcontroller experience and in particular upon your Harmony experience
 
I would say that in your case (PIC32 ethernet starter kit II) you can either go for
1/ Buying the PIC32MZ embedded connectivity with FPU starter kit
2/ Adapting the code from the pic32mx_usb_sk_int_dyn configuration to your board
to do that you'll need to identify differences and reconfigure the Harmony framework to use a different BSP which is not necessary the most obvious thing if you are just starting with Harmony.
 
If you never used Harmony before I would suggest 1 is your best option.
If you have time (I mean weeks or months) and feel comfortable with abstracted programming, you may want to go with option 2
 
Regards
#10
Jump to:
© 2018 APG vNext Commercial Version 4.5