Closed yusongone closed 1 year ago
Hello, thanks for taking the time to explain the background of your project.
Here are some pointers:
Serial.begin()
prior to using Serial.print()
? Also, which version of avr8js are you using? the one from the stackbliz example is pretty old.Thank you for taking the time to respond to my queries, it has been of great help to me.
1: I've researched previously, asking whether something needs to be done during compilation if one wants to expand the run space of Uno. However, due to my unfamiliarity with this field, I haven't received a precise answer. Currently, I'm using arduino-cli as a compile service, with the compile command being arduino-cli compile --fqbn arduino:avr:uno ./avr_sim --library ./lib/normal.
I'm unsure how to inform the compiler about the extra available memory and I would appreciate your guidance.
2:Before using Serial.println, I always use Serial.begin(115200); However, I'm uncertain whether additional code configurations are required on the avr8js end. I haven't seen related code in various examples, and have tried to find answers within the source code of avr8js. However, due to my limited technical skills, I have yet to find a solution. Below is the code to create Mega2560
const FLASH = 0x40000; // ATmega2560 params
export class AVRRunner {
program = new Uint16Array(FLASH);
cpu;
timer;
portB;
portC;
portD;
stopped = false;
constructor(hex ) {
loadHex(hex, new Uint8Array(this.program.buffer));
this.cpu = new CPU(this.program, 0x8200);
this.freqHz = 16e6;
this.timer = new AVRTimer(this.cpu, {
...timer0Config,
compAInterrupt: 0x02a,
compBInterrupt: 0x02c,
ovfInterrupt: 0x02e,
});
// this.timer= new AVRTimer(this.cpu, timer0Config);
this.portB = new AVRIOPort(this.cpu, portBConfig);
this.portC = new AVRIOPort(this.cpu, portCConfig);
this.portD = new AVRIOPort(this.cpu, portDConfig);
this.usart = new AVRUSART(this.cpu, usart0Config, this.freqHz);
}
3: I'm delighted to hear about a more accurate clock version for rp2040 and look forward to it. I find the API for rp2040 more convenient to use, for instance:
rp2040.gpio[13].addListener((state) => {});
rp2040.uart[0].onByte=()=>{}
Also, the logger functionality of rp2040 allows easier monitoring of firmware run errors, which is incredibly convenient
To tell the Arduino CLI about the extra memory use the --build-property upload.maximum_data_size=
flags, e.g.:
arduino-cli compile --fqbn arduino:avr:uno --build-property upload.maximum_data_size=8192 ./avr_sim --library ./lib/normal
For the ATmega2560, the interrupt numbers are different. So you'd want to configure the UART with the relevant interrupt numbers, e.g.:
this.usart = new AVRUSART(this.cpu, {
...usart0Config,
rxCompleteInterrupt: 0x32,
dataRegisterEmptyInterrupt: 0x34,
txCompleteInterrupt: 0x36,
}, this.freqHz);
I hope this helps!
Thank you very much, the Serial of the mega2560 is working perfectly now. I'll take some time to test the memory expansion of Uno. Your assistance has been of paramount importance to me, and I want to express my gratitude once again. Once my project is completed, I'll provide you with the online address as soon as possible to share my joy.
Awesome! Closing this issue for now, and looking forward to seeing what you are building
Project Background:
To satisfy this need, I tried the following ways:
In summary, I only need a simulator with enough memory to run hex. However, due to the lack of simulation technology and hardware knowledge, I have spent a lot of time on this issue and still have not found a good solution. If there is an ideal choice, I still hope to have a running environment of UNO simulator with 4KB, or 8KB or even higher. What should I do?