Skip to content

Add ATmega8 and fix some minor bugs with program-avr-spi applet #736

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

Merged

Conversation

turmoni
Copy link
Contributor

@turmoni turmoni commented Jan 23, 2025

There are two changes here:

  1. Adding the ATmega8 to the database of AVR microcontrollers. erase_time was chosen to match the other entry with an erase_time, since not having one seemed to lead to issues with verifying what had been written, and this one seems to work fine
  2. Fixing up the program-avr-spi applet so it doesn't give a traceback whenever you're doing something with an unidentified device

For an explanation of the second one, see the following output I got before adding the ATmega8:

% glasgow run program-avr-spi -V 5 --pin-reset 0 --pin-sck 1 --pin-cipo 2 --pin-copi 3 identify
I: g.device.hardware: device already has bitstream ID 57b5cdebb6d0d20034246a56c317b332
I: g.cli: running handler for applet 'program-avr-spi'
I: g.applet.program.avr.spi: port(s) A, B voltage set to 5.0 V
I: g.applet.program.avr.spi: device signature: 1e 93 07 (unknown)
Traceback (most recent call last):
  File "/home/dave/.local/bin/glasgow", line 8, in <module>
    sys.exit(run_main())
             ~~~~~~~~^^
  File "/home/dave/git/glasgow/software/glasgow/cli.py", line 942, in run_main
    exit(asyncio.new_event_loop().run_until_complete(main()))
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/usr/lib/python3.13/asyncio/base_events.py", line 720, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/home/dave/git/glasgow/software/glasgow/cli.py", line 710, in main
    return applet_task.result()
           ~~~~~~~~~~~~~~~~~~^^
  File "/home/dave/git/glasgow/software/glasgow/cli.py", line 659, in run_applet
    return await applet.interact(device, args, iface)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dave/git/glasgow/software/glasgow/applet/program/avr/__init__.py", line 259, in interact
    if device.erase_time is not None:
       ^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'erase_time'

This is actually the result of two different things that needed to be fixed:

  1. The code was attempting to use the device object before it checked to see if the device existed (so this change brings that further up)
  2. The code that checks for the existence of the device explicitly excludes checking when either called with no action or with the "identify" action, which means that you would still get this error even with 1 being fixed

I don't know if a simple return is what's wanted here, but I assume the point of the check was to not error out on an unidentified device because it's already done everything that's needed for the identify command

@turmoni turmoni requested a review from whitequark as a code owner January 23, 2025 22:01
@whitequark
Copy link
Member

Thanks. Could you please rebase/combine the commits so that you have the ones starting with database.microchip.avr and applet.program.avr as the only two in this PR? The idea here is that we keep the build tree free of merges which serve no value when viewing the history, and that every change is applied atomically (i.e. there is one commit per conceptual change).

Once this is done I will hit "merge". Thank you for your work once more!

turmoni added 2 commits March 16, 2025 00:28
…or unknown devices

The `identify` command would error out if it was talking to an unknown AVR. This
change additionally ensures that `programming_disable` is called before the
`interact` function finishes, which previously only happened on success.
@turmoni turmoni force-pushed the fix_avr_error_and_add_atmega8 branch from c26e307 to 8ccb56f Compare March 16, 2025 00:39
@turmoni
Copy link
Contributor Author

turmoni commented Mar 16, 2025

Thanks, I believe this is what I've now done.

@whitequark whitequark added this pull request to the merge queue Mar 16, 2025
@whitequark
Copy link
Member

Thanks!

Merged via the queue into GlasgowEmbedded:main with commit 8e055c8 Mar 16, 2025
20 checks passed
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

Successfully merging this pull request may close these issues.

2 participants