chipKIT® Development Platform

Inspired by Arduino™

Small data error when create large arrays on ChipKIT MAX32

Created Tue, 14 Jun 2016 01:12:11 +0000 by reverie001


reverie001

Tue, 14 Jun 2016 01:12:11 +0000

Hi,

I was trying to create three large arrays on chipKIT Max32 with Arduino C. They looks like below:

int A[128][64]; float B[128][64]; float C[128][64];

However, error message as " small-data section exceeds 64KB; lower small-data size limit (see option -G)" jumped out and I have to change the array size back to [64][64] as below to make the code work, as below:

int A[64][64]; float B[64][64]; float C[64][64];

I did try the compiler optimizations shown in this thread: [url]http://chipkit.net/mpide-compiler-pic32/[/url] But it did not work.

Really appreciate if anyone can give some suggestions on how to optimize the compiler to overcome this issue. I'm using mpide-0150-windows-20150820.

I also see the proposed solution in the other thread as below. I will give it a try later and see how thing goes. Thanks.

Re: Linking errors when compiling and linking for Max32 Postby EmbeddedMan » Wed Apr 20, 2016 4:55 pm

That is a pretty old version. I'd give Arduino IDE 1.6.7 a try, with chipKIT-core v1.1.0 installed within it. You can find direction here : http://chipkit.net/wiki/index.php?title=ChipKIT_core

Maybe that will help resolve your linker issue - maybe not. But it's worth a shot.

*Brian


majenko

Tue, 14 Jun 2016 10:54:23 +0000

This is actually a bug with the compiler (well, not the compiler itself, but the libraries in the compiler). It has already been identified and tackled and the next compiler release will fix it.

