Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CDC freeze when using an initialized variable
12-03-2014, 05:43 PM, (This post was last modified: 12-03-2014, 05:52 PM by ajomay.)
#1
CDC freeze when using an initialized variable
Hello to all,

i got a problem with a freezing Pinguino Micro REV-B Board.

i am using Pinguino IDE X4 installed to
C:\x4-easy-rev959 on a WIN7 64-Bit PC.

Generally the X4 system is working. I can write, compile and download files to my Pinguino-micro board. I wrote some small programs to test the CDC interface in connection with a teraterm-pro terminal program on the PC. The programs worked fine. I was able to send and receive characters with my pinguino board.


NOW THE PROBLEM STARTS:

See examples in attached files.

I tested it with 2 boards with same results - a hardware problem is not very likely.

0. Write a small "Hello world" demo for CDC. Dont forget to add a
led flash in setup() function.

1. Create a initialized variable with a init value !=0.

2. Create a function and do a write access to this variable ( from 1.)

3. Add a call of the function to the loop() function.

4. Compile and download.

Error result:

The program does not start propperly. There are NO FLASHES of led.
This means that setup() is not reached.

This happens before the function (see 2.) is called! Being there and linked
is enough!

The program hangs in the call of CDC_Init() in main32.c

One can verify this by turnig of CDC_Init() temporarily with a comment in main32.c .
The led flashes are there after compile and download.

I wrote a small demo program that demostrates the problem.

CdcVarBug_mail_funct.pde does not work
CdcVarBug_workingOk_1.pde and CdcVarBug_workingOk_2.pde do work.

See attachments.

Can anybody help?

Best Regrads,

Andreas

---- snip ----
int Counter;

u8 Testvar= 42; // <<< This finally causes the error when used in a called funktion

int Test(void)
{
Testvar= 43; // <<< We need a write access to generate the error
}


void setup() // <<< This function is not reached when the problem occurs.
// The program hangs in function call 'CDC_init();' in
// file C:\x4-easy-rev959\source\main32.c
// (I proved this with test outputs to the green led)
{
int k;

pinMode(USERLED, OUTPUT);


for(k=0; k<10; k++)
{
digitalWrite(USERLED, HIGH);
delay(50); // wait for 50ms
digitalWrite(USERLED, LOW);
delay(50); // wait for 50ms
}

Counter= 0;
}

void loop()
{

Test(); // <<< When this function is written down here, the error occurs BEFORE THE FUNCTION IS CALLED!

if (!CDCUSBIsConnected())
{
return;
}

CDC.printf("CDC: Counter= %d\r\n", Counter);

delay(100);

Counter++;
}
---- snap ----


Attached Files
.pde   CdcVarBug_mail_funct.pde (Size: 556 bytes / Downloads: 2)
.pde   CdcVarBug_workingOk_1.pde (Size: 555 bytes / Downloads: 2)
.pde   CdcVarBug_workingOk_2.pde (Size: 558 bytes / Downloads: 4)
Reply
12-03-2014, 07:31 PM,
#2
RE: CDC freeze when using an initialized variable
Dear Andreas,

Firstly, I wish to mention that the title/subject is kind of misleading. The problem you mention has got nothing to do with CDC. You just notice while using CDC.

When you use recent version of Pinguino IDE, the make script is set to generate 16bit code and optimize for size reduction. It is good for a small flash PIC but has not so much meaning for PIC32 family.

I am not gcc expert, but the code with -Os flag will allocate 1 byte for u8 variable and a non-zero initialized static variable tends to give you such error. Somehow I couldn't really established the exact nature since 1 initialized static variable was ok while 2 of them gave me error in my case. It is quite likely to bite people using the SD and CD library for the same reason.

To overcome this problem, change the line 115 of Makefile.win32 to '-O3' instead of '-Os'. This will produce optimized or execution speed and allocate 4 bytes for u8 variable to align 4 bytes boundary and you won't get the same error. In fact this used to be the default flag in older version of Pinguino IDE.

If you don;t want to change these, leave the variable uninitialized and initialize it within the function code. Having a block of code to initialize all the static variables in the beginning of program is also a good habit to keep. This arrangement can be convenient when you need to load the variables from eeprom or SD.

You may also disable the generation of 16 bit code so that existing interrupt functions can work without special overriding by remark the '__MIPS16_ENABLE__ = true' statement.

Another thing to note is this. Pinguino IDE disable the 'Verify' option when it upload the hex file and you will not notice if what is written to flash is as you expect until you run it with erratic result. Depending on the location of error, some program may just appear as running normally while some cases will give you outright error.

If you upload the hex file manually with verify option, you will see the verification error during the upload of your program. It is not possible to override the Pinguino IDE option to verify during upload by changing the *.py file on Windows environment unless you run the *.py files with Python installed.

I am hoping that the IDE code is modified to check the *.py version and use it if found so that newest version downloaded from SVN or modified can be used on Windows.

Meantime, I am using the modified version of mphidflash.exe with different verify switch to keep the verify option ON. It also has 2 extra features - retry usbOpen to allow longer time to set the Pinguino to download mode and also filter type 5 statement in hex file. The latter is also handled by Pinguino IDE script but I added in mphidflash anyway.

