Hi,
Last time I returned to my old project based on amforth (
http://amforth.sf.net ) and wanted to simulate it in simavr with terminal connected via pty.
It was relatively easy to pathc the run_avr application to add the uart_pty support:
*** /tmp/sa/simavr/simavr/sim/run_avr.c 2013-11-10 19:20:59.562394701 +0100
--- run_avr.c 2013-11-09 14:33:16.161296139 +0100
***************
*** 31,36 ****
--- 31,38 ----
#include "sim_hex.h"
#include "sim_core_decl.h"
+ #include "uart_pty.h"
+ uart_pty_t uart_pty;
void display_usage(char * app)
{
***************
*** 172,177 ****
--- 174,183 ----
avr_gdb_init(avr);
}
+ uart_pty_init(avr, &uart_pty);
+ uart_pty_connect(&uart_pty, '0');
+
+
signal(SIGINT, sig_int);
signal(SIGTERM, sig_int);
*** /tmp/sa/simavr/simavr/Makefile 2013-11-10 19:20:59.554394700 +0100
--- Makefile 2013-11-09 14:38:09.849305555 +0100
***************
*** 35,46 ****
include ../Makefile.common
cores := ${wildcard cores/*.c}
! sim := ${wildcard sim/sim_*.c} ${wildcard sim/avr_*.c}
sim_o := ${patsubst sim/%.c, ${OBJ}/%.o, ${sim}}
VPATH = cores
VPATH += sim
IPATH = sim
IPATH += .
IPATH += ../../shared
--- 35,48 ----
include ../Makefile.common
cores := ${wildcard cores/*.c}
! sim := ${wildcard sim/sim_*.c} ${wildcard sim/avr_*.c} ${wildcard sim/uart_*.c}
sim_o := ${patsubst sim/%.c, ${OBJ}/%.o, ${sim}}
VPATH = cores
VPATH += sim
+ LDFLAGS += -lpthread -lutil
+
IPATH = sim
IPATH += .
IPATH += ../../shared
I have also generated the working amforth image for atmega328p using the amforth-5.1/appl/template sources in the amforth-5.1 distribution.
The correct operation I have verified using the bare metal atmega328p microcontroller.
Afterwards I have created the hex file suited for loading into the simavr:
FWARE=/home/wzab/amforth-5.1/appl/template/template
srec_cat $FWARE.eep.hex -Intel -fill 0xff 0x0 0x400 -offset 0x810000 $FWARE.hex -Intel -fill 0xff 0 32768 -output amforth.hex -Intel -multiple -Line_Length 44
Started the simavr:
$ ./run_avr -m atmega328p -f 8000000 -g
avr_gdb_init listening on port 1234
uart_pty_init bridge on port *** /dev/pts/10 ***
uart_pty_connect: /tmp/simavr-uart0 now points to /dev/pts/10
note: export SIMAVR_UART_XTERM=1 and install picocom to get a terminal
Then minicom:
$ minicom -o -D /dev/pts/10
And gdb:
avr-gdb -x gdb.script
where gdb.script contained:
target remote localhost:1234
load whole.hex
continue
Afterwards I was able to get the Amforth prompt in the picocom,
and I was able to use compiled-in words:
Welcome to minicom 2.6.2
OPTIONS: I18n
Compiled on Feb 7 2013, 21:36:21.
Port /dev/pts/10, 19:39:56
Press CTRL-A Z for help on special keys
amforth 5.1 ATmega328P
> 10
ok
> 20
ok
> +
ok
> .
30 ok
>
The problem occurs however, when I try to compile any new word:
> : test 10 20 + . ;
ok
> test
The simulated amforth hangs forever.
To investigate the problem, I have uncommented printd in avr_eeprom.c and avr_flash.c sources, and it seems,
that the problem is associated with the way how simavr simulates writing to the flash and/or eeprom memory.
I'll be grateful if anybody could check/confirm my findings and provide any pointers how to investigate and fix that propblem.
--
Regards,
Wojtek