Skip to content

cpu/atmega32u4: Fixed external interrupts; boards/arduino-leonardo: Fixed dependency tracking#11927

Merged
miri64 merged 2 commits intoRIOT-OS:masterfrom
maribu:arduino-leonardo
Aug 29, 2019
Merged

cpu/atmega32u4: Fixed external interrupts; boards/arduino-leonardo: Fixed dependency tracking#11927
miri64 merged 2 commits intoRIOT-OS:masterfrom
maribu:arduino-leonardo

Conversation

@maribu
Copy link
Member

@maribu maribu commented Jul 26, 2019

Contribution description

  • Removes incorrect entry for external interrupt on non-existing pin PE7 for MCU ATmega32U4
  • Adds missing Makefile.dep to Arduino Leonardo board

Testing procedure

Issues/PRs references

Found bug while testing #11923

maribu added 2 commits July 26, 2019 17:22
Currently the configuration claims that external interrupt INT4 is present on
pin PE7. However, the ATmega32U4 datasheet (section 10.3.4 page 81) contains
the following remark to pin PE7: "Not present on pin-out". This commit removes
the PE7 from the interrupt config.
Somehow Makefile.dep was missing on the Arduino Leonardo. This commit adds it.
@maribu maribu added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Platform: AVR Platform: This PR/issue effects AVR-based platforms Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports labels Jul 26, 2019
@maribu maribu requested a review from miri64 July 26, 2019 15:33
@maribu
Copy link
Member Author

maribu commented Jul 26, 2019

@miri64: Mind to review? (I know, not your field of interest. But you have a board and this PR is quite small ;-))

@miri64
Copy link
Member

miri64 commented Jul 26, 2019

I'll have a look next week. My leonardo is at the office. If I don't come back to this on Monday, please feel free to remind me ;-).

@miri64
Copy link
Member

miri64 commented Jul 29, 2019

I'll have a look next week. My leonardo is at the office. If I don't come back to this on Monday, please feel free to remind me ;-).

Sorry, had no internet today in the office. In the meantime: a more descriptive PR title would be appreciated ;-)

@maribu maribu changed the title Arduino leonardo cpu/atmega32u4: Fixed external interrupts; boards/arduino-leonardo: Fixed dependency tracking Jul 29, 2019
@miri64 miri64 self-assigned this Jul 30, 2019
Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

I tried to test this and was able to flash and run hello world, however after that I was not able to flash anymore (/dev/ttyACM0 disappearing during flashing)… I'm not sure if it was this PR that effectively bricked it :-/. So I rather prefer someone else to have a look at this. I can confirm however, that PE7 is not exposed to the pinout (see datasheet, section 10.3.4)

@miri64 miri64 added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines labels Jul 30, 2019
@maribu
Copy link
Member Author

maribu commented Aug 2, 2019

however after that I was not able to flash anymore (/dev/ttyACM0 disappearing during flashing)…

Can you provide more details? Upon boot the bootloader of the Leonardo provides /dev/ttyACM0 for a bounded time (2 seconds if I remember correctly). Afterwards, the flashed firmware is loaded. In case of RIOT the USB devices than vanishes, as RIOT does not have support for USB on the ATmega32U4 yet. So if the re-build of the firmware during make flash takes too long, the time window the bootloader provides /dev/ttyACM0 might be too short for the build system to reach the point avrdude is started.

So the most reliable way to flash is using the following steps:

  1. Run make BOARD=arduino-leonardo
  2. Type make BOARD=arduino-lenoardo flash-only without hitting the enter key yet
  3. Press the reset button on the board
  4. Press the enter key to issue the flash only command

I'm not sure if it was this PR that effectively bricked it :-/

That is very unlikely. Only the bootloader in the AVR should be able to write to the flash, so unless some advanced hack to work around this protection is used, RIOT (or any other firmware flashed via the bootloader) will not be able to brick the device.

I heard that some people still had to rewrite the bootloader of an Arduino. The only plausible explanation to me is that a hard to trigger bug in the bootloader can cause it to overwrite/modify portions of itself.

@maribu
Copy link
Member Author

maribu commented Aug 19, 2019

@miri64: Time to give this another try?

If the Leonardo's bootloader was indeed somehow bricked, you can just flash it using an ISP or a second Arduino as ISP. But again: Bricking the bootloader is theoretically impossible from RIOT, only the bootloader itself has write access to the flash. But I cannot rule out that some bug in the bootloader was triggered somehow :-/

@miri64
Copy link
Member

miri64 commented Aug 28, 2019

Thanks, I'll try that!

@miri64
Copy link
Member

miri64 commented Aug 29, 2019

Ok, after burning the bootloader via an Arduino Uno as ISP, /dev/ttyACM0 does not disappear anymore after a few seconds (which was my problem) I will now test your PR :-)

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

