Flashing Firmware Before Testing
Every setup needs to put the device into a known state prior to testing. Usually this means flashing firmware to your device under test. To do this, we will use HIL Extras to send the file to the gateway and then use a PyTest fixture to actually flash the firmware as a setup step to all testing.
Adding the Firmware as an Extra
To start, modify your .embedops/hil/config.yml
file to include your
firmware as an extra:
If your project uses multiple HEX files, simply add another extra.
Setting Up a Flash Fixture
Next, create a file <hil_root>/conftest.py
with the following contents (if you
already have a conftest.py
, add these lines):
This is a basic fixture that uses a J-Link to perform the flashing. We use
the hil_extras_get_path
fixture to get the actual path to the firmware file,
and then the JLinkInterface
from the HIL SDK to perform the flashing. You only
need to populate HIL_TARGET_DEVICE
with your target device name. The list of supported
devices can be found on Segger's website.
This string must be for a specific device and not a family (e.g., nRF52840_xxAA
).
Because of the decorator @pytest.fixture(autouse=True, scope="session")
,
the fixture will run automatically at the session level, which means it will
run only once, because there is only a single session event per test run.