HWA
Bare metal programming with style
ATmega16U4/32U4
Note
This needs to be rewritten.

Defined symbols

HWA defines the following symbols describing the target device and its hardware configuration:

Symbol Comments
HW_DEVICE The device name as passed to the compiler
HW_DEVICE_ATMEGAXU4 Defined void
HW_DEVICE_ATMEGA32U4_MU Defined void depending on the HWA header included
HW_DEVICE_PACKAGE_44Q Defined void
HW_DEVICE_RAM_START Address of first RAM byte (after registers and I/O regs)
HW_DEVICE_APP_START Address of first application byte (after IRQ vector table)
Symbol ATmega16U4 ATmega32U4
HW_DEVICE atmega32u4
HW_DEVICE_SIGNATURE 0x1E,0x95,0x87
HW_DEVICE_FLASH_SIZE 32768
HW_DEVICE_FLASH_PAGE_SIZE 128
HW_DEVICE_EEPROM_SIZE 1024
HW_DEVICE_EEPROM_PAGE_SIZE 4
HW_DEVICE_RAM_SIZE 2560
HW_DEVICE_RAM_START 0x0100
HW_DEVICE_APP_START 0x00AC

Configuration fuses

ATmegaXU4 devices hold 3 fuse bytes describing their hardware configuration. HWA computes the value of these fuse bytes from the fuse values (detailed in the following subsections) that must be defined prior to including the HWA header. Factory defaults (shown with a bold face) are used for values that are undefined as the HWA header is included.

Symbol Comments
HW_DEVICE_FUSE_EB Fuse extended byte
HW_DEVICE_FUSE_HB Fuse high byte
HW_DEVICE_FUSE_LB Fuse low byte

Clocking

HWA uses these settings to compute the system clock frequency syshz.

Symbol Valid values Comments
HW_DEVICE_CLK_SRC external
rc_8MHz
low_freq_xosc
low_power_xosc
External source on pin CLKI
Internal RC calibrated oscillator
Crystal/resonator oscillator between pins XTAL1 and XTAL2
HW_DEVICE_CLK_SRC_HZ Positive integer Clock frequency for external and xosc clock source
HW_DEVICE_CLK_PSC 8
1
Clock divided by 8
Clock not divided

Startup delays

Symbol Valid values Comments
HW_DEVICE_STARTUP_DELAYS 4CK
4CK_4ms
4CK_64ms
6CK_14CK
6CK_14CK_4ms
6CK_14CK_64ms
1KCK_4ms
1KCK_64ms
32KCK_64ms
258CK_14CK_4ms
258CK_14CK_64ms
1KCK_14CK
1KCK_14CK_4ms
1KCK_14CK_64ms
16KCK_14CK
16KCK_14CK_4ms
16KCK_14CK_64ms
Valid values depend on the clocking configuration

Other fuses

Symbol Valid values Comments
HW_DEVICE_PIN_HWB enabled
disabled
Whether the HWB pin allows to execute the bootloader section after reset when tied to ground during external reset pulse.
HW_DEVICE_BROWNOUT_DETECTION off
1800_2200mV
2000_2400mV
2200_2600mV
2400_2800mV
3200_3600mV
3300_3700mV
4000_4500mV
Brown-out detection level
HW_DEVICE_ON_CHIP_DEBUG enabled
disabled
Whether on-chip debugging is enabled
HW_DEVICE_JTAG enabled
disabled
Whether the JTAG interface is enabled
HW_DEVICE_SERIAL_PROGRAMMING enabled
disabled
Whether the device can be programmed via the SPI
HW_DEVICE_WATCHDOG_ALWAYS_ON yes
no
Whether the watchdog is always running
HW_DEVICE_PRESERVE_EEPROM_THROUGH_CHIP_ERASE enabled
disabled
Whether the EEPROM memory is erased when a chip erase occurs
HW_DEVICE_BOOT application
bootloader
Whether the device starts the application or the bootloader after reset
HW_DEVICE_BOOTSECTION_SIZE 512
1024
2048
4096
Size of the boot section
HW_DEVICE_CLOCK_OUTPUT enabled
disabled
Whether the device outputs its clock

Peripherals

Note A missing class name means that the peripheral is not implemented yet.

Object name Class Comments
core0 _corec The core
watchdog0 _wdb Watchdog (WDG)
portb _gpa General purpose I/O port B (PORTB)
portc _gpa General purpose I/O port C (PORTC)
portd _gpa General purpose I/O port D (PORTD)
porte _gpa General purpose I/O port D (PORTE)
portf _gpa General purpose I/O port D (PORTF)
int0 _inta External interrupt INT0
int1 _inta External interrupt INT1
int2 _inta External interrupt INT2
int3 _inta External interrupt INT3
int6 _inta External interrupt INT6
pcic0 _pxa Pin change interrupt controller
prescaler0 _psa counter0/1/3 prescaler (PSC0)
counter0 _cta 8-bit counter-timer (T0)
counter0compare0 _oca Compare unit 0 of counter0 (OC0A)
counter0compare1 _oca Compare unit 1 of counter0 (OC0B)
counter1 _cte 16-bit counter-timer (T1)
counter1compare0 _occ Compare unit 0 of counter1 (OC1A)
counter1compare1 _occ Compare unit 1 of counter1 (OC1B)
counter1compare2 _occ Compare unit 2 of counter1 (OC1C)
counter1capture0 _ica Capture unit of counter1 (ICP1)
counter3 _cte 16-bit counter-timer (T1)
counter3compare0 _occ Compare unit 0 of counter3 (OC3A)
counter3compare1 _occ Compare unit 1 of counter3 (OC3B)
counter3compare2 _occ Compare unit 2 of counter3 (OC3C)
counter3capture0 _ica Capture unit of counter3 (ICP3)
acmp0 _aca Analog Comparator
eeprom0 _eea Eeprom memory
flash0 _fla Flash memory

Interrupts

Interrupt definition Atmel label Comments
watchdog0 WDT Watchdog Time-out Interrupt
eeprom0 EE READY EEPROM ready
eeprom0,ready EE READY EEPROM ready
flash0 SPM READY Store Program Memory Ready

I/O ports and pins

HWA name 44Q Class Atmel name
port_b _ioa PORTB
(portb,0) pin_8 _ioa PB0
(portb,1) pin_9 _ioa PB1
(portb,2) pin_10 _ioa PB2
(portb,3) pin_11 _ioa PB3
(portb,4) pin_28 _ioa PB4
(portb,5) pin_29 _ioa PB5
(portb,6) pin_30 _ioa PB6
(portb,7) pin_12 _ioa PB7
port_c _ioa PORTC
(portc,6) pin_31 _ioa PC6
(portc,7) pin_32 _ioa PC7
port_d _ioa PORTD
(portd,0) pin_18 _ioa PD0
(portd,1) pin_19 _ioa PD1
(portd,2) pin_20 _ioa PD2
(portd,3) pin_21 _ioa PD3
(portd,4) pin_25 _ioa PD4
(portd,5) pin_22 _ioa PD5
(portd,6) pin_26 _ioa PD6
(portd,7) pin_27 _ioa PD7
port_e _ioa PORTE
pe2 pin_33 _ioa PE2
pe6 pin_1 _ioa PE6
port_f _ioa PORTF
pf0 pin_41 _ioa PF0
pf1 pin_40 _ioa PF1
pf4 pin_39 _ioa PF4
pf5 pin_38 _ioa PF5
pf6 pin_37 _ioa PF6
pf7 pin_36 _ioa PF7