The modified version is attached in this reply. I hope the Pinguino IDE is also changed to enable the verify option so that this kind of error can be detected during the uploading of hex file immediately.

DJ


Attached Files
.zip   mphidflash.zip (Size: 12.13 KB / Downloads: 2)
Reply
12-03-2014, 09:51 PM, (This post was last modified: 12-03-2014, 10:01 PM by regis.)
#3
RE: CDC freeze when using an initialized variable
Here is the fixed Makefile.win32 to be tested (rename it before) :

.txt   Makefile32_win32.txt (Size: 4.52 KB / Downloads: 0)

@djpark : Some time ago, I wrote a python uploader intended to replace ubw32 (linux), mphidflash (mac os) and mphiflash.exe (windows) : easy understandable code, easy to maintain, multi-platform, it also checks if the hex is fine before it starts to write it. For me the perfect solution BUT there's still a bug somewhere Undecided I've never had time to find.
Do you want to test it ? (be sure to have a PicKit3 if you brick the bootloader)
- code is in wxgui/uploader/uploaderMCC.py (will be renamed in uploader32 once it works)
- edit the wxgui/pinguino.py, in OnUpload function simply uncomment lines 298, 299 and 320.
- give me sometime to update it to the last IDE version.
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
12-03-2014, 10:06 PM,
#4
RE: CDC freeze when using an initialized variable
Ok, I took a look at it : uploaderMCC.py is a stand alone version. You don't need the IDE to make it work. Just replace the file name inside the code.
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
13-03-2014, 12:56 AM,
#5
RE: CDC freeze when using an initialized variable
Hello DJ and Regis,

thanks for your help.

I can't expect the morning when i will test it... Wink

Best regards,

Andreas
Reply
13-03-2014, 02:10 AM,
#6
RE: CDC freeze when using an initialized variable
(12-03-2014, 09:51 PM)regis Wrote: @djpark : Some time ago, I wrote a python uploader intended to replace ubw32 (linux), mphidflash (mac os) and mphiflash.exe (windows) : easy understandable code, easy to maintain, multi-platform, it also checks if the hex is fine before it starts to write it. For me the perfect solution BUT there's still a bug somewhere Undecided I've never had time to find.
Do you want to test it ? (be sure to have a PicKit3 if you brick the bootloader)
- code is in wxgui/uploader/uploaderMCC.py (will be renamed in uploader32 once it works)
- edit the wxgui/pinguino.py, in OnUpload function simply uncomment lines 298, 299 and 320.
- give me sometime to update it to the last IDE version.

Dear Regis,

I wish I could do, but I have no experience with Python. I use C, C++ and Perl. Don't have enough spirit or time to learn a new language. Perhaps after my current project, I may want to give a go to learn.
Reply
13-03-2014, 04:52 AM,
#7
RE: CDC freeze when using an initialized variable
(12-03-2014, 10:06 PM)regis Wrote: Ok, I took a look at it : uploaderMCC.py is a stand alone version. You don't need the IDE to make it work. Just replace the file name inside the code.

Regis,

I looked at the code (without full understanding in detail). I find that there is no 'verify' function in the code. So it is not possible to enable the verify option in the current version of Python program.

