Skip to content
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

atmega: refactor cpu/board code and build/flash variables #9130

Merged
merged 6 commits into from
Feb 8, 2019

Conversation

kYc0o
Copy link
Contributor

@kYc0o kYc0o commented May 15, 2018

Contribution description

This PR proposes a refactor of the atmega based boards to match the code reuse done in other architectures. In summary:

  • Added atmega.inc.mk for toolchain variables
  • Added avrdude.inc.mk for flashing variables
  • Move cpu.c and startup.c to cpu/atmega_common
  • Share cpu_conf.h to unify the stack memory definitions
  • Cleanup all unnecessary code

I hope I factored out as much as possible, if you find something else that can be reused please let me know.

Issues/PRs references

Fixes #9001

@kYc0o kYc0o added Platform: AVR Platform: This PR/issue effects AVR-based platforms Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: arduino API Area: Arduino wrapper API Area: boards Area: Board ports labels May 15, 2018
@kYc0o kYc0o added this to the Release 2018.07 milestone May 15, 2018
@kYc0o kYc0o requested review from cladmi and bergzand May 15, 2018 00:59
@kYc0o
Copy link
Contributor Author

kYc0o commented May 15, 2018

@Josar I'm not sure if you included arduino-common because you really need it or just to import toolchain and flasher requirements. Can you confirm?

@bergzand
Copy link
Member

Thanks for picking this up @kYc0o. Is it possible to split this PR into 2 (or more) PR's? One with the makefile refactor and one with the cpu code refactor?

@@ -28,6 +33,17 @@
#define ENABLE_DEBUG (0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <avr/pgmspace.h>

#include "cpu.h"

missing new line?

@Josar
Copy link
Contributor

Josar commented May 15, 2018

@kYc0o if i remember it correctly it was requested to minimize code duplicates.
Maybe @shr70 can comment on this.
But i think you are right it is just for the toolchain and flasher.
This was still something which i was not very happy with as the jiminy is not related to arduino.

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 2 minor things

boards/common/arduino-atmega/Makefile.include Outdated Show resolved Hide resolved
cpu/atmega_common/Makefile.include Outdated Show resolved Hide resolved
@shr70
Copy link
Contributor

shr70 commented May 15, 2018

@kYc0o @Josar Yes, we only included the arduino-common due to the flasher and build commands. This was requested in the review.

@kYc0o kYc0o force-pushed the cpu/atmega/unify_stacks branch from fd5cc94 to 2720b68 Compare May 15, 2018 15:25
@kYc0o
Copy link
Contributor Author

kYc0o commented May 15, 2018

Update on this:

  • Solved murdock complaints about missing cpuid_get() on jiminy board
  • Removed dependency on arduino-atmega for jiminy board
  • Addressed comments of reviewers

@Josar or @shr70, can you test on jiminy if everything still works? Especially flashing.
@ZetaR60 Can you also test flashing on mega-xplained? I'm afraid I need to rewrite the flashing rules when not using a serial programmer.

@bergzand, I don't mind to decompose this PR in several, but if someone here can review it as is, it would be more practical.

@Josar
Copy link
Contributor

Josar commented May 15, 2018

@kYc0o flashing seems to work.

May i ask you to also change this depency to arduino?

include $(RIOTBOARD)/common/arduino-atmega/Makefile.features

I would suggest just add all FEATURES_PROVIDED to the jiminy Makefile.features. Or do i miss something which makes this a bad idea?

@kaspar030
Copy link
Contributor

+161 −791

I like!

@kYc0o
Copy link
Contributor Author

kYc0o commented May 15, 2018

Another update, and I think I'm triggering a more larger discussion.

Currently, atmega based boards are "forced" to import the CPU features from arduino-atmega/Makefile.features, which in my opinion doesn't make sense since 3 atmega based
boards are not arduinos, thus shouldn't have nothing to do with it.

I moved the features to cpu/atmega_common/Makefile.features where I thing they suit better, actually they are implemented in the same tree, which IMHO it's clear to understand why the features are defined there as well.

Finally, I left the arduino feature where I think it belongs, arduino-atmega/Makefile.features.

If nobody objects, I'd propose to start a "cleanup" in the future of these definitions, since currently every single board define features which are implemented at the cpu level.

Additionally, I removed the grouping needed previously by the CI, and if I'm not mistaken, Murdock doesn't need it anymore (@kaspar030 please correct me if I'm wrong).

Copy link
Contributor

@ZetaR60 ZetaR60 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the refactor! Did a proofread with some suggested changes, and also noted where behavior has changed.

This currently does not work on mega-xplained, due to problems with PROGRAMMER_SPEED.

boards/arduino-duemilanove/Makefile.include Show resolved Hide resolved
boards/mega-xplained/Makefile.include Show resolved Hide resolved
boards/mega-xplained/Makefile.include Show resolved Hide resolved
boards/waspmote-pro/Makefile.include Show resolved Hide resolved
makefiles/tools/avrdude.inc.mk Outdated Show resolved Hide resolved
cpu/atmega_common/cpu.c Outdated Show resolved Hide resolved
cpu/atmega256rfr2/include/cpu_conf.h Outdated Show resolved Hide resolved
cpu/atmega_common/include/cpu_conf.h Outdated Show resolved Hide resolved
cpu/atmega1281/startup.c Outdated Show resolved Hide resolved
cpu/atmega328p/startup.c Outdated Show resolved Hide resolved
@kaspar030
Copy link
Contributor

If nobody objects, I'd propose to start a "cleanup" in the future of these definitions, since currently every single board define features which are implemented at the cpu level.

Some features depend on cpu support and board configuration (periph_conf.h). That's why e.g., periph_uart is usually in a board's Makefile.features, even though the CPU provides the underlying implementation.

@kaspar030
Copy link
Contributor

I think @bergzand is right, this PR is getting very large. Difficult to spot problems.

@ZetaR60
Copy link
Contributor

ZetaR60 commented May 15, 2018

I'm not sure about moving Makefile.features entries to a common area. How do you handle, for instance, a board that has all of the ADC pins connected to LED outputs? That board would not provide ADC support, even though the CPU supports it.

EDIT: kaspar030 was just slightly faster than me on this comment. ;)

