Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hitech95 opened this issue Nov 18, 2019 · 10 comments
Closed

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

hitech95 opened this issue Nov 18, 2019 · 10 comments

Comments

@hitech95
Copy link

hitech95 commented Nov 18, 2019

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
Copy link

MCUdude commented Nov 18, 2019

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

@awatterott
Copy link

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
Copy link
Contributor

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
Copy link

awatterott commented May 3, 2020

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
Copy link

chaveiro commented May 3, 2020

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

@SpenceKonde
Copy link
Contributor

SpenceKonde commented May 3, 2020 via email

@chaveiro
Copy link

chaveiro commented May 3, 2020

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 ?

SpenceKonde added a commit to SpenceKonde/toolchain-avr that referenced this issue May 3, 2020
See info.txt in alsoneeded directory for more information on this.

These files need to replace the standard versions of them in order to
fix arduino#66, arduino#67, and an issue with eeprom_is_ready() in eeprom.h that
manifests on the newer parts. Unfortunately I'm not good enough at shell
scripting to make the build scripts slip these fixes in
facchinm pushed a commit to facchinm/toolchain-avr that referenced this issue May 26, 2020
See info.txt in alsoneeded directory for more information on this.

These files need to replace the standard versions of them in order to
fix arduino#66, arduino#67, and an issue with eeprom_is_ready() in eeprom.h that
manifests on the newer parts. Unfortunately I'm not good enough at shell
scripting to make the build scripts slip these fixes in
@hitech95
Copy link
Author

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
Copy link
Contributor

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

This issue should be closed.

@hitech95
Copy link
Author

Just tested, its working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants