Skip to content

Commit c714c78

Browse files
DRuffernashif
authored andcommitted
twister: Allow baud rates other than 115200
Fixes zephyrproject-rtos#38046 Document the changes in twister.rst Add baud rate to debug message in twister Add baud parameter to twister's add_device function Set the twister baud rate from input parameters Use 115200 as the default baud rate if not specified Add baud to the hwmap-schema.yaml file Add --device-serial-baud to twister arguments Fix compliance issues Fix mistake in parameter name from device-baud to device-serial-baud Refactoring of the code in orded to simplify the logic and clear multiple definitions of the default baud rate. Signed-off-by: Maciej Perkowski <Maciej.Perkowski@nordicsemi.no> Signed-off-by: Dennis Ruffer <daruffer@gmail.com>
1 parent 18f26b8 commit c714c78

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

doc/guides/test/twister.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ To run the script in the local tree, follow the steps below:
4141
$ source zephyr-env.sh
4242
$ ./scripts/twister
4343

44-
If you have a system with a large number of cores, you can build and run
45-
all possible tests using the following options:
44+
If you have a system with a large number of cores and plenty of free storage space,
45+
you can build and run all possible tests using the following options:
4646

4747
::
4848

@@ -512,21 +512,24 @@ Executing tests on a single device
512512
To use this feature on a single connected device, run twister with
513513
the following new options::
514514

515-
scripts/twister --device-testing --device-serial /dev/ttyACM0 -p \
516-
frdm_k64f -T tests/kernel
515+
scripts/twister --device-testing --device-serial /dev/ttyACM0 \
516+
--device-serial-baud 9600 -p frdm_k64f -T tests/kernel
517517

518518
The ``--device-serial`` option denotes the serial device the board is connected to.
519519
This needs to be accessible by the user running twister. You can run this on
520520
only one board at a time, specified using the ``--platform`` option.
521521

522+
The ``--device-serial-baud`` option is only needed if your device does not run at
523+
115200 baud.
524+
522525

523526
Executing tests on multiple devices
524527
===================================
525528

526529
To build and execute tests on multiple devices connected to the host PC, a
527530
hardware map needs to be created with all connected devices and their
528-
details such as the serial device and their IDs if available. Run the following
529-
command to produce the hardware map::
531+
details such as the serial device, baud and their IDs if available.
532+
Run the following command to produce the hardware map::
530533

531534
./scripts/twister --generate-hardware-map map.yml
532535

@@ -558,12 +561,16 @@ this example we are using a reel_board and an nrf52840dk_nrf52840::
558561
product: DAPLink CMSIS-DAP
559562
runner: pyocd
560563
serial: /dev/cu.usbmodem146114202
564+
baud: '9600'
561565
- connected: true
562566
id: 000683759358
563567
platform: nrf52840dk_nrf52840
564568
product: J-Link
565569
runner: nrfjprog
566570
serial: /dev/cu.usbmodem0006837593581
571+
baud: '9600'
572+
573+
The baud entry is only needed if not running at 115200.
567574

568575
If the map file already exists, then new entries are added and existing entries
569576
will be updated. This way you can use one single master hardware map and update

scripts/pylib/twister/twisterlib.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ def handle(self):
733733
else:
734734
serial_device = hardware.serial
735735

736-
logger.debug("Using serial device {}".format(serial_device))
736+
logger.debug("Using serial device {} @ {} baud".format(serial_device, hardware.serial_baud))
737737

738738
if (self.suite.west_flash is not None) or runner:
739739
command = ["west", "flash", "--skip-rebuild", "-d", self.build_dir]
@@ -790,7 +790,7 @@ def handle(self):
790790
try:
791791
ser = serial.Serial(
792792
serial_device,
793-
baudrate=115200,
793+
baudrate=hardware.serial_baud,
794794
parity=serial.PARITY_NONE,
795795
stopbits=serial.STOPBITS_ONE,
796796
bytesize=serial.EIGHTBITS,
@@ -3926,10 +3926,12 @@ def _generate(self, outdir, coveragelog):
39263926
["-o", os.path.join(subdir, "index.html")],
39273927
stdout=coveragelog)
39283928

3929+
39293930
class DUT(object):
39303931
def __init__(self,
39313932
id=None,
39323933
serial=None,
3934+
serial_baud=None,
39333935
platform=None,
39343936
product=None,
39353937
serial_pty=None,
@@ -3940,6 +3942,9 @@ def __init__(self,
39403942
runner=None):
39413943

39423944
self.serial = serial
3945+
self.serial_baud = 115200
3946+
if serial_baud:
3947+
self.serial_baud = serial_baud
39433948
self.platform = platform
39443949
self.serial_pty = serial_pty
39453950
self._counter = Value("i", 0)
@@ -4031,8 +4036,8 @@ def __init__(self):
40314036
self.detected = []
40324037
self.duts = []
40334038

4034-
def add_device(self, serial, platform, pre_script, is_pty):
4035-
device = DUT(platform=platform, connected=True, pre_script=pre_script)
4039+
def add_device(self, serial, platform, pre_script, is_pty, baud=None):
4040+
device = DUT(platform=platform, connected=True, pre_script=pre_script, serial_baud=baud)
40364041

40374042
if is_pty:
40384043
device.serial_pty = serial
@@ -4052,13 +4057,15 @@ def load(self, map_file):
40524057
id = dut.get('id')
40534058
runner = dut.get('runner')
40544059
serial = dut.get('serial')
4060+
baud = dut.get('baud', None)
40554061
product = dut.get('product')
40564062
fixtures = dut.get('fixtures', [])
40574063
new_dut = DUT(platform=platform,
40584064
product=product,
40594065
runner=runner,
40604066
id=id,
40614067
serial=serial,
4068+
serial_baud=baud,
40624069
connected=serial is not None,
40634070
pre_script=pre_script,
40644071
post_script=post_script,

scripts/schemas/twister/hwmap-schema.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ sequence:
3030
"serial":
3131
type: str
3232
required: false
33+
"baud":
34+
type: int
35+
required: false
3336
"post_script":
3437
type: str
3538
required: false

scripts/twister

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ logger.setLevel(logging.DEBUG)
214214
def size_report(sc):
215215
logger.info(sc.filename)
216216
logger.info("SECTION NAME VMA LMA SIZE HEX SZ TYPE")
217-
for i in range(len(sc.sections)):
217+
for i in enumerate(sc.sections):
218218
v = sc.sections[i]
219219

220220
logger.info("%-17s 0x%08x 0x%08x %8d 0x%05x %-7s" %
@@ -621,6 +621,10 @@ structure in the main Zephyr tree: boards/<arch>/<board_name>/""")
621621
"-X", "--fixture", action="append", default=[],
622622
help="Specify a fixture that a board might support")
623623

624+
parser.add_argument(
625+
"--device-serial-baud", action="store", default=None,
626+
help="Serial device baud rate (default 115200)")
627+
624628
serial = parser.add_mutually_exclusive_group()
625629
serial.add_argument("--device-serial",
626630
help="""Serial device for accessing the board
@@ -925,9 +929,11 @@ def main():
925929
if options.platform and len(options.platform) == 1:
926930
if options.device_serial:
927931
hwm.add_device(options.device_serial,
928-
options.platform[0],
929-
options.pre_script,
930-
False)
932+
options.platform[0],
933+
options.pre_script,
934+
False,
935+
baud=options.device_serial_baud
936+
)
931937
else:
932938
hwm.add_device(options.device_serial_pty,
933939
options.platform[0],

0 commit comments

Comments
 (0)