This is my first technical post on Cemetech

I have a CG50 that I am interested in programming. I am on Ubuntu 17.04 and looking to set up the C SDK. I have seen the wiki page on setting up the SDK, but it seems to be rather old. Are there any up to date instructions on setup? Can I use the version of GCC I have on my computer already? (gcc 6.3.0 20170406.) I have only recently got Ubuntu after using Windows for years, so I have a bit of learning to do. I have written only very basic C before, but I also have some slightly more advanced C++ experience.

I have some questions about the calculator and Casio themselve's. What microcontroller/processor is used in the CG50? I have read that a SuperH 3 processor is used on the CG10/20 calculator here, supposedly with a base clock rate of 116MHz, underclocked to 58MHz. The CG50 is about twice as fast in tests, yet has a longer battery life than the CG10/20, so presumably it has a different processor, but I am guessing the same instruction set. Do we know exactly what processor is in the CG50? I have searched online and can't find the answer, why doe Casio not make this information easily available? Does Casio provide technical documentation of the calculator anywhere? I have found some basic user guides, but few specifics. Does Casio provide any official programming tools for the PRIZM series or does it plan to do so?

Edit: On the wiki http://prizm.cemetech.net/index.php/Technical_Info , it says that the processor is a SH4-A family SH7305 in the CG10/20 . So is it a SH3 in the CG10/20 or an SH4-A? This technical documentation is all for the CG10/20, will the wiki ever be updated for the CG50?

Thanks
There are some great programmers using ubuntu for fx-cg addins so I think they will be able to help you. I haven’t switched from windows aa linux was too hard for me. Maybe when you succeed despite being new to ubuntu - i will give it a try again. I used windows for addins coding and struggled with some parts but it was mostly solved so if you need help with windows post the problems here and I will try to help
Here is a very easy way to setup a compiler.
If you have not already done so run

Code:

sudo apt install build-essential

You might need other packages, I don't use Ubuntu.

First copy this:

Code:

#!/bin/bash
set -e
set -o pipefail

TMPDIR=/tmp
cd $TMPDIR

wget 'http://ftp.gnu.org/gnu/binutils/binutils-2.29.1.tar.xz'
wget 'http://ftp.gnu.org/gnu/gcc/gcc-7.2.0/gcc-7.2.0.tar.xz'

tar -xf binutils*
tar -xf gcc*

export PREFIX=$HOME/casio-gcc
mkdir -p $PREFIX
export PATH=$PATH:$PREFIX/bin
export TARGET=sh3eb-elf
export CFLAGS="-O2 -pipe -s -fomit-frame-pointer -ffunction-sections -fdata-sections"
export CXXFLAGS=$CFLAGS && export LDFLAGS="-Wl,--gc-sections"
mkdir -p build-binutils
cd build-binutils
../binutils-*/configure --disable-werror --target=$TARGET --prefix=$PREFIX --disable-nls --disable-tls --disable-libssp --enable-plugin --enable-plugins --enable-gold=yes
make -j8
make -j8 install
cd ..
mkdir -p build-gcc
cd build-gcc
../gcc-*/configure --target=$TARGET --prefix=$PREFIX  --without-headers --enable-plugin --enable-plugins --enable-gold=yes --enable-sjlj-exceptions --disable-hosted-libstdcxx --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --disable-nls --disable-tls --disable-libssp --disable-threads --disable-shared --enable-static --disable-__cxa_atexit --disable-libvtv --disable-libada --with-endian=big
make -j8 all-gcc
make -j8 install-gcc

make -j8 all-target-libgcc
make -j8 install-target-libgcc


To a file. You can call it whatever you like but there is a convention to give it a .sh extension for example setup-casio-gcc.sh.

Then in a terminal cd to the directory you created this file and run bash setup-casio-gcc.sh or whatever you called it.

This will compile gcc and install it to a folder called casio-gcc which will be found in your home directory.

Once the script is done you may cleanup your /tmp directory.

Note that /tmp should have lots of space maybe even 4gb. If you don't have that in /tmp modify TMPDIR. The reason we use /tmp is because it is a ram disk so compiling is very fast. It only takes a few minutes to run this script for me (excluding downloading GCC and binutils).

Now to get the SDK just run

Code:

git clone https://github.com/Jonimoose/libfxcg --depth 1

If this does not work because you don't have git run

Code:

sudo apt-get install git
ProgrammerNerd wrote:
Here is a very easy way to setup a compiler.
If you have not already done so run

Code:

sudo apt install build-essential

You might need other packages, I don't use Ubuntu.

First copy this:

Code:

#!/bin/bash
set -e
set -o pipefail

