I am trying to understand how to use simavr to run my units tests.
I cannot make a simple example to work, I guess I'm just missing something, but would really like to understand why. I'm using simavr latest master as of 2018-11-13.
Here is my simple program, inspired from the tests:
#ifndef F_CPU
#define F_CPU 8000000
#endif
#include <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <avr/sleep.h>
#include "avr_mcu_section.h"
uint32_t value EEMEM = 0xdeadbeef;
static int uart_putchar(char c, FILE *stream) {
if (c == '\n')
uart_putchar('\r', stream);
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = c;
return 0;
}
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
int main()
{
stdout = &mystdout;
uint32_t c = eeprom_read_dword((void*)&value);
printf("Read from eeprom 0x%08lx -- should be 0xdeadbeef\n", c);
eeprom_write_dword((void*)&value, 0xcafef00d);
c = eeprom_read_dword((void*)&value);
printf("Read from eeprom 0x%08lx -- should be 0xcafef00d\n", c);
sleep_cpu();
}
I expect value to populate in the EEPROM with value 0xdeadbeef when I simulate. However, that's not what I observe:
$ avr-gcc -I../simavr/simavr/sim/avr -Os -mcall-prologues -Wall -std=c99 -mmcu=atmega88 bug.c -o bug.obj
$ avr-objcopy -R .eeprom -O ihex bug.obj bug.hex
$ ../simavr/simavr/run_avr --mcu atmega88 --freq 8000000 bug.hex
Loaded 1 section of ihex
Load HEX flash 00000000, 1836
Read from eeprom 0xffffffff -- should be 0xdeadbeef..
Read from eeprom 0xcafef00d -- should be 0xcafef00d..
The initial value of value in the EEPROM is 0xffffffff !
However, when I use the tests (atmega88_example.c) with its build chain, it seems to work as expected, which means there should be something wrong in my way to build or run the example.
Any clue?