Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIC32 PINGUIONO's and SD
19-03-2012, 02:32 AM,
#1
PIC32 PINGUIONO's and SD
Has anyone had any luck in writing to the SD card?

If so, could you post code?

Thanks,
Dale
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply
21-03-2012, 10:47 PM,
#2
RE: PIC32 PINGUIONO's and SD
Hi KiloOne,

there are SD libraries and examples in the X.3 (development) branch on the http://code.google.com/p/pinguino32 site although the X.3 branch is not necessarily as stable as the trunk. The datalogger example writes data to a file on an SD card. It is possible to use the SD library (together with the associated .pdl32 file) in the trunk version. The code was tested on a PIC32 Pinguino OTG and I have used similar code on a PIC32 Pinguino OTG. I have no experience of using it on other PIC32 Pinguinos but other may have..
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
22-03-2012, 08:17 AM,
#3
RE: PIC32 PINGUIONO's and SD
Thanks!!!

Took me a while to find the x.3 files but I got all the .pde files for SD.

Now I am not sure which .pdl32 files to get from the trunk/p32/lib directory.

Should I just get them all?

I too am using an OTG.

Dale
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply
22-03-2012, 08:27 PM,
#4
RE: PIC32 PINGUIONO's and SD
Hi Dale (KiloOne).

there are various approaches depending on which version of the IDE and what platform (PC/Mac/linux) you are using (it would help other support you if you included this information in your posts as per "READ THIS BEFORE POSTING")

If your are using a version of the X.2 (trunk) then you could replace all the files in the /p32/include/pinguino/libraries/sd folder with the files from the corresponding folder in the x.3 branch and also replace the SD.pdl32 file in the /p3/lib folder with the corresponding file from the x.3 branch. You can download individual files from http://code.google.com/p/pinguino32 by displaying the actual file and then right clicking on the link "View raw file" to the right of the page and then selecting "Save link as ..." from the drop down menu.

If you are using the X.3 branch then checkout the latest x.3 release which should include all the necessary files - see the Main Page of the wiki for a link although you will have to modify the checkout command to reflect the x.3 branch rather than the trunk. In Linux (Ubuntu) it will be something like:-

Code:
svn checkout http://pinguino32.googlecode.com/svn/branches/x.3 pinguino32-read-only

where "pinguino32-read-only" is the name of the folder you are downloading the files into
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
23-03-2012, 10:36 PM, (This post was last modified: 23-03-2012, 10:44 PM by KiloOne.)
#5
RE: PIC32 PINGUIONO's and SD
Thanks, that should be enough.

Sorry, I am using PC and Pinguino IDE X.2 Rev. unknown


PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply
02-05-2012, 02:34 PM,
#6
RE: PIC32 PINGUIONO's and SD
Hi mf01,

I can finally get back to adding SD to my code and I can not seem to get the x.3 files to compile in x.2.

I have done what you suggested but there is a problem when I compile datalogger.pde.

Here is the stdout file after trying to compile:
Code:
if exist C:\Pinguino32X.2\source\main32.o @del C:\Pinguino32X.2\source\main32.o
if exist C:\Pinguino32X.2\source\main32.elf @del C:\Pinguino32X.2\source\main32.elf
if exist C:\Pinguino32X.2\source\main32.hex @del C:\Pinguino32X.2\source\main32.hex
if exist C:\Pinguino32X.2\p32\obj\non-free\processor.o @del C:\Pinguino32X.2\p32\obj\non-free\processor.o
        1 file(s) copied.
