Page 1 of 152

ERSKY9X Coding

Posted: Thu Dec 29, 2011 3:08 pm
by MikeB
Proposed file system for ERSKY9X 4Mb external EEPROM

The EEPROM erases data in 4K blocks, so we cannot easily update a few bytes.

Treat the EEPROM as an array of 4K blocks.
Block size = 4K
Number of blocks = 128

Use the first 2 blocks as directory and FAT.

To update directory:
Write to first block, erase second block, then write to second block, erase first.
If freeList = 0xFFFF, then block is erased.
Possibly include a sequence number to enable detection of the most recent block if the erase fails to take place e.g. Tx was switched off between write command and erase command. We could also include a CRC (CPU has a CRC calculation unit).

Initially assume all files fit in a single 4K block.

To write a new file:
1. Allocate a directory entry and a block, update ram copy of directory/FAT.
2. Write data to block.
3. Write directory to 'other' block, erase first block.

To erase a file:
1. Update ram copy of directory, add old block to end of free list in ram copy of FAT.
2. Write directory to 'other' block, erase first block.
3. Erase data block

To update a file:
1. Allocate new block, update ram copy of FAT.
2. Write data to new block, add old block to end of free list in ram copy of FAT.
3. Write directory to 'other' block, erase first block, erase freed block.

By following these sequences, the file system should remain intact if a write/erase fails to happen. It should also be possible to check if blocks have not been erased. Since data blocks that are to be erased are added at the end of the FAT list, they are easily found and checked on startup.

Any thoughts or better implementations? If we do this to start with we will at least have a method of getting er9x ported.

Mike.

Re: ERSKY9X Coding

Posted: Fri Dec 30, 2011 1:04 pm
by pmackenzie
How long does a erase/write cycle take? Won't it need to be done every time you move a trim button?

Perhaps the current model should be in a fixed location (or one of two if you want to do a save then erase method) , and it is only saved to the file structure when a new one is loaded?


Pat MacKenzie

Re: ERSKY9X Coding

Posted: Fri Dec 30, 2011 3:26 pm
by MikeB
Page program (256 bytes) is 5 mS max (1.2 mS typ).
Block erase time (4K bytes) is 200mS max (50mS typ).

I believe er9x already has a write delay time in for the trim changes. When you change a trim, it does not write immediately, but runs a timeout in case you hit the trim change again. After a while, it commits the change to the EEPROM.

Mike.

Re: ERSKY9X Coding

Posted: Sat Dec 31, 2011 10:05 pm
by SkyNorth
I have access to both sides of the power switch on the PCB , we could use a transistor to allow the micro to hold the power ON
until you are ready for shutdown.

-Brent

Re: ERSKY9X Coding

Posted: Sat Dec 31, 2011 11:58 pm
by MikeB
SkyNorth wrote:I have access to both sides of the power switch on the PCB , we could use a transistor to allow the micro to hold the power ON
until you are ready for shutdown.

-Brent
That could be interesting, I've used CPU controlled shutdown before, we may just need to be sure leakage current doesn't flatten the batteries.

Mike.

Re: ERSKY9X Coding

Posted: Thu Jan 05, 2012 3:45 pm
by erazz
Mike,

I want to start meddling with the code, I think it's high time we have a code page and repository. What do you think?

I took the liberty of making a new code page with you and me as co-owners. I would have added Brent but he has to give me a valid google account for that.


Anyway, here's the code page:
http://code.google.com/p/ersky9x/

SVN link:
https://ersky9x.googlecode.com/svn/trunk/


If you can, please upload what you have so we can start collaborating in ernest :)

Re: ERSKY9X Coding

Posted: Thu Jan 05, 2012 3:53 pm
by Rob Thomson
Wonderful. Just want I have been wanting :-)

Re: ERSKY9X Coding

Posted: Thu Jan 05, 2012 4:01 pm
by MikeB
I'll upload as soon as I can. Is there something special I need to do to tell svn which files to upload? I may need to read the svn help, I've only updated files so far!

Mike.

Re: ERSKY9X Coding

Posted: Thu Jan 05, 2012 4:04 pm
by Rob Thomson
You using tortoise svn?

Simply download the repositry first time with nothing it it. That will create the repository on your PC. Then copy the files in to the repository and upload as per normal.

Rob

Re: ERSKY9X Coding

Posted: Thu Jan 05, 2012 4:05 pm
by MikeB
No just the command line svn, but the method may work anyway.

Mike.

Re: ERSKY9X Coding

Posted: Thu Jan 05, 2012 4:33 pm
by Rob Thomson
You so need to use

http://tortoisesvn.tigris.org/

on windows :D

Much easier!

Re: ERSKY9X Coding

