Skip to content

Commit c5239f3

Browse files
authored
Merge pull request buserror#460 from maxgerhardt/master
For Reference: Building in Windows + MinGW
2 parents 3e42d03 + 3aef6dd commit c5239f3

File tree

5 files changed

+114
-4
lines changed

5 files changed

+114
-4
lines changed

Makefile.common

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ else
8585
endif
8686

8787
# FIXME uname -o doesn't work on bsd derivatives
88-
#WIN := ${shell uname -o}
88+
WIN := ${shell uname -o}
8989

9090
ifeq (${WIN}, Msys)
91-
AVR_ROOT := ${shell echo "${AVR32_HOME}" | tr '\\' '/'}
92-
AVR := ${AVR_ROOT}/bin/avr-
91+
AVR_ROOT := /mingw64/avr
92+
# compiler is globally available, no need to direct to a full path
93+
AVR := avr-
9394
IPATH += ${PREFIX}/include
9495
CFLAGS += -I${PREFIX}/include
9596
LDFLAGS += -L/lib -L/local/lib

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,95 @@
11
simavr - a lean and mean Atmel AVR simulator for linux
22
======
33

4+
# Notes for compiling on MinGW
5+
6+
Get MSys2 mingw from https://www.msys2.org/
7+
Start the MSYS MinGW shortcut (e.g. MSYS2 MinGW 32-bit or 64-bit)
8+
9+
Update packages
10+
11+
```
12+
pacman -Syu
13+
```
14+
15+
Install toolchains and dependencies. For 64-bit
16+
17+
```
18+
pacman -S mingw-w64-x86_64-toolchain
19+
pacman -S mingw-w64-x86_64-libelf
20+
pacman -S mingw-w64-x86_64-avr-toolchain
21+
pacman -S mingw-w64-x86_64-freeglut
22+
```
23+
24+
Replace `x86_64` with `i686` to get the 32-bit version instead.
25+
26+
```
27+
pacman -S mingw-w64-i686-toolchain
28+
pacman -S mingw-w64-i686-libelf
29+
pacman -S mingw-w64-i686-avr-toolchain
30+
pacman -S mingw-w64-i686-freeglut
31+
```
32+
33+
etc. **There currently is an issuw with the AVR toolchain:** https://github.com/msys2/MINGW-packages/issues/9183
34+
35+
Note: If you are using the 32-bit version, you **may** have to adapt `Makefile.common` regarding `AVR_ROOT := /mingw64/avr` to `AVR_ROOT := /mingw32/avr`. I have not tested this and the paths may be the same, but if you run into errors regarding AVR, check there.
36+
37+
In the normal user directory (`cd ~`), clone this repo
38+
39+
```
40+
git clone https://github.com/maxgerhardt/simavr.git
41+
cd simavr
42+
```
43+
44+
Start building with
45+
46+
```
47+
make build-simavr V=1
48+
```
49+
50+
That should be successfull.
51+
52+
Now create a install directory and install it. Note that `/home/Max/` is in this case my home directory.
53+
54+
Additionally this renames `simavr` to `simavr.exe` to make it properly executable. Ignore the compile error in the examples, it only counts that simavr is copied to the install directory.
55+
56+
```
57+
mkdir simavr_installed
58+
make install DESTDIR=/home/$USER/simavr/simavr_installed/
59+
mv simavr_installed/bin/simavr simavr_installed/bin/simavr.exe
60+
```
61+
62+
Copy the compiled output back to the normal Windows environment, e.g.
63+
64+
```
65+
cp -r /home/$USER/simavr/simavr_installed/ /c/Users/$USER/Desktop
66+
```
67+
68+
You should now have a working simavr executable.
69+
70+
```
71+
C:\Users\Max\Desktop\simavr_installed\bin>simavr --help
72+
Usage: simavr [...] <firmware>
73+
[--freq|-f <freq>] Sets the frequency for an .hex firmware
74+
[--mcu|-m <device>] Sets the MCU type for an .hex firmware
75+
[--list-cores] List all supported AVR cores and exit
76+
[--help|-h] Display this usage message and exit
77+
[--trace, -t] Run full scale decoder trace
78+
[-ti <vector>] Add traces for IRQ vector <vector>
79+
[--gdb|-g [<port>]] Listen for gdb connection on <port> (default 1234)
80+
[-ff <.hex file>] Load next .hex file as flash
81+
[-ee <.hex file>] Load next .hex file as eeprom
82+
[--input|-i <file>] A vcd file to use as input signals
83+
[--output|-o <file>] A vcd file to save the traced signals
84+
[--add-trace|-at <name=kind@addr/mask>] Add signal to be traced
85+
[-v] Raise verbosity level
86+
(can be passed more than once)
87+
<firmware> A .hex or an ELF file. ELF files are
88+
prefered, and can include debugging syms
89+
```
90+
91+
-----------------------
92+
493
_simavr_ is a new AVR simulator for linux, or any platform that uses avr-gcc. It uses
594
avr-gcc's own register definition to simplify creating new targets for supported AVR
695
devices. The core was made to be small and compact, and hackable so allow quick

simavr/sim/avr_usb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ avr_usb_ep_read(
484484
{
485485
avr_usb_t * p = (avr_usb_t *) param;
486486
uint8_t laddr = addr - p->r_usbcon;
487-
uint8_t v;
487+
uint8_t v = 0;
488488
struct _epstate * epstate = get_epstate(p, current_ep_to_cpu(p));
489489

490490
switch(laddr) {

simavr/sim/sim_utils.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727

2828
#include "sim_utils.h"
2929

30+
31+
#ifdef __MINGW32__
32+
char *strsep(char **stringp, const char *delim) {
33+
char *rv = *stringp;
34+
if (rv) {
35+
*stringp += strcspn(*stringp, delim);
36+
if (**stringp)
37+
*(*stringp)++ = '\0';
38+
else
39+
*stringp = 0;
40+
}
41+
return rv;
42+
}
43+
#endif
44+
3045
static argv_p
3146
argv_realloc(
3247
argv_p argv,

simavr/sim/sim_utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727

2828
#include <stdint.h>
2929

30+
31+
#ifdef __MINGW32__
32+
char *strsep(char **stringp, const char *delim);
33+
#endif
34+
3035
typedef struct argv_t {
3136
uint32_t size, argc;
3237
char * line;

0 commit comments

Comments
 (0)