MightyCore - ATmega8535/16/32/164/324/644/1284

Proboscide99:
I checked the formulas on both bobuino pinout against 328P but didn't find the reason.

Is it a known problem?

Example: analogRead(4) does not work. analogRead(A4) does work.

I'm not sure what environment you are using as there seems to be several mighty cores floating around.
But for Jacks mighty core 1.6.3 I don't believe that analogRead(A4) on bobuino would work either not unless someone went and broke the analog code in yet another bad way to "fix" it for bobuino which will break all the other 1284 boards.

The problem goes back to the Arduino IDE core code and it goes back more than 4 years.
It cannot be solved by any fix in the variant file and it affects all variants other than "standard".
So all the other boards like SleepingBeauty, Bobuino, and avr_developers have analog pin mapping issues as well as any newly created variants.

Here is the reason.
The high level summary:
The code n wiring_analog.c in the function analogRead()
hard codes the analog pin to digital pin mapping as well as the analog pin number to analog channel number mapping.
This is an absolute no no!
It completely bypasses the pin mapping information in pins_arduino.h so there are guaranteed to be pin mapping problems.
This is a problem for nearly all the AVR boards, not just the 1284 based board.
It only shows up on the 1284 based boards because there is more then one pin mapping for the 1284 boards.

The code in analogRead() should be using the analogPinToChannel() macro to convert the pin value passed into analogRead() to the needed analog channel. Instead it has hardcoded the mapping in the code and it only works for the "standard" variant. (The older code from the mighy core use to use the macro correctly rather than hard code the mapping)
This needs to be fixed! and the solutions is very simple.
Use the macro in the pins_arduino.h file rather than hard code the pin mapping.
The define analogPinToChannel() was created for this very purpose.


Details:

It is a bit of wreck since the code and the documentation are very sloppy about what the "pin" parameter means.

The code in wiring_analog.c in the function analogRead() interprets the "pin" argument in multiple ways - as it can mean different things.
It can be a an analog pin/channel number or it can be a digital pin number that is assigned to an analog channel.

There is some confusion as to what the "analog pin #" argument really means.
For example if a value of say 0 is passed to analogRead() does that mean analog pin #0 or does it mean analog channel #0?
The two are not necessarily the same.
The Arduino documentation here:

sloppily uses the term "channel" in some places and "number of the analog input pin" in others.
When the mapping from analog pin # to analog channel # is one to one, it doesn't matter.
But there is no restriction to do so.

And the comments in the actual analogRead() code there are comments that say:
// allow for channel or pin numbers

which seems to imply that the argument is an actual channel number and not an analog pin #.
In fact the analogRead() code in the IDE AVR core treats the argument as an analog channel number and not an analog pin# whenever the value is a small number.

There was a somewhat heated discussion over this between me and jack over this a few years back when the mighty core was actually still shipping/including its own core code vs using the AVR core that comes with the IDE.

If you look at all the the other AVR based boards, and I mean ALL, from 328, 32u4 leonardo, they all map the analog pin # directly to the analog channels. EXCEPT..... bobuino which inverts them.
so on bobuino analog pin #0 is analog channel #7

To allow the variant to control not only the analog pin to analog channel mapping but to control the digital pin to analog pin mapping, there must be some way for the variant file to indicate this.

My suggestion (which one out) was to create a new macro analogPinToChannel() macro to do this mapping.
And... The somewhat controversial part was to assume that the argument passed into analogRead() was either a analog pin number or a digital pin number assigned to that analog pin number and not ever an analog channel number.
This is right thing to do since all boards other than bobuino, the analog pin # and the analog channel number are the same. If you make the agument a analog pin # rather than an analog channel # things get simpler and it can be mapped as needed - all while still being backward compatible with all existing code and documentation.
By using the analog pin mapping macro analogPinToChannel() it ensures that you can pass in:

  • naked analog pin numbers
  • A0 to A7 symbols
  • the appropriate digital pin number that is the same as the analog pin.

