arduino / toolchain-avr

The AVR toolchain used by the Arduino IDE
142 stars 48 forks source link

[328PB] Missing definitions in power.h #66

Closed hitech95 closed 3 years ago

hitech95 commented 4 years ago

I thought it was a problem of MiniCore but after some troubleshooting its not. #117

So far I have found that thoose functions are missing:

  power_spi_disable();
  power_twi_disable();
  power_adc_disable();

But I think that others might also missing. The same code compiled for the 168PB works fine.

I'm using Arduino 1.8.0 that is shipped with:

arduino.avrdude=6.3.0-arduino17
arduino.arduinoOTA=1.3.0
arduino.avr-gcc=7.3.0-atmel3.6.1-arduino5
MCUdude commented 4 years ago

Just for reference, power.h does not work with ATmega324PB either.

awatterott commented 4 years ago

The following things have to be changed in order to get the power functions working for m324PB and m328PB controller:

power.h add __AVR_ATmega324PB__ and __AVR_ATmega328PB__ defines

iom324pb.h and iom328pb.h PRSPI0 -> PRSPI PRTWI0-> PRTWI __AVR_HAVE_PRR0_PRSPI0 -> __AVR_HAVE_PRR0_PRSPI __AVR_HAVE_PRR0_PRTWI0 -> __AVR_HAVE_PRR0_PRTWI

SpenceKonde commented 4 years ago

Huh? That seems like a bad approach - that IS correctly defined in the io header - there are two SPI and TWI peripherals, and as far as I can tell they both get a bit in a PRR register to shut them down... So we should instead leave iom32*pb.h untouched, and add the following to power.h so that it can understand the real register names - and will provide the power management functions for the second SPI and TWI peripherals too

if defined(__AVR_HAVE_PRR0_PRSPI0)

define power_spi_enable() (PRR0 &= (uint8_t)~(1 << PRSPI0))

define power_spi_disable() (PRR0 |= (uint8_t)(1 << PRSPI0))

endif

if defined(__AVR_HAVE_PRR1_PRSPI1)

define power_spi1_enable() (PRR1 &= (uint8_t)~(1 << PRSPI1))

define power_spi1_disable() (PRR1 |= (uint8_t)(1 << PRSPI1))

endif

if defined(__AVR_HAVE_PRR2_PRSPI1)

define power_spi1_enable() (PRR2 &= (uint8_t)~(1 << PRSPI1))

define power_spi1_disable() (PRR2 |= (uint8_t)(1 << PRSPI1))

endif

if defined(__AVR_HAVE_PRR0_PRTWI0)

define power_twi_enable() (PRR0 &= (uint8_t)~(1 << PRTWI0))

define power_twi_disable() (PRR0 |= (uint8_t)(1 << PRTWI0))

endif

if defined(__AVR_HAVE_PRR1_PRTWI1)

define power_twi1_enable() (PRR1 &= (uint8_t)~(1 << PRTWI1))

define power_twi1_disable() (PRR1 |= (uint8_t)(1 << PRTWI1))

endif

if defined(__AVR_HAVE_PRR2_PRTWI1)

define power_twi1_enable() (PRR2 &= (uint8_t)~(1 << PRTWI1))

define power_twi1_disable() (PRR2 |= (uint8_t)(1 << PRTWI1))

endif

And as you said, add those parts to the list...

awatterott commented 4 years ago

Yes, that is also possible. I though to use the existing definitions from the other controllers, but you are right, because __AVR_HAVE_PRR1_PRSPI1 and __AVR_HAVE_PRR1_PRTWI1 are also missing in power.h.

chaveiro commented 4 years ago

@SpenceKonde some typos on that code but it's that the path.

SpenceKonde commented 4 years ago

Yeah, I was doing it in github off the top of my head shrug


Spence Konde Azzy’S Electronics

New products! Check them out at tindie.com/stores/DrAzzy GitHub: github.com/SpenceKonde ATTinyCore: Arduino support for almost every ATTiny microcontroller Contact: spencekonde@gmail.com

On Sun, May 3, 2020, 08:59 chaveiro notifications@github.com wrote:

@SpenceKonde https://github.com/SpenceKonde some typos that but it's that the path.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/arduino/toolchain-avr/issues/66#issuecomment-623106491, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTXEWZMIP4OMUIEFRITAMLRPVTEHANCNFSM4JOUN6KA .

chaveiro commented 4 years ago

Unfortunately i'm not sure where is the repository for hardware\tools\avr\avr\include\avr\power.h file. Is it part of AVR toolchain from Atmel (now Microchip) ?

https://github.com/arduino/toolchain-avr/ seems just a bunch of scripts that compiles the AVR Toolchain for arduino project, but no source for that file there. If the source comes from here: https://www.microchip.com/mplab/avr-support/avr-and-arm-toolchains-c-compilers

How to report a bug to Microchip ?

hitech95 commented 4 years ago

I've seen that some changes has been merged. Are those available to general public?

If not how can I test the new patches?

SpenceKonde commented 3 years ago

These fixes are in arduino7 version of toolchain, which is included by default on 1.8.13.

This issue should be closed.

hitech95 commented 3 years ago

Just tested, its working.