Having the verify option enabled (enabled by default) allows detecting of this kind of unexpected error execution and avoid scratching head to figure out what has gone wrong. While waiting for the uploader32.py to be fully ready, I suggest to remove the '-n' option in pinguino.py (around line #310) so that it doesn't disable the verify option.

DJ
Reply
13-03-2014, 11:31 AM,
#8
RE: CDC freeze when using an initialized variable
(13-03-2014, 04:52 AM)djpark Wrote: I suggest to remove the '-n' option in pinguino.py (around line #310) so that it doesn't disable the verify option.

OK.
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
13-03-2014, 01:04 PM,
#9
RE: CDC freeze when using an initialized variable
Hello DJ,

changing to option '-O3' works!
ThanX

Best regards,

Andreas

(12-03-2014, 07:31 PM)djpark Wrote: Dear Andreas,

Firstly, I wish to mention that the title/subject is kind of misleading. The problem you mention has got nothing to do with CDC. You just notice while using CDC.

When you use recent version of Pinguino IDE, the make script is set to generate 16bit code and optimize for size reduction. It is good for a small flash PIC but has not so much meaning for PIC32 family.

I am not gcc expert, but the code with -Os flag will allocate 1 byte for u8 variable and a non-zero initialized static variable tends to give you such error. Somehow I couldn't really established the exact nature since 1 initialized static variable was ok while 2 of them gave me error in my case. It is quite likely to bite people using the SD and CD library for the same reason.

To overcome this problem, change the line 115 of Makefile.win32 to '-O3' instead of '-Os'. This will produce optimized or execution speed and allocate 4 bytes for u8 variable to align 4 bytes boundary and you won't get the same error. In fact this used to be the default flag in older version of Pinguino IDE.

If you don;t want to change these, leave the variable uninitialized and initialize it within the function code. Having a block of code to initialize all the static variables in the beginning of program is also a good habit to keep. This arrangement can be convenient when you need to load the variables from eeprom or SD.

You may also disable the generation of 16 bit code so that existing interrupt functions can work without special overriding by remark the '__MIPS16_ENABLE__ = true' statement.

Another thing to note is this. Pinguino IDE disable the 'Verify' option when it upload the hex file and you will not notice if what is written to flash is as you expect until you run it with erratic result. Depending on the location of error, some program may just appear as running normally while some cases will give you outright error.

If you upload the hex file manually with verify option, you will see the verification error during the upload of your program. It is not possible to override the Pinguino IDE option to verify during upload by changing the *.py file on Windows environment unless you run the *.py files with Python installed.

I am hoping that the IDE code is modified to check the *.py version and use it if found so that newest version downloaded from SVN or modified can be used on Windows.

Meantime, I am using the modified version of mphidflash.exe with different verify switch to keep the verify option ON. It also has 2 extra features - retry usbOpen to allow longer time to set the Pinguino to download mode and also filter type 5 statement in hex file. The latter is also handled by Pinguino IDE script but I added in mphidflash anyway.

The modified version is attached in this reply. I hope the Pinguino IDE is also changed to enable the verify option so that this kind of error can be detected during the uploading of hex file immediately.

DJ
Reply
13-03-2014, 03:38 PM, (This post was last modified: 13-03-2014, 03:46 PM by ajomay.)
#10
RE: CDC freeze when using an initialized variable
Dear DJ,

unfortunally the '-O3' causes a new problem. When compiling the "P32-Interrupt-Timer1.pde" example with '-O3' there is an Linker error saying:

-----------
c:/x4-easy-rev959/win32/p32/bin/../lib/gcc/mips-elf/4.5.2/../../../../mips-elf/bin/ld.exe: function at exception vector 4 too large

c:/x4-easy-rev959/win32/p32/bin/../lib/gcc/mips-elf/4.5.2/../../../../mips-elf/bin/ld.exe: function at exception vector 4 too large

c:/x4-easy-rev959/win32/p32/bin/../lib/gcc/mips-elf/4.5.2/../../../../mips-elf/bin/ld.exe: C:\x4-easy-rev959\source\main32.o: .vector_4+0x30: Direct jumps between ISA modes are not allowed; consider recompiling with interlinking enabled.

c:/x4-easy-rev959/win32/p32/bin/../lib/gcc/mips-elf/4.5.2/../../../../mips-elf/bin/ld.exe: final link failed: Bad value
-----------

With '-Os' compiling works.

Best regards,

Andreas

(12-03-2014, 07:31 PM)djpark Wrote: Dear Andreas,

Firstly, I wish to mention that the title/subject is kind of misleading. The problem you mention has got nothing to do with CDC. You just notice while using CDC.

When you use recent version of Pinguino IDE, the make script is set to generate 16bit code and optimize for size reduction. It is good for a small flash PIC but has not so much meaning for PIC32 family.

I am not gcc expert, but the code with -Os flag will allocate 1 byte for u8 variable and a non-zero initialized static variable tends to give you such error. Somehow I couldn't really established the exact nature since 1 initialized static variable was ok while 2 of them gave me error in my case. It is quite likely to bite people using the SD and CD library for the same reason.

To overcome this problem, change the line 115 of Makefile.win32 to '-O3' instead of '-Os'. This will produce optimized or execution speed and allocate 4 bytes for u8 variable to align 4 bytes boundary and you won't get the same error. In fact this used to be the default flag in older version of Pinguino IDE.

If you don;t want to change these, leave the variable uninitialized and initialize it within the function code. Having a block of code to initialize all the static variables in the beginning of program is also a good habit to keep. This arrangement can be convenient when you need to load the variables from eeprom or SD.

You may also disable the generation of 16 bit code so that existing interrupt functions can work without special overriding by remark the '__MIPS16_ENABLE__ = true' statement.

Another thing to note is this. Pinguino IDE disable the 'Verify' option when it upload the hex file and you will not notice if what is written to flash is as you expect until you run it with erratic result. Depending on the location of error, some program may just appear as running normally while some cases will give you outright error.

If you upload the hex file manually with verify option, you will see the verification error during the upload of your program. It is not possible to override the Pinguino IDE option to verify during upload by changing the *.py file on Windows environment unless you run the *.py files with Python installed.

I am hoping that the IDE code is modified to check the *.py version and use it if found so that newest version downloaded from SVN or modified can be used on Windows.

Meantime, I am using the modified version of mphidflash.exe with different verify switch to keep the verify option ON. It also has 2 extra features - retry usbOpen to allow longer time to set the Pinguino to download mode and also filter type 5 statement in hex file. The latter is also handled by Pinguino IDE script but I added in mphidflash anyway.

The modified version is attached in this reply. I hope the Pinguino IDE is also changed to enable the verify option so that this kind of error can be detected during the uploading of hex file immediately.

DJ


Attached Files
.pde   P32-Interrupt-Timer1.pde (Size: 2.03 KB / Downloads: 0)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)