C:\Pinguino32X.2\win32\p32\bin\mips-gcc.exe -EL -O3 -ffunction-sections -fdata-sections -Wl,--gc-sections -march=24kc -msoft-float -Wl,-LC:\Pinguino32X.2\p32\obj\non-free -Wl,--defsym,_min_heap_size=16384 -Wl,-Map=C:\Pinguino32X.2\source\output.map -D __PIC32MX__ -D __32MX440F256H__ -D PIC32_PINGUINO_OTG -TC:\Pinguino32X.2\p32\lkr\PIC32_PINGUINO_OTG\procdefs.ld -TC:\Pinguino32X.2\p32\lkr\PIC32_PINGUINO_OTG\elf32pic32mx.x -LC:\Pinguino32X.2\p32\obj\non-free\usb -lm -lgcc -lc -fdollars-in-identifiers -IC:\Pinguino32X.2\p32\include\non-free -IC:\Pinguino32X.2\p32\include\pinguino\core -IC:\Pinguino32X.2\p32\include\pinguino\libraries -IC:\Pinguino32X.2\p32\lkr\PIC32_PINGUINO_OTG -IC:\Pinguino32X.2\examples\10.Libraries\SD -IC:\Pinguino32X.2\p32\obj\non-free -o C:\Pinguino32X.2\source\main32.elf C:\Pinguino32X.2\source\main32.c \
        C:\Pinguino32X.2\p32\obj\non-free\crt0.S \
        C:\Pinguino32X.2\p32\obj\non-free\processor.o \
        C:\Pinguino32X.2\p32\obj\non-free\usb\libcdc.a \
        C:\Pinguino32X.2\p32\obj\non-free\usb\libadb.a \
        C:\Pinguino32X.2\p32\lkr\PIC32_PINGUINO_OTG\ISRwrapper.S \
        C:\Pinguino32X.2\p32\include\non-free\p32xxxx.h \
        -lm -lgcc -lc
In file included from C:\Pinguino32X.2\source\/define.h:12:0,
                 from C:\Pinguino32X.2\source\main32.c:29:
C:\Pinguino32X.2\p32\include\pinguino\core/__cdc.c: In function 'CDCwrite':
C:\Pinguino32X.2\p32\include\pinguino\core/__cdc.c:211:2: warning: passing argument 1 of 'CDCputs' makes pointer from integer without a cast
C:\Pinguino32X.2\p32\include\pinguino\core/__cdc.c:164:6: note: expected 'char *' but argument is of type 'char'
C:\Pinguino32X.2\p32\include\pinguino\core/__cdc.c: In function 'CDCprint':
C:\Pinguino32X.2\p32\include\pinguino\core/__cdc.c:250:20: warning: cast from pointer to integer of different size
C:\Pinguino32X.2\p32\include\pinguino\core/__cdc.c: In function 'CDCgetstring':
C:\Pinguino32X.2\p32\include\pinguino\core/__cdc.c:294:2: warning: return makes integer from pointer without a cast
In file included from C:\Pinguino32X.2\p32\include\pinguino\libraries/sd/fileio.c:25:0,
                 from C:\Pinguino32X.2\source\/define.h:13,
                 from C:\Pinguino32X.2\source\main32.c:29:
C:\Pinguino32X.2\p32\include\pinguino\libraries/sd/sdmmc.c: In function 'initSD':
C:\Pinguino32X.2\p32\include\pinguino\libraries/sd/sdmmc.c:29:15: error: 'SDCS' undeclared (first use in this function)
C:\Pinguino32X.2\p32\include\pinguino\libraries/sd/sdmmc.c:29:15: note: each undeclared identifier is reported only once for each function it appears in
C:\Pinguino32X.2\p32\include\pinguino\libraries/sd/sdmmc.c: In function 'disableSD':
C:\Pinguino32X.2\p32\include\pinguino\libraries/sd/sdmmc.c:42:15: error: 'SDCS' undeclared (first use in this function)
C:\Pinguino32X.2\p32\include\pinguino\libraries/sd/sdmmc.c: In function 'enableSD':
C:\Pinguino32X.2\p32\include\pinguino\libraries/sd/sdmmc.c:48:15: error: 'SDCS' undeclared (first use in this function)
In file included from C:\Pinguino32X.2\p32\include\pinguino\libraries/sd/diskio.c:16:0,
                 from C:\Pinguino32X.2\p32\include\pinguino\libraries/sd/fileio.c:27,
                 from C:\Pinguino32X.2\source\/define.h:13,
                 from C:\Pinguino32X.2\source\main32.c:29:
C:\Pinguino32X.2\p32\include\pinguino\core/rtcc.c: At top level:
C:\Pinguino32X.2\p32\include\pinguino\core/rtcc.c:482:6: warning: conflicting types for 'RTCC_AlarmDisable'
C:\Pinguino32X.2\p32\include\pinguino\core/rtcc.c:269:2: note: previous implicit declaration of 'RTCC_AlarmDisable' was here
C:\Pinguino32X.2\p32\include\pinguino\core/rtcc.c:833:6: warning: conflicting types for 'RTCC_OutputDisable'
C:\Pinguino32X.2\p32\include\pinguino\core/rtcc.c:270:2: note: previous implicit declaration of 'RTCC_OutputDisable' was here
In file included from C:\Pinguino32X.2\p32\include\pinguino\libraries/sd/fileio.c:27:0,
                 from C:\Pinguino32X.2\source\/define.h:13,
                 from C:\Pinguino32X.2\source\main32.c:29:
