Skip to content

Commit 6be6f73

Browse files
committed
fix: proper build
1 parent c4c77b8 commit 6be6f73

File tree

7 files changed

+297
-13
lines changed

7 files changed

+297
-13
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
uses: actions/checkout@v2
1515

1616
- name: Install dependencies
17-
run: sudo apt update && sudo apt install gcc-avr avr-libc freeglut3-dev arduino-core-avr
17+
run: sudo apt update && sudo apt install gcc-avr avr-libc freeglut3-dev arduino-core-avr libsimavr-dev libsimavrparts1
1818

1919
- name: Setup NodeJS
2020
uses: actions/setup-node@v4

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.idea
22
build
3-
build_assets
3+
simduino/simduino
44
node_modules
55
dist

build.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
set -e
2-
rm -rf build_assets build
2+
rm -rf build
33

44
BUILD_PATH=$(realpath build)
5-
mkdir build_assets build && cd build_assets
65

7-
git clone https://github.com/buserror/simavr
8-
cd simavr
6+
cd simduino
7+
gcc -I /usr/include/simavr -I /usr/include/simavr/parts simduino.c -lsimavr -lsimavrparts -o simduino
98

10-
make -j8
11-
cd examples/board_simduino
12-
13-
EXECUTABLE=$(find . | grep simduino.elf)
14-
cp ATmegaBOOT_168_atmega328.ihex "${EXECUTABLE}" "${BUILD_PATH}"
9+
mkdir "${BUILD_PATH}"
10+
cp simduino ATmegaBOOT_168_atmega328.ihex "${BUILD_PATH}"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@leaphy-robotics/playwright-arduino",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"license": "LGPL-3.0-only",
55
"main": "./dist/index.js",
66
"type": "module",
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
:107800000C94343C0C94513C0C94513C0C94513CE1
2+
:107810000C94513C0C94513C0C94513C0C94513CB4
3+
:107820000C94513C0C94513C0C94513C0C94513CA4
4+
:107830000C94513C0C94513C0C94513C0C94513C94
5+
:107840000C94513C0C94513C0C94513C0C94513C84
6+
:107850000C94513C0C94513C0C94513C0C94513C74
7+
:107860000C94513C0C94513C11241FBECFEFD8E036
8+
:10787000DEBFCDBF11E0A0E0B1E0ECE9FFE702C060
9+
:1078800005900D92A230B107D9F712E0A2E0B1E065
10+
:1078900001C01D92AD30B107E1F70E942D3D0C945F
11+
:1078A000CC3F0C94003C982F959595959595959582
12+
:1078B000905D8F708A307CF0282F295A8091C0000B
13+
:1078C00085FFFCCF9093C6008091C00085FFFCCF60
14+
:1078D0002093C6000895282F205DF0CF982F809127
15+
:1078E000C00085FFFCCF9093C6000895EF92FF92F1
16+
:1078F0000F931F93EE24FF2487018091C00087FD22
17+
:1079000017C00894E11CF11C011D111D81E4E8164B
18+
:1079100082E4F8068FE0080780E0180770F3E09132
19+
:107920000401F091050109958091C00087FFE9CF1E
20+
:107930008091C6001F910F91FF90EF9008950E94D3
21+
:10794000763C982F8091C00085FFFCCF9093C600B5
22+
:1079500091362CF490330CF09053892F089597555D
23+
:10796000892F08951F930E949F3C182F0E949F3CCF
24+
:107970001295107F810F1F9108951F93182F882350
25+
:1079800021F00E94763C1150E1F71F9108951F935A
26+
:10799000182F0E94763C803249F0809103018F5F5E
27+
:1079A000809303018530C1F01F9108958091C0003C
28+
:1079B00085FFFCCF84E18093C6008091C00085FFE5
29+
:1079C000FCCF1093C6008091C00085FFFCCF80E102
30+
:1079D0008093C6001F910895E0910401F091050184
31+
:1079E00009951F9108950E94763C803241F0809164
32+
:1079F00003018F5F80930301853081F008958091AA
33+
:107A0000C00085FFFCCF84E18093C6008091C00058
34+
:107A100085FFFCCF80E18093C6000895E0910401CA
35+
:107A2000F09105010995089540E951E08823A1F0FE
36+
:107A30002D9A28EE33E0FA013197F1F721503040CA
37+
:107A4000D1F72D9828EE33E0FA013197F1F7215064
38+
:107A50003040D1F7815061F708953F924F925F9285
39+
:107A60006F927F928F929F92AF92BF92CF92DF924E
40+
:107A7000EF92FF920F931F93CF93DF93000080E16B
41+
:107A80008093C4001092C50088E18093C10086E015
42+
:107A90008093C2005098589A259A81E00E94143D24
43+
:107AA00024E1F22E9EE1E92E85E9D82E0FE0C02ECA
44+
:107AB00010E1B12EAA24A394B1E49B2EA6E58A2E50
45+
:107AC000F2E57F2EE0E26E2E79E4572E63E5462E36
46+
:107AD00050E5352E0E94763C8033B1F18133B9F107
47+
:107AE000803409F46FC0813409F476C0823409F41B
48+
:107AF00085C0853409F488C0803531F1823521F1A3
49+
:107B0000813511F1853509F485C0863509F48DC0BC
50+
:107B1000843609F496C0843709F403C1853709F423
51+
:107B200072C1863709F466C0809103018F5F80932C
52+
:107B30000301853079F6E0910401F0910501099582
53+
:107B40000E94763C803351F60E94F33CC3CF0E94E2
54+
:107B5000763C803249F78091C00085FFFCCFF092DF
55+
:107B6000C6008091C00085FFFCCF9092C600809136
56+
:107B7000C00085FFFCCF8092C6008091C00085FFC9
57+
:107B8000FCCF7092C6008091C00085FFFCCF609250
58+
:107B9000C6008091C00085FFFCCF5092C600809146
59+
:107BA000C00085FFFCCF4092C6008091C00085FFD9
60+
:107BB000FCCF3092C6008091C00085FFFCCFB09210
61+
:107BC000C60088CF0E94763C863808F4BDCF0E945C
62+
:107BD000763C0E94F33C7ECF0E94763C803809F4CC
63+
:107BE0009CC0813809F40BC1823809F43CC1883942
64+
:107BF00009F48FC080E00E94C73C6CCF84E10E94F2
65+
:107C0000BD3C0E94F33C66CF85E00E94BD3C0E94D3
66+
:107C1000F33C60CF0E94763C809306010E94763C44
67+
:107C2000809307010E94F33C55CF0E94763C80333D
68+
:107C300009F41DC183E00E94BD3C80E00E94C73C66
69+
:107C400049CF0E94763C809309020E94763C809343
70+
:107C5000080280910C028E7F80930C020E94763C79
71+
:107C6000853409F415C18091080290910902892B8D
72+
:107C700089F000E010E00E94763CF801E85FFE4FDA
73+
:107C800080830F5F1F4F80910802909109020817AF
74+
:107C9000190788F30E94763C803209F045CF809125
75+
:107CA0000C0280FF01C16091060170910701660F0F
76+
:107CB000771F7093070160930601A0910802B091AD
77+
:107CC00009021097C9F0E8E0F1E09B01AD014E0F09
78+
:107CD0005F1FF999FECF32BD21BD819180BDFA9A17
79+
:107CE000F99A2F5F3F4FE417F50799F76A0F7B1F4B
80+
:107CF00070930701609306018091C00085FFFCCF5F
81+
:107D0000F092C6008091C00085FFFCCFB092C60003
82+
:107D1000E1CE83E00E94C73CDDCE82E00E94C73CFA
83+
:107D2000D9CE0E94763C809309020E94763C8093D3
84+
:107D300008028091060190910701880F991F909386
85+
:107D40000701809306010E94763C853409F4A6C0A1
86+
:107D500080910C028E7F80930C020E94763C8032D0
87+
:107D600009F0B8CE8091C00085FFFCCFF092C6002C
88+
:107D7000609108027091090261157105B9F140E046
89+
:107D800050E080910C02A82FA170B82FB27011C0E2
90+
:107D9000BB2309F45CC0E0910601F0910701319624
91+
:107DA000F0930701E09306014F5F5F4F46175707B7
92+
:107DB000E8F4AA2369F3F999FECF209106013091E6
93+
:107DC000070132BD21BDF89A90B58091C00085FFB2
94+
:107DD000FCCF9093C6002F5F3F4F30930701209355
95+
:107DE00006014F5F5F4F4617570718F38091C00099
96+
:107DF00085FDE5CE8091C00085FFF8CFE0CE81E023
97+
:107E00000E94C73C67CE0E94763C803209F08CCE3F
98+
:107E10008091C00085FFFCCFF092C6008091C00029
99+
:107E200085FFFCCFE092C6008091C00085FFFCCFAB
100+
:107E3000D092C6008091C00085FFFCCFC092C600E2
101+
:107E40008091C00085FFFCCFB092C60043CEE09188
102+
:107E50000601F091070194918091C00085FFFCCF4D
103+
:107E60009093C6009CCF80E10E94C73C33CE0E9415
104+
:107E7000763C0E94763C182F0E94763C112309F430
105+
:107E800083C0113009F484C08FE00E94C73C22CE29
106+
:107E900080910C02816080930C02E5CE80910C02EF
107+
:107EA000816080930C0259CF809107018823880F4D
108+
:107EB000880B8A2180930B02809106019091070123
109+
:107EC000880F991F90930701809306018091080203
110+
:107ED00080FF09C080910802909109020196909359
111+
:107EE000090280930802F894F999FECF1127E091D6
112+
:107EF0000601F0910701C8E0D1E08091080290915D
113+
:107F00000902103091F40091570001700130D9F34B
114+
:107F100003E000935700E89500915700017001308D
115+
:107F2000D9F301E100935700E89509901990009169
116+
:107F3000570001700130D9F301E000935700E89534
117+
:107F40001395103498F011270091570001700130FB
118+
:107F5000D9F305E000935700E895009157000170B0
119+
:107F60000130D9F301E100935700E895329602976A
120+
:107F700009F0C7CF103011F00296E5CF112480919F
121+
:107F8000C00085FFB9CEBCCE8EE10E94C73CA2CD19
122+
:0C7F900085E90E94C73C9ECDF894FFCF0D
123+
:027F9C00800063
124+
:040000030000780081
125+
:00000001FF

