-
Notifications
You must be signed in to change notification settings - Fork 2k
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
cpu/atmega*: factorise common code into atmega_common #9866
Conversation
d981050
to
6e93286
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running tests/{od,shell,thread_basic,thread_flood,xtimer_usleep} is successful.
But tests/xtimer_hang hangs (nomen est omen) before boot message. Crosschecked with master, which is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things below. I haven't tested yet, but it is next on my todo list.
Thumps up for generalizing code for all platforms. |
@kaspar030 murdock seems frozen... |
047e25f
to
b399f3f
Compare
@kYc0o , in your list of boards I dedicated myself to test the arduino-duemilanove. ;-) |
@kYc0o run this tests on jiminy with expected behaviour.
|
After checking out your last changes I get compile errors for some tests. I only tried tests/xtimer_*. https://gist.github.com/A-Paul/62c3838be10840386451d5a57b655824#file-gistfile1-txt This happened to me with arduino-uno and arduino-duemilanove. |
Thanks @Josar, can you tick your board?
Yes that's normal since #9781, which added linker scripts for AVR platforms, so now they will fail if the memory doesn't fit. Maybe this PR is increasing the size for the given tests? Anyways Murdock should have complained about it, and it doesn't. |
Overlooked the errors on Murdock, it does appear there. I'll check why there's a huge memory increase by this PR. |
Well I found the reason, which is basically that having a common My 2c is that I blacklist these platforms from this tests since running tests with less than 256B of memory left may lead to errors. Any opinions? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test results on mega-xplained:
shell still reboot loops!
xtimer_hang fail (misses more than 10%)
thread_basic pass
thread_flood pass
thread_race pass
xtimer_periodic_wakeup pass
xtimer_remove pass
xtimer_reset pass
xtimer_usleep pass
xtimer_usleep_short pass
cpu/atmega_common/cpu.c
Outdated
ISR(BADISR_vect){ | ||
|
||
ISR(BADISR_vect) | ||
{ | ||
_reset_cause(); | ||
|
||
printf_P(PSTR("FATAL ERROR: BADISR_vect called, unprocessed Interrupt.\n" | ||
"STOP Execution.\n")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message could probably be a core_panic
with reason PANIC_DUMMY_HANDLER
.
It would need to go where the while (1) {}
is, because a panic halts the system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll modify that part and make the corresponding tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking, is there an easy way to trigger this? So we can make a proper test.
I think that blacklisting the ATmega328P is fine because it is already known that ATmega has problems with the stack size being too small. ATmega328P is pretty limited compared to the typical RIOT MCU, and we probably don't want to keep the more capable systems broken in order to accommodate it. I think a more comprehensive change to how stack sizes are determined is needed to properly support the ATmega328P. |
@ZetaR60, I checked tests/shell with this PR on an arduino-duemilanove and arduino-mega2560. This effect seems to be fairly common. Just an example: |
There is some 'magic' for handling constant data and strings to lower ram usage. |
I can not push to your repo so i will post it here. cpu.c
board.h (jiminy)
|
@kYc0o this patch is only tested for the atmega256rfr2. The other part has to be tested and verified. |
@Josar yes sure, I'll make tests on the platforms I have. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple minor suggestions, otherwise it looks good!
Thanks for your work on this kYc0o!
cpu/atmega_common/cpu.c
Outdated
/* save the reset flags */ | ||
#if defined(__AVR_ATmega8515__) || defined(__AVR_ATmega8535__) || \ | ||
defined(__AVR_ATmega16__) || defined(__AVR_ATmega162__) || \ | ||
defined (__AVR_ATmega128__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this amounts to "the system has an MCUCSR register", then this complex ifdef can be changed to #ifdef MCUCSR
.
I wrote a quick test case to generate a BADISR. It is pretty tightly linked to this PR so you might want to add it here, but I can create a separate PR if you want. (Sorry for the blocks of code; we need hide-able sections in comments). tests/atmega_badisr/main.c /*
* Copyright (C) 2018 Acutam Automation, LLC
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief Test for ATmega BADISR handling
*
* @author Matthew Blue <[email protected]>
*
* @}
*/
#include <avr/io.h>
#include <stdio.h>
int main(void)
{
puts("ATmega BADISR test routine");
/* Initialize timer 0 */
TCCR0A = 0;
TCCR0B = 0;
TCNT0 = 0;
/* Enable overflow interrupt without defining ISR */
#ifdef TOIE0
TIMSK0 = (1 << TOIE0);
#else
TIMSK0 = (1 << TOIE);
#endif
/* Clear interrupt flags (oddly, by writing a 1) */
#ifdef TOV0
TIFR0 = (1 << TOV0);
#else
TIFR0 = (1 << TOV);
#endif
/* Start the clock (will BADISR at overflow) */
TCCR0B = (1 << CS00);
/* Wait for BADISR */
while (1) {}
return 0;
} tests/atmega_badisr/Makefile include ../Makefile.tests_common
BOARD_WHITELIST += arduino-duemilanove \
arduino-mega2560 \
arduino-uno \
jiminy-mega256rfr2 \
mega-xplained \
waspmote-pro
TEST_ON_CI_WHITELIST += arduino-duemilanove \
arduino-mega2560 \
arduino-uno \
jiminy-mega256rfr2 \
mega-xplained \
waspmote-pro
include $(RIOTBASE)/Makefile.include tests/atmega_badisr/tests/01-run.py #!/usr/bin/env python3
# Copyright (C) 2018 Acutam Automation, LLC
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect_exact("ATmega BADISR test routine")
child.expect_exact("*** RIOT kernel panic:")
child.expect_exact("*** halted.")
if __name__ == "__main__":
sys.exit(run(testfunc)) Note that Makefile definitions for tests have changed since this PR was created. Without a rebase you will need to add this to the Makefile: test:
tests/01-run.py And here are the results I get on mega-xplained: user@lm:~/Desktop/RIOT/tests/atmega_badisr$ make BOARD=mega-xplained term
/home/user/Desktop/RIOT/makefiles/toolchain/gnu.inc.mk:18: objcopy not found. Hex file will not be created.
/bin/sh: 1: avr-ld: not found
/home/user/Desktop/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "9600"
No handlers could be found for logger "root"
2018-10-06 17:34:26,585 - INFO # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
2018-10-06 17:34:28,588 - INFO #
2018-10-06 17:34:28,659 - INFO # main(): This is RIOT! (Version: 2016.03-devel-9848-gb45d51-6807c15f4413-cpu/atmega/reuse_common)
2018-10-06 17:34:28,689 - INFO # ATmega BADISR test routine
2018-10-06 17:34:28,788 - INFO # *** RIOT kernel panic:
2018-10-06 17:34:28,789 - INFO #
2018-10-06 17:34:28,790 - INFO #
2018-10-06 17:34:28,791 - INFO # *** halted.
2018-10-06 17:34:28,792 - INFO #
2018-10-06 17:34:33,904 - INFO # Exiting Pyterm Note that the message for core_panic is not being printed. |
@ZetaR60 comments addressed. For your test, maybe you can push a PR based on this one, with the "waiting for PR" label set.
Maybe you need to activate I hope @Josar will have time soon to get this finally merged. Thanks @ZetaR60 for your testing and review! |
@PeterKietzmann can you perform a quick test on waspmote-pro? compiling and flashing tests/shell and perform |
@Josar could you run the tests on your platform? |
|
Great! so, @ZetaR60 you can ACK now. I'll take care of the overflowed tests to get Murdock pass. |
Double checked the tests before ACK:
|
d895a49
to
5bbe73a
Compare
Removes duplicated code for atmega platforms. They were all basically the same, only with the exception of atmegarfr2, for which there is an #if statement to use the code in the same file.
Removes redundancy of code since all the boards were defining the same variables. Moreover, the stack sizes are unified per architecture, as required.
cpu.c and startup.c were redundant in most platforms, except for atmega256rfr2. The common code is now in cpu/atmega_common/cpu.c and cpu/atmega_common/startup.c. cpu_conf.h is also removed as it's now in cpu/atmega_common/include thus shared by all atmega based platforms.
This adds a LED_PANIC macro which defines which LED, or combination of LEDs should notify a panic error. This is currently used to signal BADISR_vect errors.
The `atmega_set_prescaler` was using a "sensible" default but it's better to define it at the board level to make it clear.
5bbe73a
to
029af75
Compare
This variable helps to inform at boot time that some information about the booting process, e.g. reset cause.
029af75
to
65c531e
Compare
The unification of a bigger stack for the atmega platforms makes some boards to not have enough memory to provide the big stack plus the application code. It is possible though, to override the stack size to a smaller amount if running the test is necessary.
65c531e
to
dd3ca90
Compare
Merging. Thanks for the cleanup @kYc0o ! |
+215 -721! Nice one! |
Contribution description
This PR aims to take some commits from #9130 to ease the review.
In this PR I took code from atmega platforms and place it in atmega_common, since it was basically all the same.
Testing procedure
Please run at least one example/test for each of these platforms:
Issues/PRs references
#9130