C:\Pinguino32X.2\p32\include\pinguino\libraries/sd/diskio.c: In function 'disk_initialize':
C:\Pinguino32X.2\p32\include\pinguino\libraries/sd/diskio.c:249:2: error: 'SDCS' undeclared (first use in this function)
In file included from C:\Pinguino32X.2\source\main32.c:32:0:
C:\Pinguino32X.2\p32\include\pinguino\core/newlib.c: At top level:
C:\Pinguino32X.2\p32\include\pinguino\core/newlib.c:91:28: warning: 'struct stat' declared inside parameter list
C:\Pinguino32X.2\p32\include\pinguino\core/newlib.c:91:28: warning: its scope is only this definition or declaration, which is probably not what you want
In file included from C:\Pinguino32X.2\source\main32.c:36:0:
C:\Pinguino32X.2\source\/user.c: In function 'loop':
C:\Pinguino32X.2\source\/user.c:147:2: warning: incompatible implicit declaration of built-in function 'sprintf'
make: *** [link] Error 1

Declaration of SDCS is in fileio.h which must not be included I guess.

Any ideas why it looks like I would have to modify SD directory files to make it work?

Thanks,
Dale
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply
02-05-2012, 04:08 PM,
#7
RE: PIC32 PINGUIONO's and SD
Hi Dale,

firstly have you followed the suggestions in "READ THIS BEFORE POSTING" at the top of this discussion Pinguino Forum/Software/Syntax & Programs/PIC32 PINGUIONO's and SD.

If you had you will have seen that this subject has been discussed recently in the various threads in Pinguino Forum/Using Pinguino/Storage, in particular this thread Problems with PIC32-PINGUINO OTG SD card.

In particular have a look at this post http://forum.pinguino.cc/showthread.php?...83#pid4883.

Try doing the changes to the fileio.c and fileio.h files and see what that does for you. It should get rid of all the 'SDCS' undeclared errors you are seeing. If you have copied code from the DataLogger.pde example you may also want to do the changes identified for that file.

To deal with the RTCC.c warnings, try getting the LATEST RTTC.c and and RTCC.pdl32 from the X.3 branch and replacing the corresponding files in the appropriate directories. They were last updated a couple of days ago and the latest version includes not only function prototypes which should get rid of the conflicting types warnings (which have been there for a while) as well as dealing with another issue where previously it would only compile if certain other functions were used.

Strictly speaking the SD files are part of the X.3 branch, i.e. the development branch, rather than the main trunk (X.2) although some of the files were accidentally included in the main trunk at one point and not updated when the files in the X.3 branch have been updated. The development branch is not guaranteed to work and so you can anticipate a needing to put in a certain amount of "extra effort" in order to be able to use the additional functionality there.
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
02-05-2012, 07:53 PM,
#8
RE: PIC32 PINGUIONO's and SD
Hi mf,

Yes and sorry, I had skimmed that thread before but now I have done your further suggestions from that post.

I can now compile datalogger.pde for both MICRO and OTG with no errors.

I unzipped the CDC RS-232 Emulation Demo drivers from Jean-Pierre post http://forum.pinguino.cc/showthread.php?...11#pid3311

But this CDC driver won't install.

I installed everything as per this page http://wiki.pinguino.cc/index.php/Windows.

Now I remember doing all that a month ago and same results but I went on to other things. Somehow back then I put Python 2.7 on too.

Still can't get CDC driver to install.

datalogger.pde won't run without CDC installed and it looks like all error messages in other SD includes use CDC too.

Any ideas why I can't get driver to install, tried with both MICRO and OTG?

Dale
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply
02-05-2012, 09:33 PM,
#9
RE: PIC32 PINGUIONO's and SD
Hi Dale,

the CDC.print functions still work even when the board is not connected to a computer - in the data logger they are only there so that you can see what is happening.

