MaslowCNC / Firmware

Maslow Firmware
GNU General Public License v3.0
261 stars 136 forks source link

Add support for running in simavr #396

Closed idoc closed 6 years ago

idoc commented 6 years ago

Simavr is a simulator for the AVR family of microcontrollers (https://github.com/buserror/simavr). Running Maslow firmware in simavr is useful for automated testing in a CI loop and debugging in GDB.

This is the next step in #363.

These commit works around two issues with simavr:

  1. The simulated UART crashes if you don't flush often, so we flush after every character written to Serial.
  2. Our TimerOne class causes the simulator to hang, so I moved the call to runsOnATimer() into loop(). This means runsOnATimer() will be called less frequently, but I think that's OK for the simulated environment.
BarbourSmith commented 6 years ago

Looks great! Its fun to see how quickly this is progressing πŸ‘ πŸ‘

blurfl commented 6 years ago

Under normal non-simavr use does the [env:simavr] section in platformio.ini need to be commented out to prevent platformio from building and uploading to the mega?

Looking for upload port... Auto-detected: /dev/cu.usbmodem1411 Uploading .pioenvs/simavr/firmware.hex

idoc commented 6 years ago

Oh dang. I was so focused on getting simavr to work, I totally forgot to test the full workflow on a real Arduino...

I have a PR to disable the upload for simavr. I still need to test it with an Arduino plugged in, so I won’t be able to upload it till I get home this evening.

On Mon, Feb 19, 2018 at 11:47 PM Scott Smith notifications@github.com wrote:

Under normal non-simavr use does the [env:simavr] section in platformio.ini need to be commented out to prevent platformio from building and uploading to the mega?

Looking for upload port... Auto-detected: /dev/cu.usbmodem1411 Uploading .pioenvs/simavr/firmware.hex

β€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MaslowCNC/Firmware/pull/396#issuecomment-366892527, or mute the thread https://github.com/notifications/unsubscribe-auth/ABxOEylMY_kkiICY97l04zbGYUxT73Fnks5tWniLgaJpZM4SKEOG .

blurfl commented 6 years ago

Thanks for the PlatformIO setup, it offers some interesting options. I'm also interested in getting a simavr environment set up for the Teensy 3.5 & 3.6 boards. Getting PlatformIO set up for those was easy, and commenting out the unwanted sections of platformio.ini seemed to be the way to 'steer' the operation.

idoc commented 6 years ago

@blurfl I created GH-397, which turns the upload into a no-op for simavr. I don't have an Arduino at work to fully test this, but you might want to take a look and see if can help your workflow.

When we can, I think it's best to avoid commenting and uncommenting committed files. It's too easy to forget to reset the files before committing a change, and breaking other people's workflow. What do you think about using a custom script, similar to my 'simavr_env_for_platformio.py' for controlling behavior based on environment variables (set in your .profile or similar)?

This sort of thing might be useful if you want your Teensy environment to upload to your device, but assume that most others will want to skip it.

Oh, and ignore the 'upload_port' line I put in 'platformio.ini'. I should have deleted it before pushing. It's only necessary when testing 'pio run -t upload' on a computer with no Arduino plugged in. Normally, we would want this command to fail if you have nothing plugged in.

blurfl commented 6 years ago

I'll test the PR and report. I'd be glad to use a script, it sounds like a good idea.