Wednesday, March 4, 2015

ATmega32M1 and ATmega64M1 support with the new Arduino IDE 1.6.0

Update 2-14-2016:  There has been some fixes around ports usage - see readme.txt for details.  SPI is now demonstrated to work, and have been making progress in a CAN library. 

There are now 3 different 'versions' of the support files to use with different generations of the Arduino IDE, including the latest 1.6.7 w/o warning.

=====================================================================
 March 4, 2015:
This morning I posted up new portings of the ATmega64M1 uC in several variations, as well as support for the ATmega32M1 uC - all enabled at the same time in the new Arduino IDE release 1.6.0

Look under the Arduino Libs resource tab above, and follow the links and readme for the Arduino 1.6.0 IDE.  In short, you will need to copy a subdirectory in its entirety to your local 'arduino' users folder, and you will still need to make some edits with the avrdude.cong file.  But once done, you will find new 'board types' available for the ATmega64M1 and ATmega32M1 uCs.   A couple of details on the optiboot  ports:

  1. The optiboot included has disabled any startup blinking of the LED - in case you happen to have Port 13 assigned to something other than an LED.
  2. Some details on the fuses I selected:
    • Brown-out is set at 2.7v (same as the Arduino UNO), so you should be able to operate at 3.3v (take care of max clock frequency allowed when operating at lower Vcc - hence the 8Mhz versions).
    • The fuses are also set to FORCE  both the A and B outputs of the PSC controllers to a known LOW state upon startup / reset.  (6 output ports:  PSCOUT0, 1 & 2 - both A & B).
    • The clock selected is one of:  16Mhz, or 8Mhz external xtal, or internal 8Mhz osc.


 For the 'core' support libraries, at this time I simply copied over the libs I modified in the v1.0.6 IDE port.  I noted there had been a bit of cleanup with some of the 1.6.0 libs, esp around the hardware serial functions - but it does appear that the existing libs still function w/o problems.  Going forward I will update the core lib functions as errors are found.

Refer to the graph at the end of this post for a mapping of the CPU pins to Arduino PORT names/numbers.  Do make sure to check the Arduino Libs resource tab above for any updates.

Versions enabled include:
  • ATmega32M1 - 16Mhz external xtal
  • ATmega32M1 -   8Mhz external xtal
  • ATmega32M1 -   8Mhz internal osc.
  • ATmega64M1 - 16Mhz external xtal
  • ATmega64M1 -   8Mhz external xtal
  • ATmega64M1 -   8Mhz internal osc.




Enhancements to pinMode() and analgoReag() - Differential inputs.

The ATmegaxxM1 line of CPUs have an extra feature to their analog inputs:  3 sets of adjustable gain differential inputs.  The core libraries have extended to recognize three new 'virtual' ports AD0, AD1, and AD2.  To use one simply uses the analogRead() as normal, but passing one of the virtual port names.  pinMode() has been extend to recognize the three virtual ports - with a slight change; when a differential port is passed to pinMode(), it is always assumed the mode will be INPUT - and the 2nd parameter then becomes the gain factor to be used.  Gain factors may be one of these:  GAIN5, GAIN10, GAIN20, GAIN40.   Here is a sample sketch showing their use:

   void setup() {
     pinMode(AD1, GAIN10);              // Differential input channel #1

                                        // With gain of 10x
     Serial.begin(9600); 
   }





   void loop() {
     int i;
 
     i = analogRead(AD1);            // Read differential channel#1
     Serial.println(i);              // Print its value out
     delay(1000);                    // Delay 1 second between reads
   }





New 'Virtual' ports:
  •   AD0  = Differential input of   D9 - D8
  •   AD1  = Differential input of   A4 - A3
  •   AD2  = Differential input of D10 - A6 
New gain parameters passed as 2nd value in pinMode():
  • GAIN5
  • GAIN10
  • GAIN20
  • GAIN40




A few notes on the 1.6.0 release of the Arduino IDE.  Overall I am very happy to see them include a newer version of the GCC compiler - with its direct support of both the ATmega32M1 and ATmega64M1 uC as well as a better optimizer resulting in perhaps a 5% code size reduction.  It does appear they have also optimized the workflow of the overall tool some - I noted a bit better response / less delays when doing various tasks.

However I am rather disappointing they did not upgrade some of the other tools - e.g. AVRDUDE and the OptiBoot code.  You will still need to manually edit avrdude.cong adding in the ATmega32M1 and ATmega64M1 IDes, but at least now you can have both at the same time.  And for Optiboot - they not only did not upgrade to the latest release, but they totally broke the toolsets needed to recompile optiboot under 1.6.0;  it is a mess, with the only option to use a down rev 1.0.x release for the toolset and add in the latest source of optiboot source.

This is what I did for the boot files needed in this porting.

A final note:  I have only TESTED this port using the ATmega64M1-16Mhz xtl, and 8Mhz Osc options; as that is the boards / CPUs I have at had.  As folks use this if you find any issues with the porting I did, please let me know.



Click for larger view.
(Be sure to retrieve latest version from Arduino Libs resource tab above.)


No comments:

Post a Comment