简体   繁体   中英

How is inline assembly possible on AVR 8-bit?

I know this fits close to the "stupid-question" category, but I've been researching how to execute machine code after bootloading on AVR 8-bit and have come to an understanding that the Harvard Architecture that is used on the AVR 8-bit MCUs makes it impossible to execute code from anywhere other than flash. How then is it possible to introduce new executable code at runtime using inline asm?

You are mixing up three things:

  1. Inline assembly

    Inline assembly is used to pass assembler instructions to the C (or whatever language) compiler. The compiler will add that assembler instructions to the code it produces. In the end the inline assembler instructions are stored the same way as instructions that have been generated by the compiler. If you write the program to the flash memory the inline instructions will also be located in flash memory.

  2. Boot loader

    The boot loader typically will read data from some input (such as an USB interface) and write the data into the flash memory. So the program sent to the AVR will later be executed from flash memory, not from RAM.

  3. Executing code from RAM

    Many processors support that. Also many boot loaders (for other microcontrollers) allow loading code into the RAM instead of flash and executing the code from there. You are right: At least most (maybe all??) AVR 8-bit microcontrollers do not support this!

... the Harvard Architecture that is used on the AVR 8-bit MCUs makes it impossible to execute code from anywhere other than flash.

Your understanding is correct, code can be only excecuted from flash.

How then is it possible to introduce new executable code at runtime using inline asm?

You can write code which writes/reads the Flash memory as plain data. In fact this is exactly what is done by any bootloaders. Even if there is no explicit "boot loader section", such as in the attiny family, accessing the flash in this way is possible. The datasheet of your part (page 263 in this example) contains a chapter for this topic, I'd suggest reading it in detail.

That said, I've not seen code which utilizes this function for running additional yet. The additional complexity might make it infeasible for a small, low power microcontroller like the AVR.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM