Skip to content

Conversation

@GlassOnTin
Copy link
Contributor

Summary

Adds support for ATtiny1634 microcontroller.

ATtiny1634 specifications:

  • 16KB Flash, 1KB SRAM, 256B EEPROM
  • 3 GPIO ports (A: 8 pins, B: 4 pins, C: 6 pins)
  • Timer0: 8-bit with PWM on OC0A (PC0), OC0B (PA5)
  • Timer1: 16-bit with PWM on OC1A (PB3), OC1B (PA6)
  • 12-channel 10-bit ADC with temperature sensor
  • Watchdog timer, PCINT on all 3 ports

Implementation notes:

  • ATtiny1634 has no WDCE bit, so watchdog is declared manually without using the AVR_WATCHDOG_DECLARE macro
  • All WGM modes for both timers are implemented including Fast PWM with OCRnA as TOP (mode 7 for Timer0, mode 15 for Timer1)
  • External clock pins for timers are supported

Testing:

  • Compiles successfully with simavr build system
  • Core is auto-detected and added to sim_core_config.h

Use case:

This MCU is used in flashlight firmware (Anduril) and having simavr support enables firmware development and testing without physical hardware.

ATtiny1634 specifications:
- 16KB Flash, 1KB SRAM, 256B EEPROM
- 3 GPIO ports (A: 8 pins, B: 4 pins, C: 6 pins)
- Timer0: 8-bit with PWM on OC0A (PC0), OC0B (PA5)
- Timer1: 16-bit with PWM on OC1A (PB3), OC1B (PA6)
- 12-channel 10-bit ADC with temperature sensor
- Watchdog timer, PCINT on all 3 ports

Note: ATtiny1634 has no WDCE bit so watchdog is declared
manually without the timed sequence requirement.
ATtiny1634 has 16KB flash, which requires the use of 4-byte JMP
instructions in the interrupt vector table (RJMP cannot reach the
full address space). This was causing the emulator to jump to wrong
addresses when servicing interrupts.

Also improved the interrupt stack overflow error message to include
the vector number for easier debugging.
GlassOnTin added a commit to GlassOnTin/anduril that referenced this pull request Dec 10, 2025
Adds a cycle-accurate AVR emulator test infrastructure using simavr
with ATtiny1634 support. Tests run actual compiled firmware hex files,
providing true integration testing of the firmware.

## Test Framework (sim/tests/)

- anduril-test.h/c: Test API with button simulation, PWM reading, timing
- Macros: TEST_BEGIN, TEST_PASS, TEST_FAIL, ASSERT
- Helpers: anduril_click(), anduril_multi_click(), anduril_get_pwm()

## Test Suites (18 tests total)

- test_basic_ui.c (8 tests): on/off, hold, turbo, lockout
- test_ramping.c (6 tests): ramp up/down, floor/ceiling, memory
- test_channel_modes.c (4 tests): 3C switching, persistence, cycling

## ATtiny1634 Core (sim/simavr-core/)

Custom simavr core for ATtiny1634 MCU used in Anduril flashlights:
- 16KB Flash, 1KB SRAM, 256B EEPROM
- Timer0 (8-bit), Timer1 (16-bit) with PWM
- GPIO ports A, B, C

## Makefile Targets

- make test: Run all 18 tests
- make test-basic/ramping/channel: Run individual suites
- make test-verbose: Debug output with button/interrupt traces

## Dependencies

Requires simavr with ATtiny1634 core support:
- Fork: https://github.com/GlassOnTin/simavr
- Upstream PR: buserror/simavr#568
GlassOnTin added a commit to GlassOnTin/anduril that referenced this pull request Dec 10, 2025
Adds a cycle-accurate AVR emulator test infrastructure using simavr
with ATtiny1634 support. Tests run actual compiled firmware hex files,
providing true integration testing of the firmware.

## Test Framework (sim/tests/)

- anduril-test.h/c: Test API with button simulation, PWM reading, timing
- Macros: TEST_BEGIN, TEST_PASS, TEST_FAIL, ASSERT
- Helpers: anduril_click(), anduril_multi_click(), anduril_get_pwm()

## Test Suites (18 tests total)

- test_basic_ui.c (8 tests): on/off, hold, turbo, lockout
- test_ramping.c (6 tests): ramp up/down, floor/ceiling, memory
- test_channel_modes.c (4 tests): 3C switching, persistence, cycling

## ATtiny1634 Core (sim/simavr-core/)

Custom simavr core for ATtiny1634 MCU used in Anduril flashlights:
- 16KB Flash, 1KB SRAM, 256B EEPROM
- Timer0 (8-bit), Timer1 (16-bit) with PWM
- GPIO ports A, B, C

## Makefile Targets

- make test: Run all 18 tests
- make test-basic/ramping/channel: Run individual suites
- make test-verbose: Debug output with button/interrupt traces

## Dependencies

Requires simavr with ATtiny1634 core support:
- Fork: https://github.com/GlassOnTin/simavr
- Upstream PR: buserror/simavr#568
GlassOnTin added a commit to GlassOnTin/anduril that referenced this pull request Dec 10, 2025
Adds a cycle-accurate AVR emulator test infrastructure using simavr
with ATtiny1634 support. Tests run actual compiled firmware hex files,
providing true integration testing of the firmware.

## Test Framework (sim/tests/)

- anduril-test.h/c: Test API with button simulation, PWM reading, timing
- Macros: TEST_BEGIN, TEST_PASS, TEST_FAIL, ASSERT
- Helpers: anduril_click(), anduril_multi_click(), anduril_get_pwm()

## Test Suites (18 tests total)

- test_basic_ui.c (8 tests): on/off, hold, turbo, lockout
- test_ramping.c (6 tests): ramp up/down, floor/ceiling, memory
- test_channel_modes.c (4 tests): 3C switching, persistence, cycling

## ATtiny1634 Core (sim/simavr-core/)

Custom simavr core for ATtiny1634 MCU used in Anduril flashlights:
- 16KB Flash, 1KB SRAM, 256B EEPROM
- Timer0 (8-bit), Timer1 (16-bit) with PWM
- GPIO ports A, B, C

## Makefile Targets

- make test: Run all 18 tests
- make test-basic/ramping/channel: Run individual suites
- make test-verbose: Debug output with button/interrupt traces

## Dependencies

Requires simavr with ATtiny1634 core support:
- Fork: https://github.com/GlassOnTin/simavr
- Upstream PR: buserror/simavr#568
@gatk555
Copy link
Collaborator

gatk555 commented Dec 13, 2025

Strange, 2 USARTS and a USI. Why did they do that? Is there something unusual about USARTs and AC that explains their omission?

@GlassOnTin
Copy link
Contributor Author

Yeah, the 1634 is a bit of an oddball with the dual USARTs packed into such a small footprint! To be honest, I omitted them (and the AC) purely due to scope. My primary use case is flashlight firmware (Anduril) which relies heavily on the Timers, PWM, and ADC, but doesn't use the serial interfaces. I preferred to submit a core that is tested and working for my needs rather than adding untested serial logic.

@gatk555 gatk555 merged commit c6343c1 into buserror:master Dec 14, 2025
9 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.

3 participants