@kYc0o
Copy link
Contributor Author

kYc0o commented May 15, 2018

My logic behind the features is that they might be provided by the CPU, but might not be used by the board. I think it's manageable to make a difference between both and express it in the code. Actually, shouldn't my change break some compiles? I was experimenting with the change expecting Murdock to complain about it.

@kYc0o
Copy link
Contributor Author

kYc0o commented May 22, 2018

What's next then on this PR? Should I squash to try a split in different PRs? What about the features? Should they stay at the board level or at the CPU level?

@mali
Copy link
Contributor

mali commented May 23, 2018

tested with arduino Uno/Duemilanove boards 👍

@kYc0o
Copy link
Contributor Author

kYc0o commented May 23, 2018

@mali thanks for testing! Any thoughts about the overall cleanup?

@mali
Copy link
Contributor

mali commented May 23, 2018

@kYc0o I haven't looked in details, but looks cleaner and more logical in general and well ... +215 -843 :-) I've also noticed that some .hex are a little smaller than before, while others are little bigger, but we talk about an handful of bytes...

@kYc0o kYc0o force-pushed the cpu/atmega/unify_stacks branch 2 times, most recently from 511c742 to 02cfde4 Compare May 25, 2018 15:31
Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor (but blocking) issue ... otherwise looks good, tested with meg2560

endif

# the atmel port uses uart_stdio
USEMODULE += uart_stdio
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: this is actually named stdio_uart

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module was actually renamed in d55616a7f56ca17440 (so after this PR was opened) so not sure this really is a typo ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're both right, it's not a typo but it should be renamed. Thanks for spotting this!

I'll update asap.

@smlng
Copy link
Member

smlng commented Jan 7, 2019

to me this is good, please squash and rebase on latest master (had an issue which was solved in master while testing)

@smlng
Copy link
Member

smlng commented Jan 8, 2019

@ZetaR60 and @aabadie are we good to go here?

@miri64
Copy link
Member

miri64 commented Jan 8, 2019

I guess #7306 needs another rework if this is merged?

@smlng
Copy link
Member

smlng commented Jan 8, 2019

I guess #7306 needs another rework if this is merged?

might be, but rather minimal then - I think only boards/arduino-leonardo/Makefile.include would need some adaption, actually removing code (I think) ... but maybe @kYc0o can guide/help there

@kYc0o
Copy link
Contributor Author

kYc0o commented Jan 14, 2019

Ping @aabadie @ZetaR60

@kYc0o
Copy link
Contributor Author

kYc0o commented Jan 21, 2019

Weekly ping @aabadie @ZetaR60. I guess it didn't make it for the release?

@smlng
Copy link
Member

smlng commented Jan 22, 2019

please rebase

@ZetaR60
Copy link
Contributor

ZetaR60 commented Jan 23, 2019

Sorry for the delay. The issues from my review seem to be resolved. Once it is rebased I will test on mega-xplained and arduino-uno.

@maribu
Copy link
Member

maribu commented Feb 3, 2019

@kYc0o: ping

kYc0o added 6 commits February 5, 2019 17:12
Allows to use avrdude as a flashing tool in any context
(e.g. not dependent on arduino or atmega) though it only
works (AFAIK) on atmega, but I thought it's better to
have it here as we have other flashing tools.
Everything is now defined in atmega.inc.mk, following the common
RIOT-like reusability of rules and variables (e.g. cortexm.inc.mk).
Leverages common flasher (avrdude) and removes unnecessary exports.
Moreover, a reuse of serial.inc.mk is perfomed from the same
atmega_common/Makefile.include
Additionally, it removes unnecessary exports and cleans up
waspmote-pro toolchain variables (not needed) which are taken
from atmega_common.
Features must be provided by the board if they're actually
available on board. Other features might be provided by the
CPU.

Some grouping is also removed as it is not necessary.
@kYc0o kYc0o force-pushed the cpu/atmega/unify_stacks branch from c31f65f to 7139393 Compare February 5, 2019 16:17
@kYc0o
Copy link
Contributor Author

kYc0o commented Feb 5, 2019

Rebased.

@maribu
Copy link
Member

maribu commented Feb 5, 2019

@ZetaR60: ping

(Sorry for making all the fuzz. I waiting for this PR to get merged in order to move two existing PRs forward and create a third on. Normally I'm less annoying ;-))

@ZetaR60 ZetaR60 merged commit 1f9e185 into RIOT-OS:master Feb 8, 2019
@ZetaR60
Copy link
Contributor

ZetaR60 commented Feb 8, 2019

Final double-check on mega-xplained looks good. Thanks for the cleanup @kYc0o !

@kYc0o kYc0o deleted the cpu/atmega/unify_stacks branch February 10, 2019 22:38
@kYc0o
Copy link
Contributor Author

kYc0o commented Feb 10, 2019

Thanks everyone for your review! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: AVR Platform: This PR/issue effects AVR-based platforms Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

examples/gnrc_minimal: don't work anymore for atmega