Author Topic: AVR tiny simulator  (Read 3059 times)

0 Members and 1 Guest are viewing this topic.

Offline free_electronTopic starter

  • Super Contributor
  • ***
  • Posts: 9056
  • Country: us
    • SiliconValleyGarage
AVR tiny simulator
« on: September 10, 2025, 02:41:50 am »
I am looking for a toolchain that can simulate an AVR Tiny core based processor ( 4809)

I want to see LIVE I/O updates. Meaning every pin needs to have a virtual LED that updates as the program runs. The program does not need to run realtime of course. it i want to see the i/o change.
It also needs ot be able to simulate interrupts. if an pin is programmed to react to a falling edge , the interrupt handler should fire when i click the pin button low.
I also need a virtual uart terminal. If a uart is configured i need a console window to it where i can see what is being sent.

Needs to be able to  read standard OBJ files from GCC and trace sourcecode

Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Offline firewalker

  • Super Contributor
  • ***
  • Posts: 2483
  • Country: gr
Re: AVR tiny simulator
« Reply #1 on: September 10, 2025, 11:59:18 am »
« Last Edit: September 10, 2025, 12:01:27 pm by firewalker »
Become a realist, stay a dreamer.

 

Online wraper

  • Supporter
  • ****
  • Posts: 19522
  • Country: lv
Re: AVR tiny simulator
« Reply #2 on: September 10, 2025, 12:09:55 pm »
I would not bother with Proteus AVR emulation, unless you want to debug its bugs. In the past I had experience when certain math operation in firmware did not math properly (worked fine in real HW) and several other peripheral issues as well. Overall, it was a counterproductive waste of time.
 

Offline firewalker

  • Super Contributor
  • ***
  • Posts: 2483
  • Country: gr
Re: AVR tiny simulator
« Reply #3 on: September 10, 2025, 12:26:48 pm »
Tbh every time I had to user proteus VSM it was OK. I don;t know if https://wokwi.com is suitable for AVR tiny.

Alexander.
Become a realist, stay a dreamer.

 

Offline squadchannel

  • Super Contributor
  • ***
  • Posts: 1279
  • Country: jp
  • deepl translate user
Re: AVR tiny simulator
« Reply #4 on: September 10, 2025, 12:53:42 pm »
By the way, the At *mega* 4809 Curiosity nano board(DM320115) is only $9.99($10.19 in digikey). I wonder what the reason is not to buy it. :-//
I think the REAL hardware is better than an emulator, but I've never used an emulator myself, so I can't really say. ^-^


EDIT:
https://www.eevblog.com/forum/microcontrollers/processors-with-factory-programmed-bootloaders-over-uart/msg6036143/#msg6036143
from this?
I think AVR C is very easy to understand. (and can learn far more than with Arduino. also serves as a stepping stone to 32-bit MCUs.)
haven't used many other microcontrollers, but with AVR, can enable multiple IPs connected to a single pin simultaneously.(at least in recent AVR cores)
can set up a glue logic in CCL and connect the output pins directly to SDA. just enable the CCL output while keep the pin mode set to input.
There are all sorts of ways to use it.
but USART half-duplex mode can't be used properly, it overwrites the pin mode.

interrupt? just enable interrupts for each IP and then call sei();. receive the interrupt, it jumps to the ISR( vector ){};. That's all.

I never had any trouble with pin mode. maybe because I'm working with real hardware? I have a few modern(416, 4809, 3217, DA) AVR development boards because they're cheap.
« Last Edit: September 10, 2025, 03:10:59 pm by squadchannel »
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 8353
  • Country: fi
    • My home page and email address
Re: AVR tiny simulator
« Reply #5 on: September 10, 2025, 01:00:09 pm »
I am looking for a toolchain that can simulate an AVR Tiny core based processor
What about the one in the old Microchip Studio?
Use standard GNU toolchains, and only the simulator?

Never used it myself, though.
 

