Skip to content
This repository has been archived by the owner on Aug 20, 2023. It is now read-only.

added args to simulavr to define serial device #3

Open
wants to merge 20 commits into
base: traumflug
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
cb3981e
automake: don't treat warnings as errors.
Traumflug Nov 13, 2013
74c9033
src/avrerror.h: fix a number of compilation warnings.
Traumflug Nov 19, 2013
faa97b1
src/avrerror.cpp: fix MESSAGE handling.
Traumflug Nov 16, 2013
6595774
src/avrerror.cpp: simplify plain messages.
Traumflug Nov 16, 2013
179be74
Use avr_message() for verbose messages.
Traumflug Nov 16, 2013
4f6fa7c
Swap -v and -V command line parameters.
Traumflug Nov 16, 2013
e06733f
Update examples/stdiodemo/README.
Traumflug Nov 14, 2013
9a6eac7
Add yet another example, simple_serial.
Traumflug Nov 15, 2013
63a9c70
Allow to store simulation parameters inside the ELF file.
Traumflug Nov 15, 2013
06c48bc
ELF simulation info storage: bring SIMINFO_DEVICE() into action.
Traumflug Nov 16, 2013
77389ef
ELF simulation info storage: bring SIMINFO_CPUFREQUENCY() into action.
Traumflug Nov 16, 2013
276fe1f
ELF simulation info storage: introduce a length variable.
Traumflug Nov 16, 2013
cfcb58e
ELF simulation info storage: bail out on malformed .siminfo sections.
Traumflug Nov 18, 2013
9d470ca
ELF simulation info storage: introduce SIMINFO_SERIAL_OUT().
Traumflug Nov 18, 2013
b335207
ui/serialrx: implement SerialRxFile.
Traumflug Nov 18, 2013
7dfe57d
ELF simulation info storage: bring SIMINFO_SERIAL_OUT() into action.
Traumflug Nov 18, 2013
27bd1f4
ELF simulation info storage: introduce SIMINFO_SERIAL_IN():
Traumflug Nov 19, 2013
9773047
ui/serialtx: implement SerialTxFile.
Traumflug Nov 19, 2013
c93f238
ELF simulation info storage: bring SIMINFO_SERIAL_IN() into action.
Traumflug Nov 19, 2013
1a918c7
added args to simulavr to define serial device
Dec 30, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# common initialisation of autotools
####
AC_INIT([SimulAVR], [1.1dev], [simulavr-devel@nongnu.org])
AM_INIT_AUTOMAKE([1.10 -Wall -Werror foreign])
AM_INIT_AUTOMAKE([1.10 -Wall foreign])
AC_PREREQ([2.61])
AC_CONFIG_MACRO_DIR([m4])
AM_MAINTAINER_MODE
Expand Down Expand Up @@ -215,6 +215,7 @@ AC_CONFIG_FILES([
examples/atmega48/Makefile examples/atmega128_timer/Makefile
examples/atmel_key/Makefile examples/feedback/Makefile examples/simple_ex1/Makefile
examples/spi/Makefile examples/stdiodemo/Makefile examples/python/Makefile
examples/simple_serial/Makefile
])

## Certain files should only be generated if Tcl is available and enabled
Expand Down
2 changes: 1 addition & 1 deletion doc/mdate-sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Report bugs to <bug-automake@gnu.org>.
EOF
exit $?
;;
-v | --v*)
-V | --v*)
echo "mdate-sh $scriptversion"
exit $?
;;
Expand Down
4 changes: 2 additions & 2 deletions doc/simulavr.texi
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ no matter if it is ever reached or not.
run with user interface for external pin handling at port 7777. This
does not open any graphics but activates the interface to communicate
with the environment simulation.
@item -v --version
@item -V --version
show the software version of simulavr
@item -V --verbose
@item -v --verbose
output some hints to console
@item -W --writetopipe <offset>,<file>
add a special pipe register to device at IO-Offset and opens <file> for writing
Expand Down
4 changes: 2 additions & 2 deletions doc/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Invoke simulavr::
Common options
--------------

``-v, --version``
``-V, --version``
show the software version of simulavr

``-V, --verbose``
``-v, --verbose``
output some hints to console

``-h, --help``
Expand Down
2 changes: 1 addition & 1 deletion examples/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

examplesdir = $(docdir)/examples

SUBDIRS = simple_ex1
SUBDIRS = simple_ex1 simple_serial
if USE_TCL
SUBDIRS += anacomp atmega48 spi stdiodemo feedback atmega128_timer atmel_key
endif
Expand Down
3 changes: 3 additions & 0 deletions examples/simple_serial/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.elf
*.hex

43 changes: 43 additions & 0 deletions examples/simple_serial/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# $Id$
#

examplesdir = $(docdir)/examples/simple_serial

EXAMPLE = simple_serial