an through the analogPinToChannel() macro, the proper analog channel will always be selected since the variant file is control of the mapping vs having it hard coded in the analogRead() code.

So as of right now, all the 1284 variant files have an analogPinToChannel() macro in them and have for quite some time.
The problem is the analogRead() code doesn't use it.

The code in analogRead() right now is totally broken for the 1284 cores.
bobuino is the worst affected as there is no way to ever get the channel you want unless someone has gone in and created a hacked version that hard coded it for bobuino - which not the proper way to fix this.

With the other 1284 variants, since they map the analog pins one to one to the analog channels, they can use naked analog pin numbers and it will work.
However, the symbols A0 to A7 are used it will only work correctly on the "standard" core.
But it depends on which version of the mighty core you are using as some of them have bad hacks in them trying to fix the mapping issues-

As soon as the code in analogRead() is corrected to use the analogPinToChannel() macro rather than hard code the mapping, EVERYTHING will work correctly and as desired no matter what which pin # is passed in. (naked analog pin#, A0-A7, appropriate digital pin)

i.e. the analogRead() code needs to go back to using the analogPinToChannel() like it did in jacks 1.6.3 core.

It is a very simple fix.

The bad/broken code looks like this:
This is from the IDE AVR core:

#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
 if (pin >= 24) pin -= 24; // allow for channel or pin numbers

or this goofy hack from here:
https://github.com/MCUdude/MightyCore/blob/master/avr/cores/MightyCore/wiring_analog.c
That still hard codes things.

#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) \
|| defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) \
|| defined(__AVR_ATmega324__) || defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324PA__) \
|| defined(__AVR_ATmega32__) || defined(__AVR_ATmega32A__) || defined(__AVR_ATmega164__) \
|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega164PA__) || defined(__AVR_ATmega16__) \
 || defined(__AVR_ATmega16A__) || defined(__AVR_ATmega8535__)
 #if defined(BOBUINO_PINOUT)
 if (pin >= 14) pin = 7 - (pin-14);
 #elif defined(STANDARD_PINOUT) 
 if (pin >= 24) pin -= 24; 
 #endif

And the fixed/correct code should look like more like this:

(not exactly but it uses the macro in the variant file to do the mapping vs hard coding it)
This code goes back at least 4 years back to when the mighty core was shipping its own AVR core.

#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
 pin = analogPinToChannel(pin);

I guess somebody needs to create a pull request to the Arduino.cc IDE wiring_analog.c to fix it in the IDE code.

--- bill

Hi - I'm having an issue with the mapping of analog pins on a TQFP ATmega324A. Digital read/write pin numbers are correct, but, for example, digitalRead(24) correct is the same pin as analogRead(A6) or analogRead(30) incorrect. I burned the bootloader and am programming like the 'Arduino on a breadboard' example, using a spare UNO, Arduino as ISP(MightyCore). I'm using Arduino IDE 1.6.10 and the latest MightyCore.

