Recently I’ve been playing around with using the eclipse IDE as an alternative development environment for the cortex. This does require a valid EasyC license but works quite well. One final step that was needed was a way to download the output .HEX file that is created, the EasyC download software works well for this but always brings up the download window. The EasyC download program is called “iLoader” and can be run with command line arguments, although (working with others) these were recently reverse engineered I though it would be worthwhile creating an alternative command line program that could achieve the same thing and also be open sourced.
There is a great starting point for this type of project as many others have wanted to do the same type of thing, the VEX cortex can not use this code without modification as there is no direct access to a serial port on the STM32 processor, however, with minor modification this code can be adapted.
The major changes are as follows.
Add some code to allow the host to put the cortex in user code download mode, this can be achieved in one of two ways.
-
A sequence involving toggling the RTS line of the serial programming adapter along with sending one special character to it.
-
Sending a command sequence to the supervisor processor in the cortex, this has the advantage of working with both the serial programming adapter and also a direct USB connection using the latest VEX serial driver included with V3.0 firmware and later.
Retry of the auto baudrate selection command, the prolific adapter has issues/bugs in it’s driver that mean that often the first character transmitted after a change of baud rate will be dropped. A retry sequence on the auto baud selection helps with this.
Addition of command line options and removal of others.
There are other changes to the source including some re-factoring of the main source file but they are all minor.
Usage is as follows.
cortexflash -X -g0 -w thefile.hex COM3
-X will put the cortex in download mode
-g0 will cause the program to execute after download
-w thefile.hex write the specified hex file
COM3 is the serial port to which the cortex is connected, your port will probably be different, check the device manager.
Here is the full usage from running the software with no arguments.
Usage: ./cortexflash -bvngfhc] -[rw] filename] /dev/tty.usbserial
-b rate Baud rate (default 115200)
-X Enter VEX user program mode
-X1 Enter VEX user program mode using C9 commands
-X2 Enter VEX user program mode using old style RTS control
-r filename Read flash to file
-w filename Write flash to file
-u Disable the flash write-protection
-e n Only erase n pages before writing the flash
-v Verify writes
-n count Retry failed writes up to count times (default 10)
-g address Start execution at specified address (0 = flash start)
-f Force binary parser
-h Show this help
-c Resume the connection (don't send initial INIT)
*Baud rate must be kept the same as the first init*
This is useful if the reset fails
Examples:
Get device information:
./cortexflash -X /dev/tty.usbserial
Write with verify and then start execution:
./cortexflash -X -w filename -v -g 0x0 //dev/tty.usbserial
Read flash to file:
./cortexflash -X -r filename /dev/tty.usbserial
this was run on a Mac so the serial device is shown as /dev/tty.usbserial.
Source code and compiled executables for OSX and Win32 are available here. I’ve only tested under OSX 10.5 and windows XP SP3. It’s not 100% reliable and occasionally has trouble making the initial connection, if that succeeds downloads always seem to work.
https://www.box.com/s/967650aee17cc86510b6
The OSX version can only use the serial programming adapter as there is no driver for the VEX USB device ( yet:) )
Usual disclaimers apply, only use with .hex files from EasyC or images uploaded from the cortex. Don’t use this if you don’t know what you are doing, I’m not responsible for any damage you may cause. No one really needs this except the hackers amongst us who want to make their own tools.