simduino/simduino.c

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
simduino.c
3+
4+
Copyright 2008, 2009 Michel Pollet <[email protected]>
5+
6+
This file is part of simavr.
7+
8+
simavr is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation, either version 3 of the License, or
11+
(at your option) any later version.
12+
13+
simavr is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with simavr. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
#include <unistd.h>
23+
#include <sys/stat.h>
24+
#include <fcntl.h>
25+
#include <stdlib.h>
26+
#include <string.h>
27+
#include <stdio.h>
28+
#include <libgen.h>
29+
30+
#include <pthread.h>
31+
32+
#include "sim_avr.h"
33+
#include "avr_ioport.h"
34+
#include "sim_elf.h"
35+
#include "sim_hex.h"
36+
#include "sim_gdb.h"
37+
#include "uart_pty.h"
38+
#include "sim_vcd_file.h"
39+
40+
uart_pty_t uart_pty;
41+
avr_t * avr = NULL;
42+
avr_vcd_t vcd_file;
43+
44+
struct avr_flash {
45+
char avr_flash_path[1024];
46+
int avr_flash_fd;
47+
};
48+
49+
// avr special flash initalization
50+
// here: open and map a file to enable a persistent storage for the flash memory
51+
void avr_special_init( avr_t * avr, void * data)
52+
{
53+
struct avr_flash *flash_data = (struct avr_flash *)data;
54+
55+
printf("%s\n", __func__);
56+
// open the file
57+
flash_data->avr_flash_fd = open(flash_data->avr_flash_path,
58+
O_RDWR|O_CREAT, 0644);
59+
if (flash_data->avr_flash_fd < 0) {
60+
perror(flash_data->avr_flash_path);
61+
exit(1);
62+
}
63+
// resize and map the file the file
64+
(void)ftruncate(flash_data->avr_flash_fd, avr->flashend + 1);
65+
ssize_t r = read(flash_data->avr_flash_fd, avr->flash, avr->flashend + 1);
66+
if (r != avr->flashend + 1) {
67+
fprintf(stderr, "unable to load flash memory\n");
68+
perror(flash_data->avr_flash_path);
69+
exit(1);
70+
}
71+
}
72+
73+
// avr special flash deinitalization
74+
// here: cleanup the persistent storage
75+
void avr_special_deinit( avr_t* avr, void * data)
76+
{
77+
struct avr_flash *flash_data = (struct avr_flash *)data;
78+
79+
printf("%s\n", __func__);
80+
lseek(flash_data->avr_flash_fd, SEEK_SET, 0);
81+
ssize_t r = write(flash_data->avr_flash_fd, avr->flash, avr->flashend + 1);
82+
if (r != avr->flashend + 1) {
83+
fprintf(stderr, "unable to load flash memory\n");
84+
perror(flash_data->avr_flash_path);
85+
}
86+
close(flash_data->avr_flash_fd);
87+
uart_pty_stop(&uart_pty);
88+
}
89+
90+
int main(int argc, char *argv[])
91+
{
92+
struct avr_flash flash_data;
93+
char boot_path[1024] = "ATmegaBOOT_168_atmega328.ihex";
94+
uint32_t boot_base, boot_size;
95+
char * mmcu = "atmega328p";
96+
uint32_t freq = 16000000;
97+
int debug = 0;
98+
int verbose = 0;
99+
100+
for (int i = 1; i < argc; i++) {
101+
if (!strcmp(argv[i] + strlen(argv[i]) - 4, ".hex"))
102+
strncpy(boot_path, argv[i], sizeof(boot_path));
103+
else if (!strcmp(argv[i], "-d"))
104+
debug++;
105+
else if (!strcmp(argv[i], "-v"))
106+
verbose++;
107+
else {
108+
fprintf(stderr, "%s: invalid argument %s\n", argv[0], argv[i]);
109+
exit(1);
110+
}
111+
}
112+
113+
uint8_t * boot = read_ihex_file(boot_path, &boot_size, &boot_base);
114+
if (!boot) {
115+
fprintf(stderr, "%s: Unable to load %s\n", argv[0], boot_path);
116+
exit(1);
117+
}
118+
if (boot_base > 32*1024*1024) {
119+
mmcu = "atmega2560";
120+
freq = 20000000;
121+
}
122+
printf("%s bootloader 0x%05x: %d bytes\n", mmcu, boot_base, boot_size);
123+
124+
avr = avr_make_mcu_by_name(mmcu);
125+
if (!avr) {
126+
fprintf(stderr, "%s: Error creating the AVR core\n", argv[0]);
127+
exit(1);
128+
}
129+
130+
snprintf(flash_data.avr_flash_path, sizeof(flash_data.avr_flash_path),
131+
"simduino_%s_flash.bin", mmcu);
132+
flash_data.avr_flash_fd = 0;
133+
// register our own functions
134+
avr->custom.init = avr_special_init;
135+
avr->custom.deinit = avr_special_deinit;
136+
avr->custom.data = &flash_data;
137+
avr_init(avr);
138+
avr->frequency = freq;
139+
140+
memcpy(avr->flash + boot_base, boot, boot_size);
141+
free(boot);
142+
avr->pc = boot_base;
143+
/* end of flash, remember we are writing /code/ */
144+
avr->codeend = avr->flashend;
145+
avr->log = 1 + verbose;
146+
147+
// even if not setup at startup, activate gdb if crashing
148+
avr->gdb_port = 1234;
149+
if (debug) {
150+
avr->state = cpu_Stopped;
151+
avr_gdb_init(avr);
152+
}
153+
154+
uart_pty_init(avr, &uart_pty);
155+
uart_pty_connect(&uart_pty, '0');
156+
157+
while (1) {
158+
int state = avr_run(avr);
159+
if ( state == cpu_Done || state == cpu_Crashed)
160+
break;
161+
}
162+
163+
}

src/board.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Board {
66
public port = '/tmp/simavr-uart0'
77

88
constructor() {
9-
this.process = spawn('./simduino.elf', {
9+
this.process = spawn('./simduino', {
1010
cwd: `${import.meta.dirname}/../build`
1111
})
1212
}

0 commit comments

Comments
 (0)