Physical pin digitalRead(#) analogRead(#)
37 24 A6/30
36 25 A7/31
35 26 A0/24
34 27 A1/25
33 28 A2/26
32 29 A3/27
31 30 A4/28
30 31 A5/29

I tried it on a PDIP ATmega324P and it works perfectly but I need to use the smaller TQFP one.

Thanks!

There's no difference between the DIP and the TQFP version except the physical pinout of the chip. I don't have a TQFP variant lying around but there shouldn't be a difference. For the standard pinout (which I assume you use) the table looks like this:

DIP 40 PINOUT
Physical pin digitalRead(#) analogRead(#)
40/PA0 24 A0/24
39/PA1 25 A1/25
38/PA2 26 A2/26
37/PA3 27 A3/27
36/PA4 28 A4/28
35/PA5 29 A5/29
34/PA6 30 A6/30
33/PA7 31 A7/31

for the TQFP44 it looks like this
Physical pin digitalRead(#) analogRead(#)
37/PA0 24 A0/24
36/PA1 25 A1/25
35/PA2 26 A2/26
34/PA3 27 A3/27
33/PA4 28 A4/28
32/PA5 29 A5/29
31/PA6 30 A6/30
30/PA7 31 A7/31

bperrybap:
I'm not sure what environment you are using as there seems to be several mighty cores floating around.
But for Jacks mighty core 1.6.3 I don't believe that analogRead(A4) on bobuino would work either not unless someone went and broke the analog code in yet another bad way to "fix" it for bobuino which will break all the other 1284 boards.

Thanks a lot for your exhaustive explanation.

I can confirm that 'A4' works, I've found the "goofy hack" for the bobuino define in the 'wiring_analog.c' file (and this does not surprises, since the bobuino pinout is included in the core). I'm a little confused about the 'different version arund' matter, I downloaded the core from the master forks, the one that works on the 1.6.3 IDE (I'm currently using 1.6.5).

I should add that I'm not using the plain bobuino pinout but a modified version: the project I ported from the UNO (328P) works with two different LCD displays with different backlight pin placement and neither bobuino nor the standard pinout provided PWM-capable pins in the right place.

This pinout has the best possible pwm placement about UNO compatibility, the only non-pwm pin is D11, because I gave to the SPI placement higher priority (like many other pinouts for the 1284).

I attach the pinout in case someone is interested. The name is 'bobuloki' because it looks like a mix of Goldilock and Bobuino.

It matches PWM on all UNO's pins except for D11, miso/mosi/sck/ss match and the weird bobuino analog placement.

D3 and D4 are swapped (TXD1 no longer close to RXD1 but this is not important) to achieve PWM-capability on D3 (which is standard on the UNO).

If you think that the bobuino analog placement is too strange and requires extra computing effort (to avoid the hard-coded solution) I may revert back to straight assignment... but bobuino is natively supported by the core...

PWM:
D3, D5, D6, D9, D10 (matching UNO's standard)
D11 is standard on the UNO but not available here, for D11 is also the MOSI pin and this is more important.
D7, D12, D13 (extra pwm pins)

Thanks a lot!
Alessandro

pins_arduino.h (11.2 KB)

Example: analogRead(4) does not work. analogRead(A4) does work.

bperrybap is right, the wiring_analog.c file is a mess, and it shouldn't be like that. I've created an analogPinToChannel macro, and moved all the pin mapping specific stuff into the pins_arduino.h file, where it's supposed to be :slight_smile:

MightyCore ships with it's own core files, so fixing annoying issues like this is a quick job. Get the latest version (including this fix) at GitHub - MCUdude/MightyCore: Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535

hansibull:
bperrybap is right, the wiring_analog.c file is a mess, and it shouldn't be like that. I've created an analogPinToChannel macro, and moved all the pin mapping specific stuff into the pins_arduino.h file, where it's supposed to be :slight_smile:

MightyCore ships with it's own core files, so fixing annoying issues like this is a quick job. Get the latest version (including this fix) at GitHub - MCUdude/MightyCore: Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535

Thank you very much, I will check the new bobuino's pins_arduino.h against my modified version (bobuloki) in order to support the enhancement.

Btw, my version has better UNO's compatibility, do you think it would be useful to integrate it in the core?

Ciao!
Alessandro

hansibull:
bperrybap is right, the wiring_analog.c file is a mess, and it shouldn't be like that. I've created an analogPinToChannel macro, and moved all the pin mapping specific stuff into the pins_arduino.h file, where it's supposed to be :slight_smile:

MightyCore ships with it's own core files, so fixing annoying issues like this is a quick job. Get the latest version (including this fix) at GitHub - MCUdude/MightyCore: Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535

I'ts been a while since I've really looked at 1284 core support.

There seems to be multiple 1284 cores out there.
I don't know the history of this MCUdude core vs Jack's core and the relationship between them.

All of this was resolved and working in the 1.6.3 branch of jack's mighty core which is here:

This MCUdude code has definitely regressed in this area.
jack's variant files are here:

All the variant files in jack's core had proper analogPinToChannel macros - I created them and multiple thoroughly tested them.

The macro just created in the MCUdude core and added to the analogRead() code and to the variants is HORRIBLE, has problems and should be IMMEDIATELY removed and replaced!

A function like macro, particularly in a use case like that, should NEVER EVER EVER modify anything outside its scope. That macro is assuming a code implementation that includes assuming there is a variable named "pin" that exists outside its scope and it is attempting to modify it.
From a coding perspective, that is a VERY BAD thing to be doing and has the potential to cause problems down the road.

Also, the macro is wrong anyway. It won't work with naked analog pin numbers.
Just try to see what happens if you pass in a 0 or a 1
(I don’t' think it will even compile)

Here is the bobuino macro that was working from jack's mighty 1284 core:
(refer to jacks' repo for the actual files)

#define analogPinToChannel(p)       ((p) < NUM_ANALOG_INPUTS) ? (7 - (p)) : ((p)  >=  14 && (p) <= 21) ? (21 - (p)) : -1    //required

Note that it does not ever attempt to modify anything outside its scope or any other variable. It merely returns an rvalue that can be assigned to an lvalue. This ensures that it is self contained and works regardless of the lvalue variable name. i.e. it works just like a function.

The -1 default case should never happen unless a garbage pin # is passed, in which case the behavior is pretty much undefined. you could replace it with a say a 0 to ensure it at least returns a valid analog channel if you preferred but again, the behavior with garbage pin #s is undefined and could have unintended side effects.

and the code in analogRead() with a proper macro should be doing this for the 1284 cores:

pin = analogPinToChannel(pin);

as I showed earlier.

It assigns the analog channel value returned by the macro back to the pin variable as the lower code in that function expects the pin variable to contain the analog channel value.

Since the MCUdude 1284 core needs to fix its analogPinToChannel() macro to work with naked analog pin numbers anyway, it would be beneficial if it also used a proper macro that works just like the one in jack's core.

Jack's 1.6.3 1284 branch worked with the Arduino avr core without having to provide its own modified core files. That was it's intent and that is the direction that a 1284 core needs to be going.
A 1284 core should not need to be providing its own AVR core - the arduino.cc developers have bought into providing 1284 support to the AVR core so that is where it should be and they will be open to needed corrections/updates for it.
While there might be issues that crop up from time to time, that may need fixing for the 1284, it really should be handled in the arduino.cc IDE AVR core rather than have to ship a custom AVR core.

As of right now, (with jack's core) with the arduino.cc IDE supplied analogRead() there is the issue that the symbols A0 to A7 and the new PIN_A0 to PIN_A7 won't work with anything but the "standard" variant.
However, naked analog pin numbers will still work for all but bobuino.

That can easily be fixed by using a proper analogPinToChannel() macro in analogRead() rather than the current hard coded code.

I intend to have a discussion with the arduino.cc developers on the broader issue in analogRead() about the hard coding of pin mapping information.
Hopefully they will see the light and agree to add a new macro, analogPinToChannel() to all the variant files to fully resolve this once and for all.

Even if they won't go that far, I will see if they will allow it for the 1284 core.
If so, I will file a pull request for arduino.cc IDE wiring_analog.c to fix this for the 1284 core by using the analogPinToChannel() macro as defined in jack's core (which can work for all cores and all variants).

If the MCUdude 1284 corrects its analogPinToChannel() macro, it will be compatible with this update.

--- bill

bperrybap:
I'ts been a while since I've really looked at 1284 core support.

There seems to be multiple 1284 cores out there.
I don't know the history of this MCUdude core vs Jack's core and the relationship between them.

All of this was resolved and working in the 1.6.3 branch of jack's mighty core which is here:
GitHub - JChristensen/mighty-1284p at v1.6.3

Ok bperrybap, now I've understood what you meant. I was looking for different release numbers, while you were talking about several forks of the same thing.

It would be nice to understand how these version arose. If the JChristensen core is a fork of the maniacbug's one, then where the MCUdude's started from?

And afterall, what's the point in having several cores with the same goal?

Now I can answer your question, I'm using the MCUdude fork and this is why the naked pin number didn't work (at least in the previous version, I suppose). Unfortunately I won't have access to the hardware for a while so I'm unable to carry out any testing.

Thanks a lot and Regards!
Alessandro

Proboscide99:
Now I can answer your question, I'm using the MCUdude fork and this is why the naked pin number didn't work (at least in the previous version, I suppose). Unfortunately I won't have access to the hardware for a while so I'm unable to carry out any testing.

from the latest recent commits I saw in the MCUdude core, naked pin numbers is broken.
The recently added analogPinToChannel() macro is broken and will generate bad code that will not compile for any pin number less than or equal to 7 which includes naked analog pin numbers.

When fixing this, I'd also highly recommend fixing the macro to return an rvalue for the analog channel rather than trying to patch an out of scope variable inside inside the macro itself.

--- bill

from the latest recent commits I saw in the MCUdude core, naked pin numbers is broken.
The recently added analogPinToChannel() macro is broken and will generate bad code that will not compile for any pin number less than or equal to 7 which includes naked analog pin numbers.

When fixing this, I'd also highly recommend fixing the macro to return an rvalue for the analog channel rather than trying to patch an out of scope variable inside inside the macro itself.

I'll fix it. Still I don't see why this is such awful code. It compiles just fine, works with naked pin numbers and doesn't return any compiler warnings

EDIT: OK, i understand that using a macro like a function is much more elegant. I've modified the wiring_analog.c and the pins_arduino files, so everything should be OK now :wink:

bperrybap:
from the latest recent commits I saw in the MCUdude core, naked pin numbers is broken.

When fixing this, I'd also highly recommend fixing the macro to return an rvalue for the analog channel rather than trying to patch an out of scope variable inside inside the macro itself.
--- bill

I'd like to ask a couple of questions.

The first to hansibull:
I understand what bperrybap is saying about trying to change the content of the 'pin' variabie in the first parto of the macro, but then why in the right end you try to change the value of 'p' instead of the 'pin' variable?

#define analogPinToChannel(p) ((p) >= 14 ? (pin) = 7 - (pin-14) : ((p) <= 7 ? (p) = 7 - (p) : (p)))

I suppose that replacing the macro with the one from jack's core and adding 'pin = ' before the 'analogPinToChannel(pin)' in the wiring_analog.c would fix everything... am I right?

The second question is for bperrybap:
You said that with jack's core (and the IDE-supplied analogRead() function) the bobuino pinout would not work, but I don't understand why.

The macro is as follows:
#define analogPinToChannel(p) ((p) < NUM_ANALOG_INPUTS) ? (7 - (p)) : ((p) >= 14 && (p) <= 21) ? (21 - (p)) : -1

Since the analogRead() function uses the macro, it looks to me that naked numbers would work because the macro passes (7-p), successfully remapping AN0-7 to AN7-0. The subsequent code in the analogRead() function will not alter this value:

From the 1.6.5 IDE:
int analogRead(uint8_t pin)
{
uint8_t low, high;

#if defined(analogPinToChannel)
#if defined(AVR_ATmega32U4)
if (pin >= 18) pin -= 18; // allow for channel or pin numbers
#endif
pin = analogPinToChannel(pin);
#elif defined(AVR_ATmega1280) || defined(AVR_ATmega2560)
if (pin >= 54) pin -= 54; // allow for channel or pin numbers
#elif defined(AVR_ATmega32U4)
if (pin >= 18) pin -= 18; // allow for channel or pin numbers
#elif defined(AVR_ATmega1284) || defined(AVR_ATmega1284P) || defined(AVR_ATmega644) || defined(AVR_ATmega644A) || defined(AVR_ATmega644P) || defined(AVR_ATmega644PA)
if (pin >= 24) pin -= 24; // allow for channel or pin numbers
#else
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
#endif

Also, the A0-A7 notation is defined as numbers ranging from 14 to 21. Since the macro converts them back to numbers from 7 to 0, it looks like it should work as well.

What am I missing?

Thanks a lot and Regards!
Alessandro

Proboscide99:
And afterall, what's the point in having several cores with the same goal?

The point is that JChristensen/mighty-1284p is pretty much a dead project. I've put a lot of effort into trying to keep it current and it's always a struggle. JChristensen has obviously completely abandoned it for years now. Pico seems to be solely in charge of maintaining it and I'm grateful someone is still at the wheel but they're really not actively working on it. Pico doesn't even have the proper permissions to make 1.6.3 the default branch(#20). Compare that to how responsive hansibull/MCUdude has been. An issue was reported and within a matter of hours he's working on it. He has been very responsive to all the pull requests I've submitted and excellent about support when someone makes an issue report.

There is a serious licensing issue with Mighty 1284P and there always has been from the start, even when it was the maniacbug repository. I've been trying to get this resolved for close to a year now(#21, #19) with no response from JChistensen or maniacbug or any of the other people in charge of the project beyond just a "it should be fine" from pico. bperrybap was kind enough to look into this recently but still no response from anyone else or any clear indication of a roadmap for getting this resolved. That's not acceptable. I realize people have lives and sometimes have to abandon projects so they can focus on other responsibilities and that's fine but all the effort is wasted if you don't put a license on there so others can carry the flame onward. I'm not really interested in dedicating more effort to a dead project that's not even open source.

Of course the maniacbug repository is well and truly abandoned and has been for years. Mighty 1284P was an excellent project in its time but unfortunately that time has ended. Luckily we have a new project to take its place.

MightyCore is much more than Mighty 1284P ever was. ATmega1284P is only one of the parts this core supports which makes sense. Why should there be a separate project for each chip model when essentially the same code will support a whole chip family?

I do agree that including a copy of the Arduino core is not ideal. I understand why hansibull did it, in fact this analog pin issue demonstrates the benefits of having complete control of the core, but I'd much rather see these changes be merged into Arduino AVR Boards core. Not just the core but the library modifications as well. An ATmega1284P specific change to the Servo library was recently proposed on the developers mailing list. Massimo Banzi specifically requested that feilipu submit a pull request and it was merged within 4 days. Pretty responsive considering Arduino has never and probably will never make an ATmega1284P based board! Keeping an almost duplicate core and libraries updated is a lot of work, which hansibull has done an excellent job of, but if this project ever reaches a less frequently maintained state it will end up being a real liability.

hansibull:
I'll fix it. Still I don't see why this is such awful code.

The macro is passed a token "p" to operate on and yet sometimes operates on an out of scope variable named "pin" instead of using "p". Not only is this unnecessary, but it is VERY VERY bad.
It only works in very specific code implementations that happen to have a variable named "pin" that it also passes in to the macro.
The macro might as well have not taken an argument at all and just assumed the variable "pin" exists and used it for all the references inside the macro.

While that odd use of mixed parameters (passed in parameter p vs out of scope pin variable) may "work" in this specific case, it is very poor programming as it has created a very tight coupling between the macro and the code that uses it, that is for the most part hidden and makes the macro not really usable by other code.
For that type of implementation (where an rvalue is not returned) the macro should not have used "pin" but rather always used the parameter "p" so that the caller could pass in any variable name it wanted/needed and the macro would always work by modifying the token "p".

The point of creating an interface layer (in this case it uses a macro) is to provide isolation between the entity that needs the information and the entity that has and can provide the information.
The person creating an analogPinToChannel() macro/function should not need to see nor understand how the code that calls/uses it is written and likewise the person using analogPinToChannel() should not have to wonk up their code to use the macro based on the assumptions that the macro has made about the callers code.

The code is awful because it breaks that concept and permanently ties together the implementation of the function analogRead() with the implementation of the macro.
The macro seems to have assumed that analogPinToChannel() is nothing more than an extension of analogRead() which is not a good assumption.
What if a different piece of code wants/needs the same information?
Then that code must have a variable called "pin" that can be modified by this macro.
To ensure portability and a broad use case, the implementation of analogPinToChannel() must be independent of the the code that uses it such that there is no inherent knowledge being assumed between the caller of analogPinToChannel() and the actual implementation of analogPinToChannel()

Proboscide99:
The second question is for bperrybap:
You said that with jack's core (and the IDE-supplied analogRead() function) the bobuino pinout would not work, but I don't understand why.


What am I missing?

There are too many different cores being talked about....

I'm looking at from the perspective of Jack's 1284 code or a core that uses the arduino.cc IDE AVR core vs include its own and hence the analogRead() code that comes with IDE AVR code.
While the macro in bobuino variant file is correct and works correctly, the code in the IDE AVR core function analogRead() frunction does not use it and is hard coded to assume the "standard" variant pin mapping.
So when using a 1284 core that uses the IDE AVR core, if you pass in a raw analog pin number 0 to 7 analogRead() assumes that analog pins map one to one to an analog channel which is not the case for bobuino.

if the MCUdude includes its own AVR core code which has its own analogRead() that uses the macro, then it should be fine for all the 1284 variants supplied with the MCUdude core.

--- bill

pert:
The point is that JChristensen/mighty-1284p is pretty much a dead project.

I figured that was probably the case.
But it is trivial to create a fork on github and to continue on rather than try to update that repo .... :wink:
If that latest/best "fork" for 1284 support is now MCUdude, then great, we can all focus on this implementation.

There is a serious licensing issue with Mighty 1284P and there always has been from the start, even when it was the maniacbug repository. I've been trying to get this resolved for close to a year now(#21, #19) with no response from JChistensen or maniacbug or any of the other people in charge of the project beyond just a "it should be fine" from pico. bperrybap was kind enough to look into this recently but still no response from anyone else or any clear indication of a roadmap for getting this resolved. That's not acceptable. I realize people have lives and sometimes have to abandon projects so they can focus on other responsibilities and that's fine but all the effort is wasted if you don't put a license on there so others can carry the flame onward. I'm not really interested in dedicating more effort to a dead project that's not even open source.

From my perspective, from what I've seen so far, all the unknown licensed code portions are all LGPL 2.1+ regardless of who has worked on them and what their individual licensing views are since it all started with LGPL 2.1+ code. i.e. people can't make and release their modifications to LGPL 2.1+ code and have be anything but LGPL 2.1+ code.
I would set code in question to LGPL 2.1+ and blaze on.

I do agree that including a copy of the Arduino core is not ideal. I understand why hansibull did it, in fact this analog pin issue demonstrates the benefits of having complete control of the core, but I'd much rather see these changes be merged into Arduino AVR Boards core. Not just the core but the library modifications as well.

Me too.
Form what I've seen and your experience seems to reflect that as well, the arduino.cc deveopers are now open to updates to correct issues with 1284 code.

Keeping an almost duplicate core and libraries updated is a lot of work, which hansibull has done an excellent job of, but if this project ever reaches a less frequently maintained state it will end up being a real liability.

And that is what should be driving getting all this back into the arduino.cc AVR core and libraries.
I think getting the core updated should be step number 1 as I think that is going to be much easier and involve much fewer needed changes.

Beyond that, it would be great to see if we could cozy up to the arduino.cc developers enough to actually get the libraries updated with the 1284 changes.
There really aren't that many bundled libraries that need updates.

The key is to keep the changes minimal and use clean layering.
There are also some instances where it might be possible to get them to slightly change the way they are doing things by getting some additional information from the variant file instead of hard coding it for specific environments which can make some of these needed core or processor specific conditionals or changes just disappear.
In the long run those types of changes can help them in their maintenance so they may be very receptive to those types of changes.

This would be things like what is in analogRead().
For example, if all the variant files had a analogPinToChannel() macro, then there would be no need for ifdefs in that function.

--- bill

There seems to be multiple 1284 cores out there.
I don't know the history of this MCUdude core vs Jack's core and the relationship between them.

I didn't create this core because we needed another 1284 core. I created this because the current '644 core was outdated (we're talking Sanguino here!), And proper support for ATmega324, 164,32, 16 and 8535 didn't even exist.

MightyCore is not a fork of Jack's core, but a fork of the the core shipped with Arduino 1.6.5. A lot of changes needed to be done in order to make it work with the older ATmega32, 16 and 8535. There have been discovered a lot of bugs related to the core, and I think it's much easier to fix it "in house" rather than having to read a pull request, waiting for it to be added, and then waiting for a new IDE version to ship.

First of all, thank you guys for the effort put in this project.

This project (I assume MCUdude's is the "official" one) is really a good thing. Having arduino.cc integrating the changes needed to eliminate the custom core would be even better.

I will be able to download the patched version (and re-apply the changes to add my fabulous bobuloki pinout) :slight_smile: by the end of next week.

Have a nice time!

Ciao
Alessandro

hansibull:
There's no difference between the DIP and the TQFP version except the physical pinout of the chip. I don't have a TQFP variant lying around but there shouldn't be a difference. For the standard pinout (which I assume you use) the table looks like this:

DIP 40 PINOUT
Physical pin digitalRead(#) analogRead(#)
40/PA0 24 A0/24
39/PA1 25 A1/25
38/PA2 26 A2/26
37/PA3 27 A3/27
36/PA4 28 A4/28
35/PA5 29 A5/29
34/PA6 30 A6/30
33/PA7 31 A7/31

for the TQFP44 it looks like this
Physical pin digitalRead(#) analogRead(#)
37/PA0 24 A0/24
36/PA1 25 A1/25
35/PA2 26 A2/26
34/PA3 27 A3/27
33/PA4 28 A4/28
32/PA5 29 A5/29
31/PA6 30 A6/30
30/PA7 31 A7/31

Yeah, I can't find anything in the datasheet that is different between the two. It happens when analogRead() is the only thing in the sketch, and I can't find anything in the MightyCore code that would cause it. If I use only the analog pin number, however, it is correct. This is it (below)

Physical pin digitalRead(#) analogRead(#)
37/PA0 24 A6/30/0
36/PA1 25 A7/31/1
35/PA2 26 A0/24/2
34/PA3 27 A1/25/3
33/PA4 28 A2/26/4
32/PA5 29 A3/27/5
31/PA6 30 A4/28/6
30/PA7 31 A5/29/7

Are you using the boards manager or the manual install? I just fixed the analogRead() function, but I haven't created a new release yet. You can download the latest version and test it. using analogRead(0 - 7) will now work exactly as analogRead(A0 - A7) do.

hansibull:
Are you using the boards manager or the manual install? I just fixed the analogRead() function, but I haven't created a new release yet. You can download the latest version and test it. using analogRead(0 - 7) will now work exactly as analogRead(A0 - A7) do.

Works! Thanks for the help.

You're welcome! :slight_smile:

You guys should also test the new Wiring functionality I've added! I think the sleep functionality is really interesting. The Wiring functions includes:

  • portMode()
  • portRead()
  • portWrite()
  • sleepMode()
  • sleep()
  • noSleep()
  • enablePower()
  • disablepower()

Give it a spin! :smiley:

Downloaded the core, applied the changes to pins_arduino.h for my pinout.

It works.

Thanks!
Alessandro