The thing that will stop the example running are the two CDC.getKey lines. You could replace these with a delay, say 10 seconds, then let the program run for a while and then switch off the board a second or two after data is written. If you use the PIC32 Pinguino OTG board, the green LED flashes every time the SD card is accessed so you can use that a a sign when to switch off the card a second later. It is not documented in the DataLogger.pde example as it is a side effect of the Green LED being connected to the same IC pin as is used for the SPI clock. You can then look at the card on your PC to confirm that data is being written - not elegant but it would give you a way of checking that the program is functioning.

Alternatively if you have access to a serial connection you could probably replace the CDC. functions with serial. functions - although you might need to include some extra code to initialise the serial connection.

Sorry I can't give you any guidance on getting CDC to talk to a Windows XP PC. I normally use a Ubuntu computer and although it does have some issues it was relatively straight forward to get running. I have installed Pinguino X.2 on a Windows Vista netbook. I think I installed an earlier version and then removed that and then installed r305. One thing I did notice was that the first time I connected a board with a program with a CDC function running on it, it took a while to recognise it and install the appropriate drivers. NOTE that the computer ONLY sees the board as a CDC device if a program using CDC functions is actually running on the board.

I seem to recall that the file mchpcdc.zip in the /extra folder is related to the drivers needed to use CDC (it is probably the same file that is in the J-P post you refer to). Once you have the board connected and running a program using CDC functions you might try installing the drivers from this file.

Regards
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
03-05-2012, 02:30 AM,
#10
RE: PIC32 PINGUIONO's and SD
Hi mf,

I spent the day trying to get any of this working. I have had a little more success with the OTG than the MICRO.

I replaced the two getkeys in datalogger.pde each with delay(500).

I compiled for OTG and uploaded. At the end of the upload, the computer beeps once, pauses and then beeps 3 more times in succession quickly. After that, the OTG's green led flashes twice and stops. A file is created with one record in it. The sequence is repeated when I push reset, each time adding a record. When I power the board externally I only get the 2 green flashes and one record added to the file.

When I compile for the MICRO and upload, I get the same USB beeping, no LED activity on the MICRO (none expected) and NO file creation and obviously no record added.

CDC will not install with the program loaded and the Pinguinos attached to USB.

That was all easy but I decided to waste a bunch of time trying to pare the code down to just writing to the file. With slight variations of this code I have had some luck writing multiple records with both the MICRO and OTG but for some reason I can't even do that consistently:

Code:
#define B_SIZE 32        // Size of read buffer - arbitrary length,
                        // try changing it to improve efficiency
    UINT         i, b, l, btw, bw, br;
    char        filename[]    = "datalog1.csv";    
    FIL         fil;                            // File object
    FRESULT    res,    rc;
    DWORD        file_size;
    char        read_buff[B_SIZE];

void setup() {
    pinMode(10, OUTPUT);            // MICRO yellow LED    
    digitalWrite(10, HIGH);            // MICRO yellow LED On    
}

void loop()  {
    char    buffer[40]    = "1234,";        // arbitary value of 40 for length of character array
    btw = strlen(buffer);                //    number of Bytes To be Written
    SD.mount(8);                         //    Allocate file structure
    /*    Open existing file or new file if file does not already exist */
    res = SD.open(&fil, filename, FA_OPEN_ALWAYS | FA_READ | FA_WRITE);
    if (!res){
        file_size = fil.fsize;                        // Get existing file size
        SD.seek(&fil,file_size);                    // Set R/W pointer to end of file
        /*    Write data to file */
        rc = SD.write(&fil, buffer, btw, &bw);        // write new data to file
        SD.flush(&fil);                                // flush any data in cache to file
                                                    // to avoid data loss from loss of power etc
        SD.close(&fil);        //    Included for safety to ensure file properly closed
        SD.unmount();            //    in case user removes card instead of proceeding.
    }
    delay(1000);
}

On the MICRO the LED will not even light up even though I do this the first thing in setup function.

I am so frustrated and I feel totally bound, gagged and hooded trying to debug this without any debug tools.

I can't even figure out how to determine the value of 'res' as I am sure this is the culprit (file not opening). I can not seem to add my LCD display code either since the above code doesn't seem to even initiate to begin with.

Any more suggestions on getting the SD working on my MICRO or is there an error in the above code?

I need CDC but how?

Thanks,
Dale
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)