Offline free_electronTopic starter

  • Super Contributor
  • ***
  • Posts: 9056
  • Country: us
    • SiliconValleyGarage
Re: AVR tiny simulator
« Reply #6 on: September 10, 2025, 09:32:35 pm »
the reason for a simulator is that i want to be able to take a look at what bits are being flipped in internal registers.
I tried configuring the device using atmels START but that generates a metric ton of C code that runs every time at startup and takes up rom space ( and boot time)

the simulator will let me peek in the configuration registers so i can replace all that stuff with a few line of direct register loading.
Many of these toolchain rely on huge libraries with lots of calls at startup .

Silicon labs hat a config tool for the 8051Fxx series where you clicked the features you want and it would show you directly what registers got what bits flipped. there was no runtime code other than a few MOV instructions directly into the processor registers.

everything these days is hidden under layers upon layers of code.

i miss the days of true hardware emulators with bond-out chips where you could actually see and modify everything at runtime.
« Last Edit: September 10, 2025, 09:34:17 pm by free_electron »
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 5852
  • Country: dk
Re: AVR tiny simulator
« Reply #7 on: September 10, 2025, 09:45:12 pm »
the reason for a simulator is that i want to be able to take a look at what bits are being flipped in internal registers.
I tried configuring the device using atmels START but that generates a metric ton of C code that runs every time at startup and takes up rom space ( and boot time)

the simulator will let me peek in the configuration registers so i can replace all that stuff with a few line of direct register loading.
Many of these toolchain rely on huge libraries with lots of calls at startup .

Silicon labs hat a config tool for the 8051Fxx series where you clicked the features you want and it would show you directly what registers got what bits flipped. there was no runtime code other than a few MOV instructions directly into the processor registers.

everything these days is hidden under layers upon layers of code.

i miss the days of true hardware emulators with bond-out chips where you could actually see and modify everything at runtime.

https://www.digikey.dk/en/products/detail/microchip-technology/PG164100/9562532
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4671
  • Country: us
Re: AVR tiny simulator
« Reply #8 on: September 11, 2025, 12:41:00 am »
Quote
an AVR Tiny core based processor ( 4809)

You should probably note that a 4809 is NOT an "AVR Tiny" core.  It's part of the "MegaAVR 0-series." (officially known as "AVRxt" apparently.  Which IS the same designation as the "new" Tiny-0/1/2 chips.)

Quote
the simulator will let me peek in the configuration registers so i can replace all that stuff with a few line of direct register loading.
That seems a backwards way of doing things.  Why not just read the datasheet?
 

Offline squadchannel

  • Super Contributor
  • ***
  • Posts: 1279
  • Country: jp
  • deepl translate user
Re: AVR tiny simulator
« Reply #9 on: September 11, 2025, 01:19:23 am »
the reason for a simulator is that i want to be able to take a look at what bits are being flipped in internal registers.

Using the UPDI connection, it can executed on REAL hardware.

I tried configuring the device using atmels START but that generates a metric ton of C code that runs every time at startup and takes up rom space ( and boot time)

this is AVR. not CubeIDE. 8)
only includes io.h. just 190 bytes.



did you generate the project using Atmel Start? like CubeIDE, it consumes a lot of program memory.

i miss the days of true hardware emulators with bond-out chips where you could actually see and modify everything at runtime.

just buy a Curiosity Nano board from DigiKey for $10.19, connect it via USB, write program in Microchip Studio, and debug it.
can use USART, IO View, real io pins, and there's no weird behavior.
No need to buy expensive emulators or incomplete simulators.

By the way, the At *mega* 4809 Curiosity nano board(DM320115) is only $9.99($10.19 in digikey). I wonder what the reason is not to buy it. :-//

I don't know if it works in BASIC.
« Last Edit: September 11, 2025, 01:36:55 am by squadchannel »
 

Offline mtwieg

  • Super Contributor
  • ***
  • Posts: 1865
  • Country: us
