Correct compiling of c sources
Next issue I ran into :-)
I have SimpleIDE and Code::Blocks installed. My plan was to use Code::Block for development because I need the code completion feature. I just can't have all my methods in my mind ;-)
It looks like SimpleIDE compiles code differently than code blocks. I have a test program which works compiled with SimpleIDE but not with Code::Blocks.
The code:
When I compile with SimpleIDE, I see the following command lines:
propeller-elf-gcc.exe -v GCC 4.6.1 (propellergcc-alpha_v1_9_0_2365)
propeller-elf-c++ -I . -L . -o cmm/SD with Tests.elf -Os -mcmm -m32bit-doubles -fno-exceptions -fno-rtti -std=c99 SD with Tests.c -lm
cc1plus.exe: warning: command line option '-std=c99' is valid for C/ObjC but not for C++ [enabled by default]
propeller-load -s cmm/SD with Tests.elf
Patching __cfg_sdspi_config1 with 00000000
Patching __cfg_sdspi_config2 with 00000000
propeller-elf-objdump -h cmm/SD with Tests.elf
Done. Build Succeeded!
When I compile with Code::Blocks, I see the following command lines:
propeller-elf-c++.exe -Os -Wall -mcmm -m32bit-doubles -fno-exceptions -fno-rtti -IC:\PropGCC\lib\Util -IC:\PropGCC\lib\Communication -c "C:\Users\Christian\Documents\CodeBlocks\SD Test\SDTest.cpp" -o obj\Release\SDTest.o
propeller-elf-c++.exe -LC:\PropGCC\lib\Util -LC:\PropGCC\lib\Communication -o bin\Release\out.elf obj\Release\SDTest.o -Os -Wall -mcmm -m32bit-doubles -fno-exceptions -fno-rtti -s
Output size is 22.73 KB
Process terminated with status 0 (0 minutes, 0 seconds)0 errors, 0 warnings
When I load the out.elf file created by the SimpleIDE compiler invoke, the program works and I also get these lines before the program gets loaded:
Patching __cfg_sdspi_config1 with 00000000
Patching __cfg_sdspi_config2 with 00000000
When I load the out.elf file created by the Code::Blocks compiler invoke, the program does not work (SD access does not work, the printf before the first fopen are written and then the program hangs).
I also does not see the Patching ... lines when loading the program with propeller-load.
My question is, why this happens. Does the linker step from Code::Blocks does damage the elf file so that the loader does not patch the sd config in the elf file?
What do I have to change that this also works with another IDE than SimpleIDE?
Christian
I have SimpleIDE and Code::Blocks installed. My plan was to use Code::Block for development because I need the code completion feature. I just can't have all my methods in my mind ;-)
It looks like SimpleIDE compiles code differently than code blocks. I have a test program which works compiled with SimpleIDE but not with Code::Blocks.
The code:
/*
SD with Tests.side
SD Minimal modified so that it tests for drive and file before performing
any read/write operations.
http://learn.parallax.com/propeller-c-simple-devices/sd-card-data
*/
#include <stdio.h> // Include simpletools header
#include <stdint.h>
#include <propeller.h>
extern _Driver _SimpleSerialDriver;
extern _Driver _FileDriver;
_Driver *_driverlist[] = {
&_SimpleSerialDriver,
&_FileDriver,
NULL
};
int a;
int DO = 10, CLK = 9, DI = 8, CS = 7; // SD card pins on Activity Board
uint8_t videoBuffer[1024] = {65};
int main (void) { // main function
waitcnt (40000000 + CNT);
//putStr("Starting...");
printf ("Starting...\n");
printf("Opening file...\n");
//int erc = sd_mount(DO, CLK, DI, CS); // Mount SD card
int erc = 0;
if (!erc) { // Error code = 0, good, continue
FILE *fp = fopen ("test.txt", "w"); // Open a file for writing
printf("File opened...\n");
if (fp) { // Nonzero file pointer?
for (a = 0; a < 10; a++) { // Good, continue
int bytesWritten = fwrite (videoBuffer, 1, 1024, fp); // Add contents to the file
//putStr("Bytes written: ");
//putDec(bytesWritten);
//putStr("\n");
printf ("Bytes written: %d\n", bytesWritten);
}
} else { // Zero file pinter?
// Bad, error message.
// putStr("File did not open.\n");
printf ("File did not open.\n");
}
fclose (fp); // Close the file
// fp = fopen("test.txt", "r"); // Reopen file for reading.
uint8_t videoBuffer2[1024]; // Buffer for characters.
if (fp) { // Nonzero file pinter?
// Good, continue.
for (a = 0; a < 10; a++) {
fp = fopen ("test.txt", "r");
int startCnt = CNT;
int bytesRead = fread (videoBuffer2, 1, 1024, fp); // Read 21 characters
int endCnt = CNT;
fclose (fp);
//putStr("Bytes read: ");
//putDec(bytesRead);
//putStr("\n");
//putStr("Read took ticks: ");
//putDec((endCnt - startCnt));
//putStr("\n");
printf ("Bytes: %d\n", bytesRead);
printf ("Read took ticks: %d\n", (endCnt - startCnt));
}
// With a newline at the end.
} else { // Zero file pointer?
// Bad, print error.
//putStr("File did not open.\n");
//putStr("\n");
printf ("File did not open.\n");
}
} else { // Mount error code not zero?
// Bad, display code
//putStr("Error opening card.");
printf ("Error opening card.");
}
}
When I compile with SimpleIDE, I see the following command lines:
propeller-elf-gcc.exe -v GCC 4.6.1 (propellergcc-alpha_v1_9_0_2365)
propeller-elf-c++ -I . -L . -o cmm/SD with Tests.elf -Os -mcmm -m32bit-doubles -fno-exceptions -fno-rtti -std=c99 SD with Tests.c -lm
cc1plus.exe: warning: command line option '-std=c99' is valid for C/ObjC but not for C++ [enabled by default]
propeller-load -s cmm/SD with Tests.elf
Patching __cfg_sdspi_config1 with 00000000
Patching __cfg_sdspi_config2 with 00000000
propeller-elf-objdump -h cmm/SD with Tests.elf
Done. Build Succeeded!
When I compile with Code::Blocks, I see the following command lines:
propeller-elf-c++.exe -Os -Wall -mcmm -m32bit-doubles -fno-exceptions -fno-rtti -IC:\PropGCC\lib\Util -IC:\PropGCC\lib\Communication -c "C:\Users\Christian\Documents\CodeBlocks\SD Test\SDTest.cpp" -o obj\Release\SDTest.o
propeller-elf-c++.exe -LC:\PropGCC\lib\Util -LC:\PropGCC\lib\Communication -o bin\Release\out.elf obj\Release\SDTest.o -Os -Wall -mcmm -m32bit-doubles -fno-exceptions -fno-rtti -s
Output size is 22.73 KB
Process terminated with status 0 (0 minutes, 0 seconds)0 errors, 0 warnings
When I load the out.elf file created by the SimpleIDE compiler invoke, the program works and I also get these lines before the program gets loaded:
Patching __cfg_sdspi_config1 with 00000000
Patching __cfg_sdspi_config2 with 00000000
When I load the out.elf file created by the Code::Blocks compiler invoke, the program does not work (SD access does not work, the printf before the first fopen are written and then the program hangs).
I also does not see the Patching ... lines when loading the program with propeller-load.
My question is, why this happens. Does the linker step from Code::Blocks does damage the elf file so that the loader does not patch the sd config in the elf file?
What do I have to change that this also works with another IDE than SimpleIDE?
Christian

Comments
When I remove the -s option, it works :-)