For now you can disable the "smalldata" section by editing the compilation commands (in platform.txt or platforms.txt depending on if you're using mpide or chipkit-core - I forget which is which, or compiler.txt if you're using UECIDE) and adding the flag (IIRC - it's been a while since I did this myself) "-mno-gopt" to both compiler and linker commands.

Another option is to find the file "ctype.h" which is in .../pic32mx/include/ctype.h in the compiler, wherever that is, and add to the start of it:

#ifndef __IMPORT
#undef __IMPORT
#endif
#define __IMPORT __attribute__((section(".data")))

which may cure the problem for you as well without having to find the right compiler commands to modify.


EmbeddedMan

Tue, 14 Jun 2016 13:08:30 +0000

Man, Majenko, how do you ever remember all of this stuff. Thanks so much for helping everybody out with all of the interesting questions - like this one - I'm always impressed at how much technical information you seem to have instantly available at your fingertips to help people out.

Reverie001 - As soon as the new compiler is ready for release, we will do a new release of chipKIT-core. We just did a 1.2.0 release of the core, which did NOT include the new compiler with the fix Makenjo is talking about, because it isn't quite ready yet. But as soon as it is, we'll do a release and post about it.

*Brian


majenko

Tue, 14 Jun 2016 13:09:32 +0000

Brian, it's called "The GMail Search Box" ;) That and never deleting old emails ;)


reverie001

Tue, 14 Jun 2016 23:46:36 +0000

Hi Majenko, Thank you so much for you prompt reply, I really appreciate it. I think I understand what is happening now but I have some difficulty in fixing it. It will be great if I can have some hand by hand help from you. Following your instructions, what I have done is as below:

  1. I first tried the second option you give to modify "ctype.h". I found the file you mentioned at that location and added the code to the start of it. However, the same error persists.

  2. While keeping the modifications in ctype.h, I went to file "platforms.txt", I tried to understand where I should change by adding "-mno-gopt" after three commends: pic32.compiler.ldflags=-mno-gopt; pic32.compiler.upload.cmd=-mno-gopt; pic32.compiler.upload.flags=-mno-gopt. But it still did not work.

The version of my mpide is mipde-0150-windows-20150820. Now the file "platforms.txt" looks like this:

##############################################################
pic32.recipe.c.o.pattern={0}{1}::{2}::{3}{4}::-DF_CPU={5}::-D{6}::-D{7}::{8}::{9}::{10}::-o::{11}
pic32.recipe.cpp.o.pattern={0}{1}::{2}::{3}{4}::-DF_CPU={5}::-D{6}::-D{7}::{8}::{9}::{10}::-o::{11}
pic32.recipe.ar.pattern={0}{1}::{2}::{3}{4}::{5}
pic32.recipe.c.combine.pattern={0}{1}::{2}::{3}{4}::-o::{5}{6}.elf::{7}::{8}::-L{9}::-lm::-T::{10}/{11}::-T{12}/{13}
pic32.recipe.objcopy.eep.pattern={0}{1}::{2}::{3}.elf::{4}.eep
pic32.recipe.objcopy.hex.pattern={0}{1}::{2}::{3}.elf


########################################################
pic32.name=chipKit
#pic32.compiler.path=/opt/local/pic32/install-image/bin/
#pic32.compiler.path=/opt/pic32-tools/bin/
#pic32.compiler.path=C:\pic32-tools\bin\
#pic32.compiler.path=/opt/mac-pic32/bin/
pic32.compiler.c.cmd=pic32-gcc
pic32.compiler.path={0}/hardware/pic32/compiler/pic32-tools/bin/
pic32.compiler.c.flags=-O2::-c::-mno-smart-io::-w::-ffunction-sections::-fdata-sections::-g3::-mdebugger::-Wcast-align::-fno-short-double::-fframe-base-loclist
pic32.compiler.cpp.cmd=pic32-g++
pic32.compiler.cpp.flags=-O2::-c::-mno-smart-io::-w::-fno-exceptions::-ffunction-sections::-fdata-sections::-g3::-mdebugger::-Wcast-align::-fno-short-double::-fframe-base-loclist
pic32.compiler.S.flags=-O2::-g1::-c::-Wa,--gdwarf-2
pic32.compiler.ar.cmd=pic32-ar
pic32.compiler.ar.flags=rcs
pic32.compiler.objcopy.cmd=pic32-objcopy
pic32.compiler.objcopy.eep.flags=-O::ihex::-j::.eeprom::--set-section-flags=.eeprom=alloc,load::--no-change-warnings::--change-section-lma::.eeprom=0
pic32.compiler.elf2hex.flags=-a
pic32.compiler.elf2hex.cmd=pic32-bin2hex
#pic32.compiler.elf2hex.flags=-O::ihex::-R::.eeprom
#pic32.compiler.elf2hex.cmd=pic32-objcopy
pic32.compiler.c.elf.flags=-Os::-Wl,--gc-sections::-mdebugger::-mno-peripheral-libs::-nostartfiles
pic32.compiler.c.elf.cmd=pic32-g++
pic32.compiler.cpudef=-mprocessor=
#pic32.compiler.ldflags=
pic32.compiler.ldflags=-mno-gopt
pic32.compiler.ldscript=chipKIT-BL.ld
#pic32.compiler.includepath=/opt/local/pic32/install-image/pic32mx/include
pic32.compiler.upload.cmd=-mno-gopt
pic32.compiler.includepath={0}/hardware/pic32/compiler/pic32-tools/pic32mx/include
#pic32.compiler.upload.flags=
pic32.compiler.upload.flags=-mno-gopt
#pic32.library.path=./hardware/pic32/cores/pic32
pic32.library.core.path=./hardware/pic32/cores/pic32
pic32.library.path=./hardware/pic32/libraries
pic32.ldscript=chipKIT-BL-mega.ld
pic32.ldcommon=chipKIT-application-COMMON.ld
pic32.compiler.define=::-DMPIDEVER=16778004::-DMPIDE=150::
pic32.build.variant=Default_100
pic32.core.header=WProgram.h

Before I go to dig deeper into the references, it will be great if you can help point out where exactly I should modify? Thank you very much!

EmbeddedMan - Thanks for letting me know that, will upgrade at the first place if it can fix the bug. Thanks.


majenko

Wed, 15 Jun 2016 10:45:21 +0000

You need to append it to:

pic32.compiler.c.flags pic32.compiler.cpp.flags pic32.compiler.ldflags


reverie001

Wed, 15 Jun 2016 23:23:17 +0000

Dear Majenko:

I tried different ways to append "-mno-gopt" to the three commends you mentioned. For example, I tried as below:

pic32.compiler.c.flags=-mno-gopt pic32.compiler.cpp.flags=-mno-gopt pic32.compiler.ldflags=-mno-gopt

I also tried keeping the old commands and only added "-mno-gopt" to the end of the commands.

However, none of them works. The error message as "cc1plus.exe: error: unrecognized command line option "-mno-gopt" " appeared.

I would be really appreciate if you can help with this on how the code should be appended here.

Thanks a lot.


majenko

Wed, 15 Jun 2016 23:30:42 +0000

I just placed that chunk of C macros into my ctype.h file and it worked. Code that I know gives the error that you describe compiles with it in there.

I have attached my ctype.h file for you in case you didn't put the code in right.

The ctype.h file is the best way of fixing the problem.


reverie001

Thu, 16 Jun 2016 00:01:23 +0000

Thanks Majenko for your patiently help!

I first went get a clean version of the mpide-0150, then I used your ctype file to replace the old one. However, small data error is still there...

Then I went to change the command in "platforms.txt" by changing commands to:

pic32.compiler.c.flags=-mno-gopt pic32.compiler.cpp.flags=-mno-gopt pic32.compiler.ldflags=-mno-gopt

The error message as "cc1plus.exe: error: unrecognized command line option "-mno-gopt" " appeared again.

It's strange that it works for you but not for me...Is it just because this mpide-0150 has some other bugs?

May I know your choice of the compiler so maybe I can switch to your setup to update my CHIPKIT MAX32?

Many thanks!


majenko

Thu, 16 Jun 2016 08:15:23 +0000

I always use UECIDE of course :)

