mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-11 22:43:40 +00:00
avr: add attiny1616 support
This is just support for the chip, no boards are currently supported.
However, you can use this target on a custom board.
Notes:
- This required a new runtime and machine implementation, because the
hardware is actually very different (and much nicer than older
AVRs!).
- I had to update gen-device-avr to support this chip. This also
affects the generated output of other AVRs, but I checked all chips
we support and there shouldn't be any backwards incompatible
changes.
- I did not implement peripherals like UART, I2C, SPI, etc because I
don't need them. That is left to do in the future.
You can flash these chips with only a UART and a 1kOhm resistor, which
is really nice (no special hardware needed). Here is the program I've
used for this purpose: https://pypi.org/project/pymcuprog/
This commit is contained in:
committed by
Ron Evans
parent
4d11d552db
commit
2fb866ca86
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"inherits": ["avrtiny"],
|
||||
"cpu": "attiny1616",
|
||||
"build-tags": ["attiny1616"],
|
||||
"gc": "none",
|
||||
"cflags": [
|
||||
"-D__AVR_ARCH__=103"
|
||||
],
|
||||
"linkerscript": "src/device/avr/attiny1616.ld",
|
||||
"extra-files": [
|
||||
"src/device/avr/attiny1616.s"
|
||||
],
|
||||
"flash-command": "pymcuprog write -f {hex} --erase --verify -d attiny1616 -t uart -u {port}"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
; TODO: remove these in LLVM 15
|
||||
#define __tmp_reg__ r16
|
||||
#define __zero_reg__ r17
|
||||
|
||||
; Startup code
|
||||
.section .text.__vector_RESET
|
||||
.global __vector_RESET
|
||||
__vector_RESET:
|
||||
clr __zero_reg__ ; this register is expected to be 0 by the C calling convention
|
||||
|
||||
; Keep the stack pointer at the default location, which is RAMEND.
|
||||
|
||||
; Initialize .data section.
|
||||
.section .text.__do_copy_data,"ax",@progbits
|
||||
.global __do_copy_data
|
||||
__do_copy_data:
|
||||
ldi xl, lo8(__data_start)
|
||||
ldi xh, hi8(__data_start)
|
||||
ldi yl, lo8(__data_end)
|
||||
ldi yh, hi8(__data_end)
|
||||
ldi zl, lo8(__data_load_start)
|
||||
ldi zh, hi8(__data_load_start)
|
||||
1: ; loop
|
||||
cp xl, yl ; if x == y
|
||||
cpc xh, yh
|
||||
breq 2f ; goto end
|
||||
ld r16, Z+ ; r0 = *(z++)
|
||||
st X+, r16 ; *(x++) = r0
|
||||
rjmp 1b ; goto loop
|
||||
2: ; end
|
||||
|
||||
; Initialize .bss section.
|
||||
.section .text.__do_clear_bss,"ax",@progbits
|
||||
.global __do_clear_bss
|
||||
__do_clear_bss:
|
||||
ldi xl, lo8(__bss_start)
|
||||
ldi xh, hi8(__bss_start)
|
||||
ldi yl, lo8(__bss_end)
|
||||
1: ; loop
|
||||
cp xl, yl ; if x == y
|
||||
breq 2f ; goto end
|
||||
st X+, __zero_reg__ ; *(x++) = 0
|
||||
rjmp 1b ; goto loop
|
||||
2: ; end
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"llvm-target": "avr",
|
||||
"build-tags": ["avr", "avrtiny", "baremetal", "linux", "arm"],
|
||||
"goos": "linux",
|
||||
"goarch": "arm",
|
||||
"gc": "conservative",
|
||||
"linker": "ld.lld",
|
||||
"scheduler": "none",
|
||||
"rtlib": "compiler-rt",
|
||||
"libc": "picolibc",
|
||||
"default-stack-size": 256,
|
||||
"cflags": [
|
||||
"-Werror"
|
||||
],
|
||||
"ldflags": [
|
||||
"-T", "targets/avrtiny.ld",
|
||||
"--gc-sections"
|
||||
],
|
||||
"extra-files": [
|
||||
"src/internal/task/task_stack_avr.S",
|
||||
"src/runtime/asm_avr.S",
|
||||
"targets/avrtiny.S"
|
||||
],
|
||||
"gdb": ["avr-gdb"]
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/* Linker script for AVRs with a unified flash and RAM address space. This
|
||||
* includes the ATtiny10 and the ATtiny1616.
|
||||
*/
|
||||
|
||||
MEMORY
|
||||
{
|
||||
FLASH_TEXT (x) : ORIGIN = 0, LENGTH = __flash_size
|
||||
FLASH_DATA (r) : ORIGIN = __mapped_flash_start, LENGTH = __flash_size
|
||||
RAM (xrw) : ORIGIN = __ram_start, LENGTH = __ram_size
|
||||
}
|
||||
|
||||
ENTRY(main)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
KEEP(*(.vectors))
|
||||
*(.text.__vector_RESET)
|
||||
KEEP(*(.text.__do_copy_data)) /* TODO: only use when __do_copy_data is requested */
|
||||
KEEP(*(.text.__do_clear_bss))
|
||||
KEEP(*(.text.main)) /* main must follow the reset handler */
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
} > FLASH_TEXT
|
||||
|
||||
/* Read-only data is stored in flash, but is read from an offset (0x4000 or
|
||||
* 0x8000 depending on the chip). This requires some weird math to get it in
|
||||
* the right place.
|
||||
*/
|
||||
.rodata ORIGIN(FLASH_DATA) + ADDR(.text) + SIZEOF(.text):
|
||||
{
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
} AT>FLASH_TEXT
|
||||
|
||||
/* The address to which the data section should be copied by the startup
|
||||
* code.
|
||||
*/
|
||||
__data_load_start = ORIGIN(FLASH_DATA) + LOADADDR(.data);
|
||||
|
||||
.data :
|
||||
{
|
||||
__data_start = .; /* used by startup code */
|
||||
*(.data)
|
||||
*(.data*)
|
||||
__data_end = .; /* used by startup code */
|
||||
} >RAM AT>FLASH_TEXT
|
||||
|
||||
.bss :
|
||||
{
|
||||
__bss_start = .; /* used by startup code */
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
__bss_end = .; /* used by startup code */
|
||||
} >RAM
|
||||
}
|
||||
Reference in New Issue
Block a user