I just did a first run at fsrw26 program, below is some observations.
Now, using these preliminary code size numbers for the RTC, CM2302, and fsrw26 code size, it looks like all of those will not fit in the available RAM. Plus using the ADC, which is an unknown at this point, will probably add another ~8000, maybe.
Not sure as to what kind of optimization you would have to do, in order to make it comparable to PropGCC code size.
Ray
rem test_fsrw26.bas
' October 14, 2018
' Test for the fsrw26 to interact with the SD card.
dim fsrw as class using "fsrw.spin"
fsrw.mount_explicit(22, 23, 24, 25)
Options - No Optimization
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2018 Total Spectrum Software Inc.
Version 3.9.5-beta Compiled on: Oct 11 2018
test_fsrw.bas
|-fsrw.spin
|-|-safe_spi.spin
test_fsrw.pasm
G:/fastspin/programs/test_fsrw/test_fsrw.pasm(6705) error: fit 496 failed: pc is 532
child process exited abnormally
Options - Default Optimization
G:/fastspin/spin2gui/bin/fastspin -l -O1 -L ./lib G:/fastspin/programs/test_fsrw/test_fsrw.bas
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2018 Total Spectrum Software Inc.
Version 3.9.5-beta Compiled on: Oct 11 2018
test_fsrw.bas
|-fsrw.spin
|-|-safe_spi.spin
test_fsrw.pasm
Done.
Program size is 13664 bytes
Options - Full Optimization
G:/fastspin/spin2gui/bin/fastspin -l -O2 -L ./lib G:/fastspin/programs/test_fsrw/test_fsrw.bas
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2018 Total Spectrum Software Inc.
Version 3.9.5-beta Compiled on: Oct 11 2018
test_fsrw.bas
|-fsrw.spin
|-|-safe_spi.spin
test_fsrw.pasm
G:/fastspin/programs/test_fsrw/test_fsrw.pasm(2157) error: syntax error, unexpected ??
child process exited abnormally
Problem sorted. Both my bad.
I re downloaded fsrw26 ( I think it was corrupted) and changed my Fastspin options
fastspin -I-O0-L--fixed "%f"
class fullduplex using "FullDuplexSerial.spin"
class fsrw using "fsrw.spin" 'dowloaded from OBEX
dim ser as fullduplex
dim sd as fsrw
' test typewriter here
dim chr as ubyte
ser.start(31, 30, 0, 115200)
pausems(1000)
do
chr = ser.rx()
ser.tx(chr)
if chr = 13 then
ser.tx(10)
' handle SDcard commands here...but not ready yet
end if
loop
Voici le résultat
simpletest.bas
|-FullDuplexSerial.spin
|-fsrw.spin|-
|-safe_spi.spin
simpletest.pasm
Done.
Program size is 15384 bytes
Compilation finished successfully.
Ron and Ray : thank you both for testing fsrw! SD card support is obviously a pretty important feature, and the slot on my C3 board doesn't seem to work . Reducing the amount of memory (both COG and HUB) used by fsrw.spin is high on my list of things to do.
Below is my first attempt at using fsrw to write something to the SD card. The program compiles without any errors, using the Options - Default Optimization, but I do not get anything written to the SD card. It does not even create the file name. Any ideas as to what too look at?
Ray
rem test_fsrw26.bas
' October 14, 2018
' Test for the fsrw26 to interact with the SD card.
dim fsrw as class using "fsrw.spin"
dim file as string
dim mode as string
dim line1 as string
file = "data1.txt"
mode = "w"
line1 = "So be it."
fsrw.mount_explicit(22, 23, 24, 25)
fsrw.popen(file,mode)
fsrw.pwrite(line1,11)
fsrw.pclose()
fsrw.unmount()
I have a version of safe_spi.spin that I used in spinix that supports the C3 and the 4-pin methods. However, because of the way spinix works, it's split into two files. I'll see if I have an in-split version somewhere.
@Rsadeika : I think the first problem is that fsrw.popen actually takes an integer rather than a string for its "mode" parameter. This is one of the odd features of the Spin language: a single character inside quotes gets translated into the ASCII value of that character. So you actually want to set mode with:
dim mode as integer
...
mode = asc("w")
You could also try printing the results of the fsrw operations to see if they return errors.
The asc() was the missing part, now it is creating the file on the SD card. I added some CR/LF stuff which does not want to work. I also tried the asc("13')/asc("10"), that also did not work. Maybe need to try '13'/'10'.
I tried the mode "a", which does create a file, if none is existing, but it does not append to an existing file, it just seems to overwrite.
Also the file contents looks like there is unwanted chars that are being added. Maybe the character count of the string has to be exact, I have been adding one char number to the count.
Ray
rem test_fsrw26.bas
' October 14, 2018
' Test for the fsrw26 to interact with the SD card.
dim fsrw as class using "fsrw.spin"
dim file as string
dim mode as integer
dim line1 as string
file = "data1.txt"
mode = asc("a") '
line1 = "So be it."
fsrw.mount_explicit(22, 23, 24, 25)
fsrw.popen(file,asc("w"))
fsrw.pwrite(line1,10)
fsrw.pwrite(13,1)
fsrw.pwrite(10,1)
fsrw.pwrite("Lets try this to.",19)
fsrw.pwrite(13,1)
fsrw.pwrite(10,1)
fsrw.pwrite("Lets try this one also.",24)
fsrw.pwrite(13,1)
fsrw.pwrite(10,1)
fsrw.pclose()
fsrw.unmount()
SD file contents.
So be it. °Lets try this to. L °Lets try this one also. °
I did the chr$() suggestion, so I am not sure if that cured the CR/LF, but the compiler did not like it. Since the error shows something about fit 496, I guess it is over running the COG ram.
Ray
rem test_fsrw26.bas
' October 14, 2018
' Test for the fsrw26 to interact with the SD card.
dim fsrw as class using "fsrw.spin"
dim file as string
dim mode as integer
dim line1 as string
file = "data1.txt"
mode = asc("a") '
line1 = "So be it."
fsrw.mount_explicit(22, 23, 24, 25) ' This is using the WX Activity Board
fsrw.popen(file,asc("w"))
fsrw.pwrite(line1,10)
fsrw.pwrite(chr$(13),1)
fsrw.pwrite(chr$(10),1)
fsrw.pwrite("Lets try this to.",19)
fsrw.pwrite(chr$(13),1)
fsrw.pwrite(chr$(10),1)
fsrw.pwrite("Lets try this one also.",24)
fsrw.pwrite(chr$(13),1)
fsrw.pwrite(chr$(10),1)
fsrw.pclose()
fsrw.unmount()
G:/fastspin/spin2gui/bin/fastspin -l -O1 -L ./lib G:/fastspin/programs/test_fsrw/test_fsrw.bas
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2018 Total Spectrum Software Inc.
Version 3.9.5-beta Compiled on: Oct 11 2018
test_fsrw.bas
|-fsrw.spin
|-|-safe_spi.spin
test_fsrw.pasm
G:/fastspin/programs/test_fsrw/test_fsrw.pasm(6458) error: fit 496 failed: pc is 510
child process exited abnormally
@rsut and @Rsadeika : thanks for testing this! I'm glad fsrw is working. Reducing the memory footprint of fastspin compiled objects is pretty high on my priority list, so that we can make fsrw even more useful with other objects.
You can work around the COG memory problem by adding "--fcache=0" to the fastspin command line; that'll free up some COG space. To do that with spin2gui, open the "Configure Commands..." dialog and change the "Run Command" string to start with "fastspin --fcache=0" instead of "fastspin".
As I mentioned, reducing the COG memory footprint is high on my to-do list.
… open the "Configure Commands..." dialog and change the "Run Command" string to start with "fastspin --fcache=0" instead of "fastspin".
This should be change the "Compile Command".
The "fcache" did the trick, at least for being able to get the chr$() to work. On the first line, in the SD file, I have a "w" showing up, and I do not see where or what is causing that. Now, when we can get that program, or at least the fsrw down too ~5000, that would be great.
Ray
rem test_fsrw26.bas
' October 14, 2018
' Test for the fsrw26 to interact with the SD card.
dim fsrw as class using "fsrw.spin"
dim file as string
dim mode as integer
dim line1 as string
dim CRLF as string
file = "data1.txt"
mode = asc("a") '
line1 = "So be it."
CRLF = chr$(10)+chr$(13)
fsrw.mount_explicit(22, 23, 24, 25) ' This is using the WX Activity Board
fsrw.popen(file,asc("w"))
fsrw.pwrite(line1,11)
fsrw.pwrite(CRLF,2)
fsrw.pwrite("Lets try this to.",17)
fsrw.pwrite(CRLF,2)
fsrw.pwrite("Lets try this one also.",23)
fsrw.pwrite(CRLF,2)
fsrw.pclose()
fsrw.unmount()
print "All Done!"
I've updated the first post in this thread to have links to the most recent fastspin / spin2gui. The fastspin compiler has a bunch of bug fixes and support for global (shared) variables. spin2gui has the new fastspin and now comes with proploader instead of propeller-load, so it should be able to work over WiFi (it's not something I can test).
There happens to be nine chars in that string. So, you have to have the correct number, representing the string, in order for pwrite() to work correctly.
I just tried the new spin2gui, and it is not working, as expected. When I do the Compile & Run, it just throws up a blank terminal screen, and closes very quickly. Nothing is getting written to the SD card, so it never opened a port.
I think proploader looks for open ports, which includes active WiFi ports, and then you have choose which one to use. Since I have another WX Activity Board, in the vicinity, that is running 24/7, that would be showing up as a valid port. I think David Betz needs to jump in with an explanation as to how it would work with spin2gui.
Ron: actually I don't think it's obvious at all -- I think we do indeed need some way for BASIC to catch aborts that are thrown by Spin objects, otherwise the program gets terminated (or should be... I just found a bug in fastspin's abort code that causes it to sometimes get into a loop when abort happens).
I'm thinking of two possible syntaxes:
x = try fsrw.popen(file, mode)
which would be the same as spin's
x = \fsrw.popen(file, mode)
and also a more verbose:
try
fsrw.popen
catch err
print "got error code", err
end
Yes, I will look at that tomorrow. I need the return args from fsrw.
Here is some code of functions I have been looking at this evening. They are simple functions which I can break
to try you approach
rem test_fsrw26.bas
dim sd as class using "fsrw.spin"
dim ser as class using "FullDuplexSerial"
dim mode as ubyte
dim file_name as string
dim text as string
dim len as integer
function rdfile(file_name$, text$, lLEN) 'TODO need to use sd.getfilesize to use this function
mode= asc("r")
sd.popen(file_name,mode)
sd.pread(text,LEN)
sd.pclose()
end function
function wrfile(file_name$, text$, len) 'TODO Use ser class for input in leu of INPUT$ so that I can count string length at the input stage
mode= asc("w")
sd.popen(file_name,mode)
sd.pwrite(text,LEN)
sd.pclose()
end function
The abort mechanism in Spin has a flaw I always struggle with, and that is the problem to distinguish between a regular return code and a abort situation.
If I have something like popen(xxxx) returning some valid value (say filehandle) and I do have some abort, ho to tell apart?
x:= \popen(xxxx) does not give me that, I have to make sure my abort value is (for example) negative and my expected correct return value not.
the try catch syntax would allow to separate this (if possible?)
try
x = fsrw.popen(xxx)
catch err
print "got error code", err
end
Comments
Now, using these preliminary code size numbers for the RTC, CM2302, and fsrw26 code size, it looks like all of those will not fit in the available RAM. Plus using the ADC, which is an unknown at this point, will probably add another ~8000, maybe.
Not sure as to what kind of optimization you would have to do, in order to make it comparable to PropGCC code size.
Ray
Options - No Optimization Options - Default Optimization Options - Full Optimization
Problem sorted. Both my bad.
I re downloaded fsrw26 ( I think it was corrupted) and changed my Fastspin options
fastspin -I-O0-L--fixed "%f"
class fullduplex using "FullDuplexSerial.spin"
class fsrw using "fsrw.spin" 'dowloaded from OBEX
dim ser as fullduplex
dim sd as fsrw
' test typewriter here
dim chr as ubyte
ser.start(31, 30, 0, 115200)
pausems(1000)
do
chr = ser.rx()
ser.tx(chr)
if chr = 13 then
ser.tx(10)
' handle SDcard commands here...but not ready yet
end if
loop
Voici le résultat
simpletest.bas
|-FullDuplexSerial.spin
|-fsrw.spin|-
|-safe_spi.spin
simpletest.pasm
Done.
Program size is 15384 bytes
Compilation finished successfully.
Cheers
Ron
Eric
Ray
The C3 switches 7 SPI clients using an extra chip.
Look for SPI_SEL_CLK in ftp://ftp.propeller-chip.com/PropC3/Sources/c3_sd_drv_010.spin
You could also try printing the results of the fsrw operations to see if they return errors.
@ersmith
Eric, I can confirm that the SDcard runs all the tests.
I am using a standard demo board with the standard basepin config.
Now to write some code.
Ron
I tried the mode "a", which does create a file, if none is existing, but it does not append to an existing file, it just seems to overwrite.
Also the file contents looks like there is unwanted chars that are being added. Maybe the character count of the string has to be exact, I have been adding one char number to the count.
Ray
SD file contents.
Ray
I think Mickster's solution is the right one, Ray. For that matter you could do: and then use fsrw.pwrite(nl$, 2) to write the newline.
As I mentioned, reducing the COG memory footprint is high on my to-do list.
asc("a") replaced with 97
asc("w") replaced with 119
Dunno, just taking wild stabs until Eric chirps in
The "fcache" did the trick, at least for being able to get the chr$() to work. On the first line, in the SD file, I have a "w" showing up, and I do not see where or what is causing that. Now, when we can get that program, or at least the fsrw down too ~5000, that would be great.
Ray
Ray
I think proploader looks for open ports, which includes active WiFi ports, and then you have choose which one to use. Since I have another WX Activity Board, in the vicinity, that is running 24/7, that would be showing up as a valid port. I think David Betz needs to jump in with an explanation as to how it would work with spin2gui.
Ray
How do you trap for an error in classes, for example, in fsrw if the file can't be opened for whatever reason ?
In the case of an abort within the class, how is this handled ?
Ron
I'm thinking of two possible syntaxes: which would be the same as spin's and also a more verbose:
Do those seem to make sense?
Thanks for bringing this to my attention!
Eric
Yes, I will look at that tomorrow. I need the return args from fsrw.
Here is some code of functions I have been looking at this evening. They are simple functions which I can break
to try you approach
Ron
Yes, I will look at that tomorrow. I need the return args from fsrw.
Here is some code of functions I have been looking at this evening. They are simple functions which I can break
to try you approach
Ron
If I have something like popen(xxxx) returning some valid value (say filehandle) and I do have some abort, ho to tell apart?
x:= \popen(xxxx) does not give me that, I have to make sure my abort value is (for example) negative and my expected correct return value not.
the try catch syntax would allow to separate this (if possible?)
so that x just get changed if NO abort happened?
Mike
Think it's better to return an error value or 0 if OK...