Re: AVR tiny simulator
« Reply #10 on: September 16, 2025, 12:47:04 pm »
I recall back in school, AVR studio 4.xx could simulate nearly every AVR part in the way you described. Looks like the 4908 was released ~2018, did they stop providing simulator support for new parts? Or does the current successor to AVR studio just not support simulation period?

Anyways, I also think debugging actual hardware is preferable. You should be able to see every register the simulator would show you, maybe more.
 

Offline gjl

  • Newbie
  • Posts: 7
  • Country: de
Re: AVR tiny simulator
« Reply #11 on: September 21, 2025, 08:09:32 pm »
the simulator will let me peek in the configuration registers so i can replace all that stuff with a few line of direct register loading.
So you want to simulate some code, then reverse-engineer what hardware setup s needed, and use that to program the device.

Sounds terribly complicated, error prone and driven by avoiding writing working code from the start.

What about reading the manual, and from there engineer proper code?
 

Offline free_electronTopic starter

  • Super Contributor
  • ***
  • Posts: 9056
  • Country: us
    • SiliconValleyGarage
Re: AVR tiny simulator
« Reply #12 on: September 21, 2025, 10:51:09 pm »
the simulator will let me peek in the configuration registers so i can replace all that stuff with a few line of direct register loading.
So you want to simulate some code, then reverse-engineer what hardware setup s needed, and use that to program the device.

Sounds terribly complicated, error prone and driven by avoiding writing working code from the start.

What about reading the manual, and from there engineer proper code?

No , i want to set up the peripherals using the graphical configuration tool from Atmel. The configuration tool creates a bunch of startup code in C. I want to see the result after that code has run. What registers have they modified and what are the content. some things are easy to configure using the GUI but require multiple registers to be modified. It pre-empts mistakes in the register configuration.






Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Online PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3435
  • Country: au
Re: AVR tiny simulator
« Reply #13 on: September 22, 2025, 05:58:34 am »
I am looking for a toolchain that can simulate an AVR Tiny core based processor ( 4809)
My understanding was that Atmel tools were able to simulate any AVR member, via a compiled simulator engine derived from the chip gate level source code.

 Is that no longer the case ?

Did microchip discard or lose that nice capability along the way ?
 

Offline Zoli

  • Frequent Contributor
  • **
  • Posts: 809
  • Country: ca
  • Grumpy old men
Re: AVR tiny simulator
« Reply #14 on: September 22, 2025, 06:15:32 am »
Attached is a screenshot of the IO view in Microchip Studio 7.0.2594(current) for ATTiny10.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4671
  • Country: us
Re: AVR tiny simulator
« Reply #15 on: September 22, 2025, 07:06:25 am »
Quote
i want to set up the peripherals using the graphical configuration tool from Atmel. The configuration tool creates a bunch of startup code in C. I want to see the result after that code has run. What registers have they modified and what are the content. some things are easy to configure using the GUI but require multiple registers to be modified. It pre-empts mistakes in the register configuration.

This is not what you said originally:

Quote
I want to see LIVE I/O updates. Meaning every pin needs to have a virtual LED that updates as the program runs. The program does not need to run realtime of course. it i want to see the i/o change.
It also needs ot be able to simulate interrupts. if an pin is programmed to react to a falling edge , the interrupt handler should fire when i click the pin button low.
I also need a virtual uart terminal. If a uart is configured i need a console window to it where i can see what is being sent.

Quote
Atmel tools were able to simulate any AVR member
AFAIK, they can simulate a 4809 just fine, and might be OK for checking those register contents, but I don't think they do much in the way of the "live GUI interface", and "stimulous files" were a pain.

