Closed jonpchin closed 6 years ago
The blink.spin file I used to test on the Propeller 40 pin DIP chip:
CON Delay = 9_000_000
MY_LED_PIN = 26 ' Use pin 26
PUB main DIRA[MY_LED_PIN] := 1 ' Set the LED pin to an output
repeat ' Repeat forever OUTA[MY_LED_PIN] := 1 ' Turn the LED on waitcnt(cnt + Delay) ' Wait 1 second ' cnt is the clock tick counter, ' clkfreq is the number of clock ticks in a second OUTA[MY_LED_PIN] := 0 ' Turn the LED off waitcnt(cnt + Delay) ' Wait 1 second
Generally speaking all of the Propeller chips support Propeller C, so I don't think your problem is in the chip. Most likely you're hitting some kind of compiler bug. I have seen issues sometimes with the compiler optimizing away references to the CNT register, which can lead to strange bugs sometimes. Have you tried compiling with optimization disabled? That might help.
Another thing you could try is using spin2cpp's asm mode to directly compile the code:
spin2cpp --asm --binary --code=hub --data=hub blink.spin
should produce a blink.binary directly, without using Propeller C at all.
I tried your suggestion spin2cpp --asm --binary --code=hub --data=hub blink.spin and the result is still the same.
How do I disable optimizations when compiling?
I reduced the delay to have a faster blinking and ran the output of spin2cpp --asm --binary --code=hub --data=hub blink.spin
in GEAR (because I had no simple Propeller board with a LED at hand) and it did blink (i.e. toggle pin 26) in the simulator.
What did you reduce the delay too? I tried the three following delays and still the same result:
Delay = 9_000_000
Delay = 3_000_000
Delay = 1_000_000
I am not using GEAR but I am using the 40 pin DIP chip P8X32A-D40 with the prop plug for uploading the code.
I am using P8X32A-Propellent-v1.6 running the command Propellent.exe blink.binary to upload the blink.binary file.
Gear is a Propeller simulation.
—▶ https://github.com/davispuh/gear-emu/releases/tag/V14.07.03
I reduced the delay to 100_000 because the simulation is slower than the original Propeller, but that should not have an impact on the correctness of your code.
I cannot test the code with Propellent because I'm using Debian (v9.4.0/AMD64).
I tried testing on Linux with Propller IDE which uses spin language and the blink works fine. But when I try the SimpleIDE using C on Linux it does not work. This was the original issue I saw in Windows as well when running SimpleIDE.
I think the C code in SimpleIDE is getting converted to .binary and that is uploaded to the chip. I guess I'll just code in spin for now.
The console log of SimpleIDE says it loaded into RAM successfully but the LED does not blink.
And the C code is?
/* Blink Light.c
Blink light circuit connected to P26. */
int main() // main function { while(1) // Endless loop { high(26); // Set P26 I/O pin high pause(1000); // Wait 1 second low(26); // Set P26 I/O pin low pause(1000); // Wait another 1 second } }
Oh sorry... I have no idea how to use and link to those "Simple Libraries". They are far too complicated for me! ;-)
I use "naked C" (no complex libraries), an editor of my liking and shell tools instead of SimpleIDE and its libraries. That way names of registers and functions are very similar to Spin and PASM.
#include "propeller.h"
int main(int argc, char* argv[])
{
int pin = 26;
int freq = CLKFREQ>>1; // half of the ticks of a full period
DIRA |= (1<<pin);
for(;;) {
OUTA |= (1<<pin);;
waitcnt(freq+getcnt());
OUTA &= ~(1<<pin);
waitcnt(freq+getcnt());
}
}
This "blinks" in the simulator.
My (self built) PropGCC is...
$ /opt/parallax/bin/propeller-elf-gcc -v
Using built-in specs.
COLLECT_GCC=/opt/parallax/bin/propeller-elf-gcc
COLLECT_LTO_WRAPPER=/opt/parallax/libexec/gcc/propeller-elf/4.6.1/lto-wrapper
Target: propeller-elf
Configured with: /opt/parallax.src/propgcc/gcc/configure --target=propeller-elf --prefix=/opt/parallax --disable-nls --disable-shared --with-pkgversion=propellergcc-alpha_v1_9_0_propellergcc-alpha_v1_9_1-5-g5fc1abdab --with-bugurl=http://code.google.com/p/propgcc/issues
Thread model: single
gcc version 4.6.1 (propellergcc-alpha_v1_9_0_propellergcc-alpha_v1_9_1-5-g5fc1abdab)
My "naked C" code working in my context cannot exclude bugs in SimpleTools or your PropGCC.
Pleaaaaase... someone with knowledge of SimpleTools jump in here...
When I try to compile with prop gcc from simpleIDE with the C code you posted above I get.
blink.cpp: In function 'int main(int, char**)': blink.cpp:12:9: error: 'getcnt' was not declared in this scope
I also tried building propgcc on Windows from source but ran into some problems building it.
The propGCC from SimpleIDE is:
D:\Programs\spin2cpp>propeller-elf-gcc -v Using built-in specs. COLLECT_GCC=propeller-elf-gcc COLLECT_LTO_WRAPPER=c:/program files (x86)/simpleide/propeller-gcc/bin/../libexec/gcc/propeller-elf/4.6.1/lto-wrapper.exe Target: propeller-elf Configured with: ../../propgcc/gcc/configure --target=propeller-elf --prefix=/opt/parallax --disable-nls --disable-libssp --disable-lto --disable-shared --with-pkgversion=propellergcc_v1_0_0_2408 --with-bugurl=http://code.google.com/p/propgcc/issues Thread model: single gcc version 4.6.1 (propellergcc_v1_0_0_2408)
You're compiling it as C++ code. Name it "blink.c".
D:\Programs\spin2cpp>propeller-elf-gcc blink.c
C:\Users\username\AppData\Local\Temp\ccP3pDVm.o: In function _main': (.text+0xb4): undefined reference to
_getcnt'
C:\Users\username\AppData\Local\Temp\ccP3pDVm.o: In function _main': (.text+0x104): undefined reference to
_getcnt'
collect2: ld returned 1 exit status
If I do:
propeller-elf-gcc -c blink.c
then there is no errors and it produces a blink.o, but how do I make it a blink.binary? I tried uploading and renaming the file with .binary extension and uploading that using Propellent.exe but it gives an error popup saying the file is corrupt or is not a Propeller application Word 3 (codebase) must be $0010
That .o
file is only "blink.c" compiled, but not linked to the needed libc.
$ propeller-elf-gcc blink.c -o blink.elf
You can send that to the Propeller using propeller-load
.
(I never did this with Windows, so use the name of the serial instead of $COMX.)
$ propeller-load -p $COMX -r blink.elf
Your Propeller runs at 80MHz?
If not, add -Dclkfreq=
and the right speed (in Hz).
Look at propeller-load --help
: Values like -Dclkfreq=20khz
seem to be possible to.
I made a "normal" blink.binary
because GEAR doesn't load ELF format with propeller-load -Dclkfreq=20kHz -s blink.elf
and ran that resulting blink.binary
with GEAR:
Seems, propeller-load
reads khz
as 1024*Hz
:-)
Not a drama but nice to know.
Relative to spin2cpp
we are far off topic now!
Switching over to https://forums.parallax.com/categories/propeller-1-multicore-microcontroller would yield answers I cannot give too: It's the natural habitat of SimpleIDE users... ;-)
My guess is that it's a clock issue. I notice that your Spin code does not declare the clock frequency or mode. spin2cpp assumes an 80 MHz external crystal, as does Propeller GCC (most Parallax boards have this). If you're using a DIP chip in your project you may well not have an external crystal? In which case something (like the SimpleIDE pause() function) probably will not work properly.
drawkula's blink.c above should work. You can replace getcnt() with just CNT (on Prop1 they are identical, the getcnt() macro was introduced to make porting to Prop2 easier).
Closing for now as a "cannot reproduce". But if any more details come to light please re-open.
I tested a blink.spin which blinks LED and uploaded it to the Propeller 40 pin DIP chip using the Prop USB plug and it blinks the LED just fine. But running the .binary file does not seem to work after I transform the file blink.spin to blink.binary. The upload is fine but nothing happens once the blink.binary is uploaded. Does the Propeller Chip 40 pin DIP not support Propeller C? I originally tried getting this to work in SimpleIDE using C code and it had the same problem so it led me down to this path.