Rahix / avr-device

Register access crate for AVR microcontrollers
Apache License 2.0
170 stars 66 forks source link

ATmega4809 scaffold support #62 #63

Closed explicite closed 3 years ago

explicite commented 3 years ago

Scaffold for #62

Rahix commented 3 years ago

For some reason, CI is failing right now ... I'm not quite sure why, maybe you can take a look and check whether this is also happening for you locally?

explicite commented 3 years ago

make: *** No rule to make target 'src/devices/atmega4809/mod.rs', needed by 'atmega4809'. Stop. From CI and on local machine.

Should I run svd2rust on svd and then copy mod.rs?

Rahix commented 3 years ago

Ah, I see. I think the issue is that you must add a patch/atmega4809.yaml file for the Makefile to work right now ...

explicite commented 3 years ago

patch/atmega4809.yaml added. I was able to define ports from common. make pass. Still spot some problems with keaywords on rs

error: expected identifier, found keyword `async`
   --> src/devices/atmega4809/tcb0/ctrlb.rs:248:12
    |
248 |     pub fn async(&self) -> ASYNC_R {
    |            ^^^^^ expected identifier, found keyword
    |
help: you can escape reserved keywords to use them as identifiers
    |
248 |     pub fn r#async(&self) -> ASYNC_R {
    |            ^^^^^^^

Will try to dig into patching.

Rahix commented 3 years ago

Newer versions (built from git) of svd2rust automatically sanitize names that are keywords in rust. But using those is currently blocked on Rahix/atdf2svd#13 ...

explicite commented 3 years ago

@Rahix make pass with common patch for ports. Should I fix something more in https://github.com/Rahix/atdf2svd? Looks like we need to release it and then I can back to this and refine patches.

Rahix commented 3 years ago

I just released version 0.2.0 of atdf2svd so you're good to go! I recommend working with the git version of svd2rust as well

explicite commented 3 years ago

I started with AC. Still not sure what is the logic. @Rahix do we have any guide for this? First diff which I spotted are modes for AC. From read-write we moved to read-only Screenshot from 2020-11-26 22-09-24

Rahix commented 3 years ago

The right version is the patched one so the move was from read-only to read-write actually.

I'd take a look at the patches in common/ and check if the changes that are done in each one also look necessary for ATmega4809. If yes, include the patch. Similarly for the timers, but you'll have to check which type of timers are used in your MCU.

Don't worry about patching everything from the get-go. If all the common patches which apply are included, this is already a pretty good foundation and hopefully enough to make a HAL implementation work.

explicite commented 3 years ago

Only common/ports.yaml works without any changes. For rest I need to create custom patches. Should this be done with mcu suffix or in nested dir?

common/usart.yaml

svdtools.patch.MissingRegisterError: Could not find USART0:UCSR?A

common/as.yaml

svdtools.patch.MissingPeripheralError: Could not find AC

common/adc.yaml

svdtools.patch.MissingPeripheralError: Could not find ADC

common/spi.yaml

svdtools.patch.MissingRegisterError: Could not find SPI0:SPSR

common/twi.yaml

svdtools.patch.MissingRegisterError: Could not find TWI0:TWCR

common/usart.yaml

svdtools.patch.MissingRegisterError: Could not find USART0:UCSR?A

common/wdt.yaml

svdtools.patch.MissingRegisterError: Could not find WDT:WDTCSR,WDTCR
Rahix commented 3 years ago

hmm, I'd create a subdir atmega_0x/.

But it looks like the peripherals differ substantially from the ones we currently have on the other MCUs. So it's probably not directly obvious what needs to be patches unless you want to go through the datasheet line by line ...

I'd actually keep patching to a minimun for now, and check back later, while doing the HAL implementation to see where changes are necessary.

Rahix commented 3 years ago

Thanks a lot!