Ok, I still get the error occasionally, but I am confident that this has nothing to do with your PR as I observe the same behavior with a freshly burned bootloader on master and get similar output when flashing a sketch with the Arduino IDE as well... I think my poor Leonardo is just on the last leg of its life :( (it's quite old and rusty):

BOARD=arduino-leonardo make -C tests/periph_timer/ flash-only
avrdude -c avr109 -p m32u4 -P /dev/ttyACM0 -F -D -U flash:w:/home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/bin/arduino-leonardo/tests_periph_timer.hex

Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
    Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
    Device code: 0x44

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9587 (probably m32u4)
avrdude: reading input file "/home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/bin/arduino-leonardo/tests_periph_timer.hex"
avrdude: input file /home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/bin/arduino-leonardo/tests_periph_timer.hex auto detected as Intel Hex
avrdude: writing flash (6760 bytes):

Writing | ################################################## | 100% 0.81s

avrdude: 6760 bytes of flash written
avrdude: verifying flash memory against /home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/bin/arduino-leonardo/tests_periph_timer.hex:
avrdude: load data flash data from input file /home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/bin/arduino-leonardo/tests_periph_timer.hex:
avrdude: input file /home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/bin/arduino-leonardo/tests_periph_timer.hex auto detected as Intel Hex
avrdude: input file /home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/bin/arduino-leonardo/tests_periph_timer.hex contains 6760 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.05s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x1800
         0xff != 0x0f
avrdude: verification error; content mismatch

avrdude: safemode: Verify error - unable to read lfuse properly. Programmer may not be reliable.
avrdude: safemode: Sorry, reading back fuses was unreliable. I have given up and exited programming mode
avrdude: error: programmer did not respond to command: leave prog mode

and after that I get mostly this

make: Entering directory '/home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer'
avrdude -c avr109 -p m32u4 -P /dev/ttyACM0 -F -D -U flash:w:/home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/bin/arduino-leonardo/tests_periph_timer.hex

Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
    Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
    Device code: 0x44

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9587 (probably m32u4)
avrdude: reading input file "/home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/bin/arduino-leonardo/tests_periph_timer.hex"
avrdude: input file /home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/bin/arduino-leonardo/tests_periph_timer.hex auto detected as Intel Hex
avrdude: writing flash (6760 bytes):

Writing | ##############################################     | 92% 0.46savrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: write block
Writing | ###############################################    | 94% 0.46s ***failed;  
 ***failed;  
 ***failed;  
[…]
 ***failed;  
avrdude: Error: butterfly programmer uses avr_write_page() but does not
provide a cmd() method.
 *** page 103 (addresses 0x19e8 - 0x1a67) failed to write

Writing | ################################################## | 100% 0.52s

avrdude: 6760 bytes of flash written
avrdude: verifying flash memory against /home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/bin/arduino-leonardo/tests_periph_timer.hex:
avrdude: load data flash data from input file /home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/bin/arduino-leonardo/tests_periph_timer.hex:
avrdude: input file /home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/bin/arduino-leonardo/tests_periph_timer.hex auto detected as Intel Hex
avrdude: input file /home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/bin/arduino-leonardo/tests_periph_timer.hex contains 6760 bytes
avrdude: reading on-chip flash data:

Reading |                                                    | 0% 0.00savrdude: error: programmer did not respond to command: set addr
Reading | #                                                  | 1% 0.00savrdude: error: programmer did not respond to command: set addr
Reading | ##                                                 | 3% 0.00savrdude: error: programmer did not respond to command: set addr
Reading | ###                                                | 5% 0.00savrdude: error: programmer did not respond to command: set addr
[…]
Reading | ################################################   | 96% 0.05savrdude: error: programmer did not respond to command: set addr
Reading | #################################################  | 98% 0.05savrdude: error: programmer did not respond to command: set addr
Reading | ################################################## | 100% 0.05s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x3f != 0x0c
avrdude: verification error; content mismatch

avrdude: safemode: hfuse changed! Was d8, and is now ff
Would you like this fuse to be changed back? [y/n] y
ding | ################################################   | 96% 0.05savrdude: error: programmer did not respond to command: set addr
Reading | #################################################  | 98% 0.05savrdude: error: programmer did not respond to command: set addr
Reading | ################################################## | 100% 0.05s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x3f != 0x0c
avrdude: verification error; content mismatch

avrdude: safemode: hfuse changed! Was d8, and is now ff
Would you like this fuse to be changed back? [y/n] y
^Cmake: *** [/home/mlenders/Repositories/RIOT-OS/RIOT/tests/periph_timer/../../Makefile.include:562: flash-only] Interrupt

However, I was able to confirm all the steps in your testing procedures. ACK.

@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Aug 29, 2019
@miri64 miri64 merged commit b83c7dd into RIOT-OS:master Aug 29, 2019
@maribu
Copy link
Member Author

maribu commented Aug 29, 2019

Thanks for review!

@maribu maribu deleted the arduino-leonardo branch August 29, 2019 10:41
@kb2ma kb2ma added this to the Release 2019.10 milestone Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: boards Area: Board ports Area: cpu Area: CPU/MCU 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 Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants