ERSKY9X Coding

erskyTx runs on many radios and upgrade boards
ersky9x was a port of er9x for use on the sky9x board.
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

ERSKY9X Coding

Post 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.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

pmackenzie
Posts: 236
Joined: Tue Dec 27, 2011 11:19 pm
Country: -
Location: Don Mills, Ontario

Re: ERSKY9X Coding

Post 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
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: ERSKY9X Coding

Post 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.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
SkyNorth
Posts: 958
Joined: Tue Dec 27, 2011 11:40 am
Country: -
Location: Mansfield , Ontario

Re: ERSKY9X Coding

Post 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
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: ERSKY9X Coding

Post 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.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
erazz
9x Developer
Posts: 682
Joined: Tue Dec 27, 2011 6:25 pm
Country: -
Location: NJ-USA
Contact:

Re: ERSKY9X Coding

Post 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 :)
Z

BEWARE - WE ARE IN THE AIR!!!
What goes up... Should be controlled by a 9X!
User avatar
Rob Thomson
Site Admin
Posts: 4543
Joined: Tue Dec 27, 2011 11:34 am
Country: United Kingdom
Location: Albury, Guildford
Contact:

Re: ERSKY9X Coding

Post by Rob Thomson »

Wonderful. Just want I have been wanting :-)
Slope Soaring, FPV, and pretty much anything 'high tech'
...........if you think it should be in the wiki.. ask me for wiki access, then go add it!
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: ERSKY9X Coding

Post 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.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
Rob Thomson
Site Admin
Posts: 4543
Joined: Tue Dec 27, 2011 11:34 am
Country: United Kingdom
Location: Albury, Guildford
Contact:

Re: ERSKY9X Coding

Post 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
Slope Soaring, FPV, and pretty much anything 'high tech'
...........if you think it should be in the wiki.. ask me for wiki access, then go add it!
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: ERSKY9X Coding

Post by MikeB »

No just the command line svn, but the method may work anyway.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
Rob Thomson
Site Admin
Posts: 4543
Joined: Tue Dec 27, 2011 11:34 am
Country: United Kingdom
Location: Albury, Guildford
Contact:

Re: ERSKY9X Coding

Post by Rob Thomson »

You so need to use

http://tortoisesvn.tigris.org/

on windows :D

Much easier!
Slope Soaring, FPV, and pretty much anything 'high tech'
...........if you think it should be in the wiki.. ask me for wiki access, then go add it!
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: ERSKY9X Coding

Post 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.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
erazz
9x Developer
Posts: 682
Joined: Tue Dec 27, 2011 6:25 pm
Country: -
Location: NJ-USA
Contact:

Re: ERSKY9X Coding

Post 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 :)
Z

BEWARE - WE ARE IN THE AIR!!!
What goes up... Should be controlled by a 9X!
Rafit
Posts: 15
Joined: Sun Jan 08, 2012 8:25 pm
Country: -
Location: Poland
Contact:

Re: ERSKY9X Coding

Post by Rafit »

Which compiler / IDE are you using for coding ErSky9X?
Is there anything free which works on Windows?
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: ERSKY9X Coding

Post 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.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: ERSKY9X Coding

Post 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.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
Rob Thomson
Site Admin
Posts: 4543
Joined: Tue Dec 27, 2011 11:34 am
Country: United Kingdom
Location: Albury, Guildford
Contact:

ERSKY9X Coding

Post 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
Slope Soaring, FPV, and pretty much anything 'high tech'
...........if you think it should be in the wiki.. ask me for wiki access, then go add it!
SkyNorth
Posts: 958
Joined: Tue Dec 27, 2011 11:40 am
Country: -
Location: Mansfield , Ontario

Re: ERSKY9X Coding

Post 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
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: ERSKY9X Coding

Post 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.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
SkyNorth
Posts: 958
Joined: Tue Dec 27, 2011 11:40 am
Country: -
Location: Mansfield , Ontario

Re: ERSKY9X Coding

Post by SkyNorth »

He could also use his SmartieParts USB connector.
-Brent
User avatar
Rob Thomson
Site Admin
Posts: 4543
Joined: Tue Dec 27, 2011 11:34 am
Country: United Kingdom
Location: Albury, Guildford
Contact:

Re: ERSKY9X Coding

Post 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!
Slope Soaring, FPV, and pretty much anything 'high tech'
...........if you think it should be in the wiki.. ask me for wiki access, then go add it!
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: ERSKY9X Coding

Post 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.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: ERSKY9X Coding

Post 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.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: ERSKY9X Coding

Post 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.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Installing Serial Flash applet

Post 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 731 times

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
SkyNorth
Posts: 958
Joined: Tue Dec 27, 2011 11:40 am
Country: -
Location: Mansfield , Ontario

Re: ERSKY9X Coding

Post 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
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: ERSKY9X Coding

Post 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.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
prefabu
Posts: 3
Joined: Wed Feb 22, 2012 10:08 pm
Country: -

Re: ERSKY9X Coding

Post 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.
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: ERSKY9X Coding

Post by MikeB »

Just got the prototype board from SkyNorth and went from there, all learning/debugging done on that.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: ERSKY9X Coding

Post 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.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

Post Reply

Return to “erskyTx (was ersky9x)”