I am an ECET student programming a PIC from MPLAB X using the SDCC plugin. My system is a Debian Stretch. I recently manually installed SDCC and GPUTILS. In my application, I have a PIC18F2520 with an LED on PORTC bit 1 and a button on PORTA bit 3.
LED changes state every ~0.5s. Pressing the button will toggle the state of the LED.
sdcc -v
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.7.0 #10228 (Linux)
I am not 100% sure how the SDCC plugin works together with MPLAB X to compile my project, but I have attached the entire project here in case it is useful. Here is the text output of the build window:
CLEAN SUCCESSFUL (total time: 60ms)
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory '/media/data/peterl/Source/MPLabX/Timer.X'
make -f nbproject/Makefile-default.mk dist/default/production/Timer.X.production.hex
make[2]: Entering directory '/media/data/peterl/Source/MPLabX/Timer.X'
mkdir -p "build/default/production"
mkdir -p "build/default/production"
mkdir -p "build/default/production"
mkdir -p "build/default/production"
rm -f build/default/production/Led.o
"/usr/local/bin/sdcc" --use-non-free --opt-code-size -c -mpic16 -p18f2520 Led.c -obuild/default/production/Led.o
rm -f build/default/production/main.o
rm -f build/default/production/Timer.o
"/usr/local/bin/sdcc" --use-non-free --opt-code-size -c -mpic16 -p18f2520 main.c -obuild/default/production/main.o
rm -f build/default/production/Button.o
"/usr/local/bin/sdcc" --use-non-free --opt-code-size -c -mpic16 -p18f2520 Timer.c -obuild/default/production/Timer.o
"/usr/local/bin/sdcc" --use-non-free --opt-code-size -c -mpic16 -p18f2520 Button.c -obuild/default/production/Button.o
mkdir -p dist/default/production
"/usr/local/bin/sdcc" -Wl-c -Wl-m --use-non-free --opt-code-size -mpic16 -p18f2520 build/default/production/Timer.o build/default/production/main.o build/default/production/Led.o build/default/production/Button.o -odist/default/production/Timer.X.production.hex
message: Using default linker script "/usr/local/share/gputils/lkr/18f2520_g.lkr".
warning: Relocation symbol "_cinit" [0x00001C] has no section. (pass 0)
warning: Relocation symbol "_cinit" [0x000020] has no section. (pass 0)
warning: Relocation symbol "_cinit" [0x000024] has no section. (pass 0)
warning: Relocation symbol "_cinit" [0x00001C] has no section. (pass 0)
warning: Relocation symbol "_cinit" [0x000020] has no section. (pass 0)
warning: Relocation symbol "_cinit" [0x000024] has no section. (pass 0)
make[2]: Leaving directory '/media/data/peterl/Source/MPLabX/Timer.X'
make[1]: Leaving directory '/media/data/peterl/Source/MPLabX/Timer.X'
BUILD SUCCESSFUL (total time: 569ms)
As I have no idea as to the cause of this behavior, I have not really come up with a simpler case than the code provided. However, I will try to the best of my knowledge to help out in whatever way I can. This is my first (ever!) bug report, please go easy on me! ;)
Clarification. (3) is in addition to (2).
Have you looked at the LED with an oscilloscope? I bet it's blinking too fast for your eyes to see.
I can't believe that didn't occur to me. You're absolutely right. Now to find out why...
Last edit: Peter Lapets 2018-02-19
The oscilloscope shows a 44.36 uS duration between LED toggles. On a system oscillator of 32 MHz, /4 for 8 MHz, this yields ~355 cycles. These pulses are periodically longer due to an interrupt call. This is not such a long time, and my guess would be that a flag in my code is stuck TRUE for some reason and the main loop code keeps running without interruption. What gives me pause is that the same code runs on XC8 without issue. If there's a compiler quirk I'm overlooking, I'd greatly appreciate a few pointers.
I've found the source of the problem. In my code, I have a typedef struct:
In another part of the code, I have the following function:
This always returns true. However, if I change it to:
then everything works as expected.
...that shouldn't do that, should it?
Last edit: Peter Lapets 2018-02-21
Can you show the generated assembly for these two cases?
I apologize for the delay -- for some reason my email put everything into spam folder.
n.b. this assembly is from invocation with no optimization.
Working case:
Non-working case:
Last edit: Peter Lapets 2018-03-01
Diff:
Changed subject on OP's request