Posted: Thu Jan 05, 2012 4:44 pm
by MikeB
OK, I've managed to get the source files uploaded in trunk\src. Revision 3, as revision 2 only created the src directory. I'm still learning svn!

Erazz, anything specific you want to work on?
Build, load and run.
Disconnect the USB and power from another source.
The LCD should come up with BAD eeprom - formatting etc. You will need to press a key, then you should get a blank LCD with ERSKY9X V0.23 at the top. From there, you need to have a terminal connected at 9600 baud (n,8,1) on the connector labelled COM1.

Type 'V' (single character, no quotes) and you should get the version number on the terminal.
Type 'W', this will enable a main processing routine every 10mS. This will also schedule an EERPOM write routine that will update the external EEPROM so you won't see the BAD eeprom again. You also get a display where you can test six switches, the trims, and the sticks/pots.

Hope this gets you started.

I've got a lot working, Menus is next on my list, followed by controlling the PPM output pulse widths, they are there, but are fixed at present. Then we might have a useable unit in a tx.

For the EEPROM, I've created a RAM copy of the existing eeprom structure, and write this to the first two 4K blocks alternately in the background. This is at least getting things started.

Mike.

Remember the EERPOM has a wiring problem:
The SI and SO signals to the EEPROM are swapped, MISO should go to SO and MOSI should go to SI.
Note: the SPI expansion port pads are incorrectly labeled, the pads MOSI and SCK are swapped.

Re: ERSKY9X Coding

Posted: Thu Jan 05, 2012 5:33 pm
by erazz
I think I need to sit down with a nice glass of Glenlivet and read your code. This ARM stuff is new to me too :)

Re: ERSKY9X Coding

Posted: Fri Jan 13, 2012 1:42 am
by Rafit
Which compiler / IDE are you using for coding ErSky9X?
Is there anything free which works on Windows?

Re: ERSKY9X Coding

Posted: Fri Jan 13, 2012 9:32 am
by MikeB
Compiler downloaded from YAGARTO. It is a GNU-GCC compiler (free). I don't use an IDE as such, I have an editor called MULTIEDIT that provides that function, it integrates calls to compile/make so works like an IDE. There is an IDE called ECLIPSE that should work with the YAGARTO compiler. I have it installed, but have not really used it.

Mike.

Re: ERSKY9X Coding

Posted: Wed Jan 18, 2012 5:06 pm
by MikeB
Announcement:

It works!

Well, I've mounted my prototype ersky9x board in a 9x, with a FrSky DIY tx module, calibrated the sticks, and can actually control a servo on a FrSky V8R4 rx.
Most of the menus are now in, standard version er(sky)9x only, no telemetry, no startup alerts, just plain PPM control. Powers up with a splash screen for 1.5 seconds, then goes into normal operation.
Checked all the switches and pots work using the diag menus.
The 9x with Tx module and LED backlight, running from 7.3 volts (bench PSU) is taking about 210mA. The backlight is probably around 20 to 30mA of this.

Still a lot of things to do, but this is proof of concept.

Source files at this point are committed to the ersky9x site.

Mike.

ERSKY9X Coding

Posted: Wed Jan 18, 2012 6:05 pm
by Rob Thomson
Well done!

Time for me to get it in my spare tx.

Before I do this - has the USB port moved from the current board that we have?

Rob


Sent from my iPhone using Tapatalk

Re: ERSKY9X Coding

Posted: Wed Jan 18, 2012 8:04 pm
by SkyNorth
Mike, that puts a smile on my face!

Yes Rob, the USB port has been moved over , so dont put a hole in your case for it yet.

-Brent

Re: ERSKY9X Coding

Posted: Wed Jan 18, 2012 10:49 pm
by MikeB
Rob, the USB is also on a 4 pin header. You may need to wire a suitable USB connector to that, or possibly, see if there is a vertical mount mini connector available to replace the existing, right-angled one. Snag with that is, it would still be inside the case, so the 4 pin header is your best bet. That's what I've done, but then I had a USB connector lying around.

Mike.

Re: ERSKY9X Coding

Posted: Wed Jan 18, 2012 11:15 pm
by SkyNorth
He could also use his SmartieParts USB connector.
-Brent

Re: ERSKY9X Coding

Posted: Thu Jan 19, 2012 6:41 am
by Rob Thomson
No issue hooking it in - just was wondering if I should drill the case. This has now been answered - so will hold off on that for now!

Re: ERSKY9X Coding

Posted: Thu Jan 19, 2012 9:32 pm
by MikeB
I think I'm finding some problems with the compiler. This is due to the mixture of int8_ts, int16_ts and int32_ts. It is possible the compiler is working OK, but it is allowed to make decisions regarding how long a variable actually is. The problem area I have is in menuProcExpoOne. expo() in declared as returning int16_t, and the result is being assigned to an int32_t. No sign extension of the 16 bit value is taking place. It is as though the compiler actually expects the returned value (in a register) to already be 32 bits long, but it isn't. I'm still investigating this. Adding explicit casts does not cure the problem.
The horizontal and vertical lines in menuProcExpoOne are incorrectly displayed when the stick position is negative.