TMPDIR=/tmp
cd $TMPDIR

wget 'http://ftp.gnu.org/gnu/binutils/binutils-2.29.1.tar.xz'
wget 'http://ftp.gnu.org/gnu/gcc/gcc-7.2.0/gcc-7.2.0.tar.xz'

tar -xf binutils*
tar -xf gcc*

export PREFIX=$HOME/casio-gcc
mkdir -p $PREFIX
export PATH=$PATH:$PREFIX/bin
export TARGET=sh3eb-elf
export CFLAGS="-O2 -pipe -s -fomit-frame-pointer -ffunction-sections -fdata-sections"
export CXXFLAGS=$CFLAGS && export LDFLAGS="-Wl,--gc-sections"
mkdir -p build-binutils
cd build-binutils
../binutils-*/configure --disable-werror --target=$TARGET --prefix=$PREFIX --disable-nls --disable-tls --disable-libssp --enable-plugin --enable-plugins --enable-gold=yes
make -j8
make -j8 install
cd ..
mkdir -p build-gcc
cd build-gcc
../gcc-*/configure --target=$TARGET --prefix=$PREFIX  --without-headers --enable-plugin --enable-plugins --enable-gold=yes --enable-sjlj-exceptions --disable-hosted-libstdcxx --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --disable-nls --disable-tls --disable-libssp --disable-threads --disable-shared --enable-static --disable-__cxa_atexit --disable-libvtv --disable-libada --with-endian=big
make -j8 all-gcc
make -j8 install-gcc

make -j8 all-target-libgcc
make -j8 install-target-libgcc


To a file. You can call it whatever you like but there is a convention to give it a .sh extension for example setup-casio-gcc.sh.

Then in a terminal cd to the directory you created this file and run bash setup-casio-gcc.sh or whatever you called it.

This will compile gcc and install it to a folder called casio-gcc which will be found in your home directory.

Once the script is done you may cleanup your /tmp directory.

Note that /tmp should have lots of space maybe even 4gb. If you don't have that in /tmp modify TMPDIR. The reason we use /tmp is because it is a ram disk so compiling is very fast. It only takes a few minutes to run this script for me (excluding downloading GCC and binutils).

Now to get the SDK just run

Code:

git clone https://github.com/Jonimoose/libfxcg --depth 1

If this does not work because you don't have git run

Code:

sudo apt-get install git


Thank you for the answer. So am I correct that your instructions will build another version of gcc, that wont affect the existing gcc on my system? The wiki says that I need mk3ga for the makefile to package the .elf files into .g3a files, does mk3ga come with the SDK? How do I invoke gcc to compile for the processor on the casio and not for my computer?

Thanks!

I have a lot of questions, I imagine some of them obvious.
RobC wrote:
Thank you for the answer. So am I correct that your instructions will build another version of gcc, that wont affect the existing gcc on my system? The wiki says that I need mk3ga for the makefile to package the .elf files into .g3a files, does mk3ga come with the SDK? How do I invoke gcc to compile for the processor on the casio and not for my computer?

Thanks!

I have a lot of questions, I imagine some of them obvious.

Normally you can just rename gcc in the installed compiler directory to gcc-casio if it isn't already. Then it will be able to compile for casio by running gcc-casio instead. I believe that mk3ga does come; but you should probably check that.
MateoConLechuga wrote:

Normally you can just rename gcc in the installed compiler directory to gcc-casio if it isn't already.

Assuming that it isn't, how would I do this?
RobC wrote:
MateoConLechuga wrote:

Normally you can just rename gcc in the installed compiler directory to gcc-casio if it isn't already.

Assuming that it isn't, how would I do this?

Navigate into the created script directory 'casio-gcc' and rename the 'gcc' file to 'gcc-casio' Smile
MateoConLechuga wrote:
RobC wrote:
MateoConLechuga wrote:

Normally you can just rename gcc in the installed compiler directory to gcc-casio if it isn't already.

Assuming that it isn't, how would I do this?

Navigate into the created script directory 'casio-gcc' and rename the 'gcc' file to 'gcc-casio' Smile

Doh, Thanks!
I never had to do that. All you do is run sh3eb-elf-gcc instead of gcc. Also run

Code:

export PATH=$PATH:~/casio-gcc/bin

To easily use sh3eb-elf-gcc anywhere. In practice you will never have to type sh3eb-elf-gcc because the make files will do it for you. When I want to compile my programs I just type make and everything is taken care of for me.