"Of course", "Studio" is deprecated and you're supposed to move to "MPLABX."  I haven't tried to use the MPLABX simulator; a quick test looks pretty grim :-( (No VPORT SFRs, no PORTB, sorting by address ... doesn't...)
Also, I don't think either simulator is set up to handle the new structure-style IO definitions very well (or at all)
 

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 8606
  • Country: ro
Re: AVR tiny simulator
« Reply #16 on: September 22, 2025, 07:30:47 am »
the reason for a simulator is that i want to be able to take a look at what bits are being flipped in internal registers

ATtiny has one wire debugging (a hardware capability), so you can look inside the real hardware if you want to.  That can be interfaced with GDB (AVR-GCC and AVR-GDB under the hood), but it can be used from the Eclipse GUI, for example:


Printscreen from https://www.eevblog.com/forum/microcontrollers/avr-(arduino)-linux-debug/msg3511900/#msg3511900

The setup was not trivial, but all the pieces of software used there are free and open source.  I did once that setup, and in the end you get a true (hardware) debugger, not a software stub debugger (ATtiny won't have enough memory for a stub debugger).  A hardware debugger consumes no memory, it makes use of the debugging features already implemented in the chip's hardware.

Once you get the setup working, you will have the whole set of features of a proper hardware debugger:  step by step execution capability, breakpoints, I/Os, registry and memory inspection and/or modification during execution, stack trace, both a C and assembler view for sources, etc.
 
Not all AVR chips have one wire debugger capability, but ATtiny has it (I've tested that on an ATtiny13).  Recent ATmega series (for example the ATmega328 used in the typical Arduino boards) also have the one wire debugger feature, just that the Arduino boards doesn't take advantage of it.
« Last Edit: September 22, 2025, 07:35:17 am by RoGeorge »
 
The following users thanked this post: PCB.Wiz

Offline free_electronTopic starter

  • Super Contributor
  • ***
  • Posts: 9056
  • Country: us
    • SiliconValleyGarage
Re: AVR tiny simulator
« Reply #17 on: September 22, 2025, 05:37:56 pm »
This is not what you said originally:
i gave up on that idea. The compiler i use has enough simulation capability ( like an LCD display and the i/o pins) but it can't handle interrupts.  I got the interrupt code working. It's very minimal and was fairly easy to get going 

The big thing is (was) the configuration of some of the more complex blocks like the timer/compare blocks that have various settings for prescalers and clock sources.

Silicon labs had a nice config tool for their F-series processors where you had a GUI and could click the options and set the numbers you wanted. It produced direct machine or C code that performed SFR writes without requiring  library of functions like in Arduino or STM ecosystem. That code is invariably a ton of calls to a library.

The silabs GUI did all the lifting and just told you : based on what you selected in the GUI : set these 9 registers with the following values. The startup code was essentially a number of mov operations. No bit twiddling happened at runtime. It was pre-calculated in the GUI.
I can figure it out from the datasheet but if there is a nice tool to make life easier ( and crosscheck what i figured out) those things are welcome. Atmel had START https://start.atmel.com/ But it banks on some "middleware" and now there is MCC . START let's you configure the pinmux and set up some elements like the clock domain for the ADC.

But the generated code is unreadable. It is scattered in like 20 files and they predefine a bunch of inline functions fore each possible bit and then call those. At compile time the compiler + optimizer processes those and squashes it to a single register write. They essentially let the compiler do the lifting as opposed to the GUI.

That's why i wanted a simulator to see what the compiler had ultimately produced in terms of register writes. That is all i needed. I don't use C so i need to implement the register operations in my toolchain.
Compile the produced code and run it ( just the system_init. Then halt and inspect the register contents.





Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Offline 0xdeadbeef

  • Super Contributor
  • ***
  • Posts: 1912
  • Country: de
Re: AVR tiny simulator
« Reply #18 on: September 22, 2025, 06:19:09 pm »
Maybe out of context and not very helpful, but commercial simulators like Lauterbach Trace32 just simulate the core ("instruction set simulator"). If you write to or read from peripherals, this is just like writing to and reading from a (virtual) RAM. There is no trap handling, there are no interrupts, even the FPU behavior is not the same.
I guess, at least at a certain level, the complexity of simulating complex microcontrollers with all their peripherals is just too much effort for all the possible hardware variants.


Trying is the first step towards failure - Homer J. Simpson
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->