Add WIP test script
Depends on having: 1. An STM32 Nucleo with an STM32L412RB connected 2. A serial device connected to that board 3. A JLink connected to that board (no the onboard ST-Link!) For now, there are some hardcoded paths, too.
This commit is contained in:
99
test/src/tr_test/test.py
Executable file
99
test/src/tr_test/test.py
Executable file
@@ -0,0 +1,99 @@
|
||||
# Copyright (C) 2020 Max Regan
|
||||
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
import pytest
|
||||
import subprocess
|
||||
import serial
|
||||
import serial.tools.list_ports
|
||||
import logging
|
||||
import pylink
|
||||
import time
|
||||
|
||||
from typing import List
|
||||
|
||||
SAMPLE_TIME_MS = 2500
|
||||
SAMPLES_PER_SEC = 12000000
|
||||
DRIVER = "fx2lafw"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def logger():
|
||||
logging.basicConfig()
|
||||
return logging.getLogger(__name__)
|
||||
|
||||
@pytest.fixture
|
||||
def context_factory():
|
||||
|
||||
def create_context(mcu: str, addr: int, fw_path: str, leave_halted: bool=False):
|
||||
ports = serial.tools.list_ports.comports()
|
||||
if len(ports) == 0:
|
||||
raise RuntimeError("No serial devices found")
|
||||
if len(ports) > 1:
|
||||
raise RuntimeError(
|
||||
"Too many serial devices, not sure which to use. "
|
||||
"This should be made configurable"
|
||||
)
|
||||
|
||||
jlink = pylink.jlink.JLink()
|
||||
jlink.open()
|
||||
jlink.disable_dialog_boxes()
|
||||
jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)
|
||||
jlink.connect(mcu)
|
||||
#jlink.set_reset_strategy(pylink.enums.JLinkResetStrategyCortexM3.HALT_AFTER_BTL)
|
||||
jlink.flash_file(fw_path, addr)
|
||||
assert jlink.halted()
|
||||
jlink.reset(halt=True)
|
||||
|
||||
serial_dev = serial.Serial(port=ports[0].device, baudrate=115200)
|
||||
|
||||
if not leave_halted:
|
||||
jlink.reset(halt=False)
|
||||
while True:
|
||||
try:
|
||||
serial_dev.read_until(b"HELLO WORLD!\r\n")
|
||||
except serial.serialutil.SerialException:
|
||||
continue
|
||||
break
|
||||
|
||||
return serial_dev, jlink
|
||||
|
||||
return create_context
|
||||
|
||||
|
||||
def test_serial(context_factory, logger):
|
||||
serial_dev, jlink = context_factory(
|
||||
"STM32L412RB",
|
||||
0x8000000,
|
||||
"/home/max/work/TimelyReference/firmware/watch.bin"
|
||||
)
|
||||
|
||||
lines = [serial_dev.readline().decode("ascii", errors="ignore") for _ in range(3)]
|
||||
logger.info("Test lines: {}".format(lines))
|
||||
|
||||
assert lines[0] == "Counter: 0\r\n"
|
||||
assert lines[1] == "HELLO WORLD!\r\n"
|
||||
assert lines[2] == "Counter: 1\r\n"
|
||||
|
||||
|
||||
def main():
|
||||
pytest.main()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user