The reason this installation of will not interfere with your systems installation of GCC is because we install it in a different directory. In addition the script is not ran as root so your system's GCC installation is protected.
ProgrammerNerd wrote:
I never had to do that. All you do is run sh3eb-elf-gcc instead of gcc. Also run

Code:

export PATH=$PATH:~/casio-gcc/bin

To easily use sh3eb-elf-gcc anywhere. In practice you will never have to type sh3eb-elf-gcc because the make files will do it for you. When I want to compile my programs I just type make and everything is taken care of for me.

Oh, OK, I will try this first instead. So sh3-elf-gcc will produce the .elf that I can then convert to .g3a with the mkg3a. Great, I will try to set this up tomorrow if I have time, and compile, package and upload a test C program to confirm it all works. If I get this all working I will document the steps on the wiki.
Yes that is all correct. Note that when compiling your programs you will need to specify a few options. Running sh3eb-elf-gcc main.c -o my_program is not enough. Look at this make file for an example
https://github.com/ComputerNerd/Mandelbrot-Casio-Prizm-Explorer/blob/master/Makefile.casio

Note that not everything in that Makefile is necessary for compiling a program. The -DCASIO_PRIZM is only used by my Mandelbrot project to allow cross compiling for PC.

Also this makefile assumes it is in the libfxcg/examples/project_name because of its use of relative paths.
ProgrammerNerd wrote:
Yes that is all correct. Note that when compiling your programs you will need to specify a few options. Running sh3eb-elf-gcc main.c -o my_program is not enough. Look at this make file for an example
https://github.com/ComputerNerd/Mandelbrot-Casio-Prizm-Explorer/blob/master/Makefile.casio

Note that not everything in that Makefile is necessary for compiling a program. The -DCASIO_PRIZM is only used by my Mandelbrot project to allow cross compiling for PC.

Also this makefile assumes it is in the libfxcg/examples/project_name because of its use of relative paths.


Does this makefile definitely work? Mandelbrot explorer does not work on cg50 for me.
My thanks to ProgrammerNerd for getting me off the starting blocks on FX-CG50 C programming! Where others view this device as a calculator, I look at it as a microprocessor with a color graphics display at a favorable price ($52 at Walmart this week.) Very Happy

I did had to dodge a problem with stdint.c, in the libfxcg includes, which I'd seen mentioned elsewhere. I can expand on that, if anyone else go hung-up there. But what has me scratching my head at this point is trouble linking the Mandelbrot example cited above. The linking stage proceeds like this:

