Code Monkey home page Code Monkey logo

mcusim's Introduction

Archived repository note

Everything has its end. This project does as well.
MCUSim will be archived from now on as I don't have enough time to develop it further.
Feel free to fork it. If you'll be interested in plans and development ideas - drop me a note via email. I'll share them gladly. Good luck!


Readme for MCUSim

MCUSim is a digital simulator and NGSpice library with microcontrollers. It is created to assist in circuit simulation, firmware debugging, testing and signal tracing.

Please note that the 8-bit AVR (RISC) microcontrollers are aimed at the moment. Feel free to start a discussion about any other family or architecture of the microcontrollers.

Quick start

$ git clone https://github.com/mcusim/MCUSim.git
$ cd MCUSim
$ mkdir build && cd build
$ cmake -DWITH_UNIT_TESTS=True -DWITH_XSPICE=True ..
$ make && make check && make tests
$ make install

Screenshots

Description

There is an mcusim.conf configuration file installed together with the mcusim binary and libmsim which can be used to tweak the program.

The best way to prepare your own simulation is to copy mcusim.conf to a new directory, adjust the options and run the simulator. Firmware and Lua files should also be placed there.

Lua scripts can be used to substitute models of the real devices during a simulation process. They may affect state of the chip in several ways, e.g. access registers, generate signals or terminate MCU.

Scripts are supposed to be external devices connected to the MCU of the simulated circuit (external EEPROM, humidity sensor, MOSFET switch, etc).

Registers of the simulated MCU can be saved into a VCD (value change dump) file and read using GTKWave viewer.

How can I start a discussion?

Feel free to ask questions and start a discussion in a mailing list for developers. Just subscribe and send a letter.

How can I join the development?

You may drop a note in the mailing list first or just code the feature you want to add and share your patch there. Before you start coding check the latest development release of MCUSim from our git repository or try to find a ticket at https://trac.mcusim.org/report. It might be that your feature has already been implemented.

There is no bureaucracy here.

Mailing list

Web sites

Source code is hosted at https://github.com/mcusim/MCUSim.
Wiki and issue tracker are at https://trac.mcusim.org.
Mailing list is at https://www.freelists.org/list/mcusim-dev.

mcusim's People

Contributors

asalychev avatar dsalychev avatar obarzpaw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mcusim's Issues

Configure ATmega8/8A by setting fuse bytes and lock bits

It's necessary to take into account any simulation-significant changes which can be made by setting these fuse bytes and lock bits, i.e. size of the bootloader section, top border of the frequency value, restrictions for the LPM and SPM instructions.

This configuration mechanism is already partially implemented in the simulator for ATmega8/8A only. You may take a look at declaration of the functions to set fuse and lock bytes. They usually look like:

int MSIM_M8ASetFuse(void *mcu, unsigned int fuse_n, unsigned char fuse_v);
int MSIM_M8ASetLock(void *mcu, unsigned char lock_v);

and placed inside an MCU-specific header file (simm8a.h for ATmega8/8A). NOTE: Declarations of the functions are important!

It is important to let initialization mechanism know that these functions are available. You may achieve it defining macros with functions names:

#define SET_FUSE_F	MSIM_M8ASetFuse
#define SET_LOCK_F	MSIM_M8ASetLock

in the header file.

You may read datasheet (its Memory Programming section) to understand what modifications should be done in struct MSIM_AVR instance according to the fuse and lock bytes values provided.

How you could help

MCUSim has a separate issue tracker and a wiki located at trac.mcusim.org. You may visit it and list the active tickets by milestone.

There is a separate milestone called Patches Welcome which contains experimental features which could be useful to have. Please, pick up an issue or another one and let the mailing list ([email protected]) know which one it was.

If you don't know which issue to choose or feature to implement, just leave a short message at the mailing list anyway.

Start-up times for different clock sources

See datasheet for ATmega48A/PA/88A/PA/168A/PA/328/P:

  • p. 27 (9. System Clock and Clock Options)
  • p. 28 (9.2 Clock Sources)
  • p. 30 (Table 9-4. Start-up Times for the Low Power Crystal Oscillator Clock Selection)
  • p. 31 (Table 9-6. Start-up Times for the Full Swing Crystal Oscillator Clock Selection)
  • p. 33 (Table 9-9. Start-up Times for the Low-frequency Crystal Oscillator Clock Selection and Table 9-10. Start-up Times for the Low-frequency Crystal Oscillator Clock Selection)
  • p. 34 (Table 9-12. Start-up times for the internal calibrated RC Oscillator clock selection)
  • p. 35 (Table 9-14. Start-up Times for the 128kHz Internal Oscillator and Table 9-16. Start-up Times for the External Clock Selection)

Program and data memory size checks

It could be worth to check size of program and data memory during MCU initialization process. There is a MSIM_M8AInit() function to initialize an instance of ATMega8A which could be a good point to start.

P.S. ATMega8A has 4K x 16 bits program (8192 bytes of flash) memory and 1120 bytes of data memory (96 bytes for register file and I/O memory and 1024 bytes for SRAM).

Add remaining I/O registers of ATmega8A to avrsim/include/mcusim/avr/sim/vcd_regs.h

It's required to make all missing I/O registers of ATmega8A microcontroller available to include into VCD dump.

You'll have to scan through datasheet http://www.atmel.com/Images/Atmel-8159-8-bit-AVR-microcontroller-ATmega8A_datasheet.pdf (page 380, 381), copy name of a register (MCUCSR for instance), try to find it in avrsim/include/mcusim/avr/sim/vcd_regs.h and add lines like this

You may build and run avrsim as follows to print a list of registers available for VCD dump file:
./avrsim -p m8a -U flash:w:dhtc.txt --dump-regs=?
You'll see a new register in a list if you perform these steps described above correctly.

Please, feel free to ask me in case of any trouble or help required.

dhtc.txt

AVR Stopped Mode

There is a BREAK command which is used by On-chip Debug system. It is intended to switch AVR MCU to the Stopped Mode to examine its internal resources. The AVRsim allows to do the same thing and is perfectly able to support it:

  • AVRSim is executing commands loaded from a ROM file; MCU state is AVR_RUNNING;
  • BREAK command is appeared; MSU state is switched to AVR_STOPPED; AVRSim is waiting for user input (if compiled with MSIM_TEXT_MODE) to continue.

Improve avrsim/avrsim.c to start AVR simulation

There is a main() function - entry point for avrsim - placed in a file avrsim/avrsim.c. It has only a stub for parsing command line arguments at the moment. The stub uses POSIX getopt() function to parse the arguments passed to the application.

This task is to improve avrsim.c to parse parameters:

  • m (example looks like avrsim -m m8a) to specify exact model of AVR microcontroller; avrsim.c should limit possible values for the parameter and select required microcontroller by calling specific initialization function (like MSIM_M8AInit())
  • p (example looks like avrsim -p ~/avr-project/prog.hex); avrsim should check existence of the file and pass it to a function which loads AVR program memory (these functions are expected to be exist for each model of AVR microcontrollers, for instance MSIM_M8ALoadProgmem()

There is a test which performs a sequence of very similar actions (MCU initialization, program memory loading and simulating). It can be found at tests/avr_core_test.c.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.