Go Down

Topic: Adding Wiring board to Arduino IDE? (Read 7663 times) previous topic - next topic

letaage

After using an Ardunio Diecimila for a while with great success, I have now made a Wiring compatible board for my next design, basically so I can use the external bus feature of the ATmega128 and the larger program memory.

I have got my new board working from within the Wiring IDE, but I was wondering if anyone has got a Wiring board to work from within the Arduino IDE?

By this I mean all the wiring specific functionality working, such as all the I/O mapped as per Wiring definitions, and the 32kHz timer and the other on-board peripherals such as I2C and the second UART etc etc

Is this as simple as adding a "Wiring" entry to boards.txt, adding an appropriate bootloader for the ATmega128 under the "bootloader" folder?  

Or do I also need to add a "wiring" entry under the "cores" folder?  

Has anyone done this already and can they point me to instructions?

I've searched the forum for how to do this, but haven't had any luck finding instructions.

If not, has any thought been given to adding the Wiring board to the Arduino IDE or unifying the development environment?

I could just continue to use the Wiring IDE, but it doesn't easily allow you to change the serial baud rate for talking to sketches and it seems silly to have 2 copies of an almost identical development environment on my Mac (2x AVR GCC tool chains etc) at over 100MB each.  Also to me the Wiring community seems a little stagnant when compared to the Arduino community.

Anyone had any luck trying this? I'd be keen to hear if you had any success!


mellis

It should be possible along the lines you outline.  You'll need to add the boards.txt entry, and the Wiring core (in hardware/cores).  The bootloader file you only need to include if you want to be able to burn it from within the IDE.

Ramdough

Any progress?  

I wish someone would write a tutorial on how to port the code for different AVR's!  

msproul

Yes it is very simple, create a new entry in the boards.txt file like below

The MAIN thing you will noticed change is the word before the "." in each line. This must be unique. Also the NAME in the first line, what ever you want to call it.

Then change the rest of the parameters as needed for your new board. If you have a bunch of CORE files different, make a copy of the folder and put the new name in the last entry ...core=foldername.

Restart the Arduino environment and it should show up under the BOARDS menu.

Mark

##############################################################

myArduino.name=My Arduino

myArduino.upload.protocol=stk500
myArduino.upload.maximum_size=14336
myArduino.upload.speed=19200

myArduino.bootloader.low_fuses=0xff
myArduino.bootloader.high_fuses=0xdd
myArduino.bootloader.extended_fuses=0x00
myArduino.bootloader.path=atmega168
myArduino.bootloader.file=ATmegaBOOT_168_diecimila.hex
myArduino.bootloader.unlock_bits=0x3F
myArduino.bootloader.lock_bits=0x0F

myArduino.build.mcu=atmega168
myArduino.build.f_cpu=16000000L
myArduino.build.core=arduino

##############################################################

Ramdough

Hey Mark.... Thanks for the input.  

For an ATmega1280,  for  example, I would change your board data example to say...


##############################################################

myArduino.name=My Arduino

myArduino.upload.protocol=stk500
myArduino.upload.maximum_size=14336
myArduino.upload.speed=19200

myArduino.bootloader.low_fuses=0xff
myArduino.bootloader.high_fuses=0xdd
myArduino.bootloader.extended_fuses=0x00
myArduino.bootloader.path=atmega1280
myArduino.bootloader.file=ATmegaBOOT_1280.hex
myArduino.bootloader.unlock_bits=0x3F
myArduino.bootloader.lock_bits=0x0F

myArduino.build.mcu=atmega1280
myArduino.build.f_cpu=16000000L
myArduino.build.core=atmega1280_mod

##############################################################


Then I would need to Create a new Bootloader called ATmegaBOOT_1280.hex in a folder called atmega1280.  I would also need to write new core files to define the pins in folder atmega1280_mod.  Wouldn't the "myArduino.upload.maximum_size" also increase with a bigger chip?  

Thank you for your help,... I am a bit new to this.  

letaage

Urrm, I've talked the talk but not walked the walk yet... I've been too busy but I have a general idea about how to go about doing it.

One problem is that the Arduino and Wiring Core source files are different, they're all arranged slightly differently and the timer systems is different, eg Wiring uses the 32kHz oscillator in the ATmeag128 that the Arduino Atmega168 does not have. I've not had a chance to dig deeper than this, there may be more problems.

I think I have worked out a simple, albeit brute force, way around all the problems, at least in concept by copying the entre Wiring Core source folder over to  Arduino.  However this requires downloading the entire Wiring code base as they're not included with the basic install, only the object files are provided.  This should work, at least in concept, and I will get a chance to try it soon.

It would be nice if the Arduino IDE supported the Wiring board out of the box from a single code base... is that too much to ask for???

I'll post more when I get it going...

letaage

#6
Feb 09, 2009, 02:30 pm Last Edit: Feb 09, 2009, 02:33 pm by letaage Reason: 1
I've had some time on and off to work on porting Wiring board to the Arduino environment and I have a fair bit of it working:

- modified boards.txt
- Serial Boot loader working through the Arduino IDE including auto-reset
- Timers, delays
- Digital I/O
- Analogue Out
- Both Serial Ports

It was while porting the Arduino serial port code to work on the ATmega128 and also to support both serial ports as per Wiring that I discovered a couple of major differences.

1- The Wiring code is interrupt driven for both TX and RX while the Arduino code only has a RX interrupt, TX is polled.

2- The Wiring code uses circular buffers and pointer arithmetic using a buffer handler library while the Arduino code uses an array and index counters (which is kind of the same thing as pointers) but doesn't use the buffer handlers.

3- The Arduino code doesn't go to great lengths to protect variables that are read or written during an interrupt (eg rx_buffer_head, rx_buffer_tail and rx_buffer) from side effects when accessing them in the main loop from Serial. functions.

I think that 3 above could be a bug.  I have not looked into the avr-gcc compiler and AVR assembler to work out if there will be a problem when accessing integer variables (ie 2 bytes, eg rx_buffer_head) in the main loop and getting an interrupt in between reading the first byte and reading the second byte.  I'm not sure if the assembler handles this automatically, if it does not then this kind of event will cause problems, it will cause intermittent bugs that will be hard to track down.

I believe that sections of code in the main loop that read variables which are also changed in an interrupt service routine should always be protected from the interrupt for the duration of the read, otherwise you're asking for trouble... anyone have any other opinion on that?

Secondly (and this is really what I intended to post about here today) I am not sure if I should go the whole hog and port all the functionality of the Wiring code to the Arduino environment or not, for example the interrupt driven TX and buffer libraries.  Does anyone have an opinion on that?

Is it better to replicate the behaviour of Wiring generated code exactly or is it better for a Wiring board in the Arduino environment to behave more like a real Arduino instead?

The first option makes it easy for people to move existing code from the Wiring environment to the Arduino environment and not suffer any performance or behaviour differences, eg timing, polled serial TX overhead etc.

The second option makes the Wiring board behave more like Arduino, lends itself to more familiar behaviour for people using Arduino and a similar code base and might reduce confusion.

Right now the code I have ported is going down the second path but I am at a cross road as to which path to follow...

What do people think about these options?

Go Up