Of course, we could be seeing completely different things. Your problem may be caused by something else that my problem, which is why my fix isn't working for you.

Any chance you could post your entire code so I can try it out?


reverie001

Thu, 16 Jun 2016 18:50:18 +0000

Hi Majenko, thanks a lot.

I tried UECIDE (uecide-0.8.8alpha22-windows-full), the plugin manager does not work for me, I could not see anything to install or download. I guess it's because of the firewall system in the company.

Second, sorry that I could not directly share the code here, it's company's property. I did more tests by adding code block by block and wanted to see which cause the problem. Indeed, if I only claim a 128x64 array at the beginning with nothing else, your solution works and code complies with no error! This continued until I added in the 11th block of my code, which adds up to a few thousand lines of code in total, then the small-data error message appears:

C:/Users/humia/Downloads/mpide-0150/hardware/pic32/compiler/pic32-tools/bin/../lib/gcc/pic32mx/4.5.2/../../../../pic32mx/bin/ld.exe: small-data section exceeds 64KB; lower small-data size limit (see option -G)
sketch_jun16a.cpp.o: In function `pulse_the_latch()':
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:495:(.text._Z15pulse_the_latchv+0x8): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
sketch_jun16a.cpp.o: In function `column_safe_start()':
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:512:(.text._Z17column_safe_startv+0x20): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
sketch_jun16a.cpp.o: In function `row_safe_start()':
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:592:(.text._Z14row_safe_startv+0x24): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
sketch_jun16a.cpp.o: In function `setup_col_pulse_width(int, int, int)':
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:744:(.text._Z21setup_col_pulse_widthiii+0x40): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:812:(.text._Z21setup_col_pulse_widthiii+0x170): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
sketch_jun16a.cpp.o: In function `setup_col_sample_and_hold(int, int, int)':
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:821:(.text._Z25setup_col_sample_and_holdiii+0x40): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:875:(.text._Z25setup_col_sample_and_holdiii+0x170): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
sketch_jun16a.cpp.o: In function `setup_col_adc_convst(int, int, int)':
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:883:(.text._Z20setup_col_adc_convstiii+0x44): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:936:(.text._Z20setup_col_adc_convstiii+0x168): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
sketch_jun16a.cpp.o: In function `setup_col_dac_span(int, int)':
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:946:(.text._Z18setup_col_dac_spanii+0x40): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:999:(.text._Z18setup_col_dac_spanii+0x1e0): additional relocation overflows omitted from the output
collect2: ld returned 1 exit status

So I think you are right, it is due to something else. But does it simply means that my hardware could not handle the larger code if I want to put in more functions? Or is there anyway to overcome this issue? Actually in another thread: [url]http://chipkit.net/forum/viewtopic.php?t=974[/url], I see they are solving a very similar problem that I encountered here. However, the final solution is quite vague to understand how it was solved.

In the worst case, I will have to delete the additional functions to implement on the MCU, or I have to find better ways to code my things? Like using fewer variables? I really don't know.

Thanks!


majenko

Thu, 16 Jun 2016 23:04:44 +0000

You should see the same in alpha22 that you see in alpha21. They both use the same repsitory.

We have just (literally a few minutes ago) been handed a new version (prerelease beta) of the compiler with a number of bug fixes. I am at this moment in time building the UECIDE packages for it - it might cure your problem (or it might not). It should appear in the plugin manager in due course.


reverie001

Mon, 20 Jun 2016 21:49:33 +0000

Thanks Majenko, I think I will build two versions of firmware to overcome the problem at this moment. One with more functions but support small arrays, one with fewer functions but support larger arrays.

And I will update the compiler as well later to see if that helps, thanks a lot for your help all this way!