spin2cpp: missing volatile (bug?)
SRLM
Posts: 5,045
I tried running spin2cpp on FullDulpexSerial.spin, and created my own main.cpp file:
Running with the version of FDS that spin2cpp generates gives gibberish output:
However, compiling with -O0 (instead of -Os) gives the expected output. This lead to the addition of volatile to the fdsSpin class variables:
fds.h:
I don't know if this is a bug or not, since there isn't really any way to tell if a PASM snippet will modify a variable, but maybe a warning would be good.
#include "fds.h" #include <stdint.h> #include <propeller.h> int main(void) { int32_t rxpin = 31; int32_t txpin = 30; int32_t mode = 0; int32_t baud = 115200; fdsSpin port; port.Start(rxpin, txpin, mode, baud); waitcnt(CLKFREQ*1 + CNT); port.Tx('a'); port.Tx('b'); port.Tx('c'); port.Tx('d'); port.Tx('\n'); port.Tx('\r'); port.Str("Trouble\r\n"); waitcnt(CLKFREQ/2 + CNT); for(;;) { // char output[] = "Hello, World!\r\n"; // port.Str(&output); port.Str("XYZ\r\n"); waitcnt(CLKFREQ/2 + CNT); port.Str("Afternoon\r\n"); waitcnt(CLKFREQ/2 + CNT); port.Str("Boxing\r\n"); waitcnt(CLKFREQ/2 + CNT); port.Str("Charlie\r\n"); waitcnt(CLKFREQ + CNT); } }
Running with the version of FDS that spin2cpp generates gives gibberish output:
Propeller Version 1 on /dev/ttyUSB0 Loading main.elf to hub memory 4596 bytes sent Verifying RAM ... OK [ Entering terminal mode. Type ESC or Control-C to exit. ] bcd Trouble YZ fternoon Xoxing eharlie oYZ fternoon Xoxing eharlie oYZ ...
However, compiling with -O0 (instead of -Os) gives the expected output. This lead to the addition of volatile to the fdsSpin class variables:
fds.h:
// // automatically generated by spin2cpp on Mon Nov 26 13:40:54 2012 // ./spin2cpp.linux fds.spin // #ifndef fdsSpin_Class_Defined__ #define fdsSpin_Class_Defined__ #include <stdint.h> class fdsSpin { public: ... private: // int32_t Cog; // int32_t Rx_head; ... volatile int32_t Cog; volatile int32_t Rx_head; ... }; #endif
I don't know if this is a bug or not, since there isn't really any way to tell if a PASM snippet will modify a variable, but maybe a warning would be good.
Comments
Thanks for the report!
Eric
Another small issue, with the same object: the buffer size is specified with a constant in the Spin version, but replaced with a literal in the .h file (look for 987):
Eric