Mike.

Edit: OK, tracked this one down. expo() calls expou() that returns a uint16_t. Even though this value is assigned to an int16_t, it appears the compiler 'promotes' the 16 bit int to unsigned, so doesn't sign extend it to 32 bits for the return. Declaring y, in expo(), as a 32 bit int solves the problem. It seems mixing 16 bit signed and unsigned may cause problems.

Re: ERSKY9X Coding

Posted: Thu Jan 19, 2012 11:16 pm
by MikeB
Just got the diagnostic timer running on the main loop. If I've done it correctly, and the values are representative, I have a time of about 2mS for ersky9x for tmain, compared with about 7mS on er9x. So we might guess that the ARM processor is running about 3.5 times faster that the ATMEGA.
This is without fully optimising the compiled ARM code. Also we are running the ARM at 36MHz, it will go to 64MHz if necessary. This is software controlled as it has on-chip PLL for the clock generation, so it is available as a future enhancement. The processor will, however consume more current at the higher speed.
Current consumption of ARM board, LED backlight, and FrSKy V8HT module is about 210mA.

Mike.

Re: ERSKY9X Coding

Posted: Sun Jan 29, 2012 11:10 pm
by MikeB
Just spent a load of time getting an applet for the SAM-BA loader to load and run. I can now read blocks from the external serial EEPROM using SAM-BA. I need to get it to be able to write and erase blocks and erase the chip as well, but it is a start. This and other things (like actually flying a couple of models yesterday, and slimming er9x) has slowed my progress on ersky9x itself. I'll get back on it soon.

Mike.

Installing Serial Flash applet

Posted: Wed Feb 01, 2012 11:00 pm
by MikeB
In the Sam-ba installation under sam-ba_2.11 directory is the directory tcl_lib. In this directory is a file boards.tcl. Edit this file and in the:
array set boards {
section add:
"at91sam3s2-9x" "at91sam3s2-9x/at91sam3s2-9x.tcl"

Next unzip the attached file to create a new sub-directory "at91sam3s2-9x" containing 5 files including applet-serialflash-atsam3s2.bin

Now, when you plug the ersky9x board in and run Sam-ba, select at91sam3s2-9x as the board. You should now get an extra tab labelled SerialFlash. Select this, then execute the enable_serial_flash script. Now you should be able to read and write the external SPI flash device from Sam-ba.
Note: The erase chip script is not yet implemented.

I'll post the source of the applet sometime, had to write my own almost completely.

Updated zip file (2nd time) with bug fixed 13/3/2012
at91sam3s2-9x.zip
(8.3 KiB) Downloaded 741 times

Mike.

Re: ERSKY9X Coding

Posted: Thu Feb 02, 2012 1:00 pm
by SkyNorth
Great work Mike, this is not easy stuff to figure out for the first time....

I think its really cool that you can talk to memory chip on the board , through the programmer interface.

Is there the same access to the I2C port through a applet?

Again , I really want to thank you for your outstanding effort.

-Brent

Re: ERSKY9X Coding

Posted: Thu Feb 02, 2012 1:37 pm
by MikeB
That's OK, it's quite interesting really. I haven't had as much time for it recently.

It should be possible to have an applet for the I2C, I think there is one that could be used as a starting position, used for an AT45 type device. I now have some idea how they are set up and work. In general applets are used to provide access to memory, so the operations available are read, write and erase typically.

Mike.

Re: ERSKY9X Coding

Posted: Wed Feb 22, 2012 11:48 pm
by prefabu
Can you recommend a path for learning about development with the Atmel ARM products? Did/would you use one of the Atmel evaluation boards (like the ATSAM3S-EK) as a learning tool? Thanks.

Re: ERSKY9X Coding

Posted: Thu Feb 23, 2012 12:30 am
by MikeB
Just got the prototype board from SkyNorth and went from there, all learning/debugging done on that.

Mike.

Re: ERSKY9X Coding

Posted: Sat Mar 03, 2012 7:04 pm
by MikeB
Been doing some more work on this, I reckon I've got DSM running on ersky9x, PXX to follow shortly. We have hardware assist for this - create the bit stream, then just tell the sync. serial port to send it using DMA, NO processor overhead !!. Just two interrupts, one when it is time to generate next bit stream, and one to kick it off.
As I don't have any DSM modules I'll need someone else to test if it does transmit properly.
I will be able to test the PXX when it is done though.
I should commit these changes to the ersky9x repository later tonight.

Mike.