AVR_GCC = @AVR_GCC@
AVR_CPU = atmega644
AVR_FREQUENCY = 20000000
AVR_CFLAGS = -g -O2 -mmcu=$(AVR_CPU) -DF_CPU=$(AVR_FREQUENCY)
AVR_CFLAGS += -Wl,--section-start=.siminfo=0x900000
AVR_OBJS = main.o serial.o
SIMULAVR_ARGS = -d $(AVR_CPU) -f $(EXAMPLE).elf

EXTRA_DIST = main.c serial.c serial.h

examples_DATA = $(EXAMPLE).hex $(EXAMPLE).elf $(EXTRA_DIST) README

CLEANFILES = $(EXAMPLE).hex $(EXAMPLE).elf $(AVR_OBJS)


do: $(EXAMPLE).elf
../../src/simulavr $(SIMULAVR_ARGS)

program: $(EXAMPLE).hex
avrdude -c stk500v2 -b 115200 -p $(AVR_CPU) -P $(SERIAL_AVR) \
-U flash:w:$<


$(EXAMPLE).hex: $(EXAMPLE).elf
avr-objcopy -j .text -j .data -O ihex -R .eeprom -R .fuse -R .lock $< $@

$(EXAMPLE).elf: $(AVR_OBJS)
$(AVR_GCC) $(AVR_CFLAGS) -o $@ $^

main.o: $(srcdir)/main.c
$(AVR_GCC) $(AVR_CFLAGS) -c -o $@ $<

serial.o: $(srcdir)/serial.c $(srcdir)/serial.h
$(AVR_GCC) $(AVR_CFLAGS) -c -o $@ $<

48 changes: 48 additions & 0 deletions examples/simple_serial/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# $Id$
#
#
# Copyright (C) 2013 Markus Hitter <mah@jump-ing.de>


This example illustrates how one can communicate with the simulated AVR
using its USART. The other end of the communications line is stdin/stdout,
so you can simply interact with the simulated AVR by typing into the
terminal you used to start it with.

The firmware provided can be uploaded to real hardware as-is and should do
just the same when accessed through a serial terminal. This is an important
point, because in main.c you can see how few tweaks to the original code
are required to allow interacting with a simulated run. All of these tweaks
don't alter the binary actually executed at all.

Building and running the example:

- Have SimulAVR built, default configuration options are fine.

- Go to examples/simple_serial (here).

- Build the example:

make

- Run the example:

make do

- Upload the example to and run it on real hardware (this isn't exactly
flexible, yet, it might require some tweaks to the Makefile to match
/your/ hardware):

export SERIAL_AVR=/dev/<your device here>
make program
gtkterm -p $SERIAL_AVR -s 19200

Interaction:

Well, extremely simple. It's a code example, after all. Type characters and
the characters will be sent back with some extra text. That's all, I hope
this fuels your imagination.



78 changes: 78 additions & 0 deletions examples/simple_serial/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
****************************************************************************
*
* simple_serial - A demo for the SimulAVR simulator.
* Copyright (C) 2013 Markus Hitter <mah@jump-ing.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
****************************************************************************
*
* $Id$
*
* Super trivial example exercising the UART serial communications line.
*
* It's purpose is to show how SimulAVR can redirect serial communications
* in a way useful for running in a simulator, while requiring NO code
* modifications which would change it's behaviour compared to running
* on real hardware or disallowing to run the very same compiled binary
* on that hardware. The compiled binary should work in the simulator just
* as fine as on hardware.
*/

#include "serial.h"

#include <avr/interrupt.h>

/*
* Here we tell SimulAVR for which device and which frequency we build this
* code. The nice thing is, these macros add a section to the ELF file, so
* they can be read by SimulAVR, but they're also ignored when converted to
* an ihex file for hardware upload. Accordingly, the executed binary for
* SimulAVR and real hardware is the same, no need to recompile for one or
* another. The more important result of this is, behaviour is also exactly
* the same, no extra cycles for serving simulator matters.
*
* One small caveat: To stop the linker from stripping this section, avr-gcc
* needs an extra parameter when linking the binary (see Makefile.am):
*
* -Wl,--section-start=.siminfo=0x900000
*
* For details on these macros, see the comments in simulavr_info.h.
*/
#include "../../src/simulavr_info.h"
SIMINFO_DEVICE("atmega644");
SIMINFO_CPUFREQUENCY(F_CPU);
SIMINFO_SERIAL_IN("D0", "-", 19200);
SIMINFO_SERIAL_OUT("D1", "-", 19200);


// This is all we need:
int main (void) {

serial_init();
sei();

serial_writestr_P(PSTR("Hello, world!\n\nNow, please type:\n"));

for (;;) {
if (serial_rxchars() != 0) {
uint8_t c = serial_popchar();
serial_writestr_P(PSTR("received: <"));
serial_writechar(c);
serial_writestr_P(PSTR(">\n"));
}
}
}
Loading