Quote:
sh3eb-elf-gcc src/main.o -m4a-nofpu -mb -O3 -mhitachi -Wall -I../../include -lgcc -L../../lib -DCASIO_PRIZM -flto -fuse-linker-plugin -nostartfiles -T../../toolchain/prizm.x -Wl,-static -Wl,-gc-sections -o mandelbrot.elf
/home/rdavis/casio-gcc/lib/gcc/sh3eb-elf/7.2.0/../../../../sh3eb-elf/bin/ld: mandelbrot.elf section `.bss' will not fit in region `ram'
/home/rdavis/casio-gcc/lib/gcc/sh3eb-elf/7.2.0/../../../../sh3eb-elf/bin/ld: region `ram' overflowed by 65616 bytes
/home/rdavis/casio-gcc/lib/gcc/sh3eb-elf/7.2.0/../../../../sh3eb-elf/bin/ld: BFD (GNU Binutils) 2.29.1 internal error, aborting at ../../binutils-2.29.1/bfd/linker.c:2162 in _bfd_generic_link_output_symbols


The -T option points to a linker file which appears to reserve 64K of target memory for code-segment 'ram' and the linker seems to think I'm trying to use more than twice that. This will be a test of my elf knowledge. I reckon I can claw my way thru it, but thought to check for been-there-done-that experts.

I've yet to find any architectural summary of the FX-CGxx family members, e.g. their memory maps, processor flavors, etc... have I simply missed this?
Actually you have much more ram but the linker script is wrong. You can change the 64K.
I think this will work:

Code:

ram (rwx) : o = 0x08100000, l = 512k
When i tried to make a hello world program all i get is syscall errors.

Here is my source code

https://cdn.discordapp.com/attachments/667255925735686185/672370624093487104/game.7z
Doesn't look like your makefile is building .S files. The syscalls are implemented in a bunch of separate assembly .S files in libfxcg. You should be able to see the right flags and as options for this in any of the libfxcg sources lying around..

Something I have on my list is to inline assemble all of the sdk syscalls in my SDK version, sort of like the linux std library, as there really isn't any need for separate symbols.
Looks like you have built fxcg libs in there, too, btw. You probably can use those instead if you want, but you need to list them in your ldflags
hi all, i followed ProgrammerNerd's code to download and compile gcc and binutils. I installed and bunch of prerequisites on my system after which I git cloned libfxcg and built that too and it went fine. I compiled the example code and deployed to my calculator, that worked fine too, i changed code and rebuilt that worked. But as soon as I try to use sprintf and include <stdio.h> my build fails with the following error:


Code:

sh3eb-elf-gcc -MMD -MP -MF /home/ab/casio/libfxcg/examples/display/helloWorld/build/main.d -Os -Wall -mb -m4a-nofpu -mhitachi -nostdlib   -I/home/ab/casio/libfxcg/examples/display/helloWorld/build -I/home/ab/casio/libfxcg/include -ffunction-sections -fdata-sections -c /home/ab/casio/libfxcg/examples/display/helloWorld/src/main.c -o main.o
/home/ab/casio/libfxcg/examples/display/helloWorld/src/main.c:8:6: warning: return type of 'main' is not 'int' [-Wmain]
 void main(void){
      ^~~~
sh3eb-elf-gcc  main.o -mb -m4a-nofpu -mhitachi -nostdlib -T/home/ab/casio/libfxcg/toolchain/prizm.x -Wl,-static -Wl,-gc-sections  -L/home/ab/casio/libfxcg/lib -lc -lfxcg -lgcc -o /home/ab/casio/libfxcg/examples/display/helloWorld/helloWorld.bin
/home/ab/casio-gcc/lib/gcc/sh3eb-elf/7.2.0/../../../../sh3eb-elf/bin/ld: BFD (GNU Binutils) 2.29.1 internal error, aborting at ../../binutils-2.29.1/bfd/linker.c:2162 in _bfd_generic_link_output_symbols

/home/ab/casio-gcc/lib/gcc/sh3eb-elf/7.2.0/../../../../sh3eb-elf/bin/ld: Please report this bug.

collect2: error: ld returned 1 exit status
make[1]:  [/home/ab/casio/libfxcg/toolchain/prizm_rules:83: /home/ab/casio/libfxcg/examples/display/helloWorld/helloWorld.bin] Error 1
make:  [Makefile:108: all] Error 2


any idea on whats going on here? thanks.
zero00 wrote:
hi all, i followed ProgrammerNerd's code to download and compile gcc and binutils. I installed and bunch of prerequisites on my system after which I git cloned libfxcg and built that too and it went fine. I compiled the example code and deployed to my calculator, that worked fine too, i changed code and rebuilt that worked. But as soon as I try to use sprintf and include <stdio.h> my build fails with the following error:


Code:

sh3eb-elf-gcc -MMD -MP -MF /home/ab/casio/libfxcg/examples/display/helloWorld/build/main.d -Os -Wall -mb -m4a-nofpu -mhitachi -nostdlib   -I/home/ab/casio/libfxcg/examples/display/helloWorld/build -I/home/ab/casio/libfxcg/include -ffunction-sections -fdata-sections -c /home/ab/casio/libfxcg/examples/display/helloWorld/src/main.c -o main.o
/home/ab/casio/libfxcg/examples/display/helloWorld/src/main.c:8:6: warning: return type of 'main' is not 'int' [-Wmain]
 void main(void){
      ^~~~
sh3eb-elf-gcc  main.o -mb -m4a-nofpu -mhitachi -nostdlib -T/home/ab/casio/libfxcg/toolchain/prizm.x -Wl,-static -Wl,-gc-sections  -L/home/ab/casio/libfxcg/lib -lc -lfxcg -lgcc -o /home/ab/casio/libfxcg/examples/display/helloWorld/helloWorld.bin
/home/ab/casio-gcc/lib/gcc/sh3eb-elf/7.2.0/../../../../sh3eb-elf/bin/ld: BFD (GNU Binutils) 2.29.1 internal error, aborting at ../../binutils-2.29.1/bfd/linker.c:2162 in _bfd_generic_link_output_symbols

/home/ab/casio-gcc/lib/gcc/sh3eb-elf/7.2.0/../../../../sh3eb-elf/bin/ld: Please report this bug.

collect2: error: ld returned 1 exit status
make[1]:  [/home/ab/casio/libfxcg/toolchain/prizm_rules:83: /home/ab/casio/libfxcg/examples/display/helloWorld/helloWorld.bin] Error 1
make:  [Makefile:108: all] Error 2


any idea on whats going on here? thanks.


I have never seen an error like that before, might you be able to include your code?
You should also make a new thread as this is quite old and is about a different issue.
i made a new post here https://www.cemetech.net/forum/viewtopic.php?p=299624#299624 as you asked.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement