Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/renode: add support for target reset #19375

Merged
merged 1 commit into from
Mar 10, 2023

Conversation

aabadie
Copy link
Contributor

@aabadie aabadie commented Mar 10, 2023

Contribution description

This PR adds support for the reset target when emulating a board with renode. This feature can be used when using renode 1.12 and above versions.

The default emulator listens on port 1234 but this can be overridden on command line using RENODE_TELNET_PORT. I don't think it's possible to use a Unix socket instead.

Testing procedure

Tested this with emulated hifive1b and cc1538dk boards:

Start an emulated application in one terminal:
$ EMULATE=1 make BOARD=hifive1b -C examples/default flash term --no-print-directory 
Building application "default" for "hifive1b" with MCU "fe310".

"make" -C /work/riot/RIOT/boards/common/init
"make" -C /work/riot/RIOT/boards/hifive1b
"make" -C /work/riot/RIOT/core
"make" -C /work/riot/RIOT/core/lib
"make" -C /work/riot/RIOT/cpu/fe310
"make" -C /work/riot/RIOT/cpu/fe310/periph
"make" -C /work/riot/RIOT/cpu/fe310/vendor
"make" -C /work/riot/RIOT/cpu/riscv_common
"make" -C /work/riot/RIOT/cpu/riscv_common/periph
"make" -C /work/riot/RIOT/drivers
"make" -C /work/riot/RIOT/drivers/periph_common
"make" -C /work/riot/RIOT/drivers/saul
"make" -C /work/riot/RIOT/drivers/saul/init_devs
"make" -C /work/riot/RIOT/sys
"make" -C /work/riot/RIOT/sys/auto_init
"make" -C /work/riot/RIOT/sys/div
"make" -C /work/riot/RIOT/sys/fmt
"make" -C /work/riot/RIOT/sys/isrpipe
"make" -C /work/riot/RIOT/sys/libc
"make" -C /work/riot/RIOT/sys/malloc_thread_safe
"make" -C /work/riot/RIOT/sys/newlib_syscalls_default
"make" -C /work/riot/RIOT/sys/phydat
"make" -C /work/riot/RIOT/sys/preprocessor
"make" -C /work/riot/RIOT/sys/ps
"make" -C /work/riot/RIOT/sys/rtc_utils
"make" -C /work/riot/RIOT/sys/saul_reg
"make" -C /work/riot/RIOT/sys/shell
"make" -C /work/riot/RIOT/sys/shell/cmds
"make" -C /work/riot/RIOT/sys/stdio_uart
"make" -C /work/riot/RIOT/sys/tsrb
   text	   data	    bss	    dec	    hex	filename
  15552	   4120	   2340	  22012	   55fc	/work/riot/RIOT/examples/default/bin/hifive1b/default.elf
/work/riot/RIOT/dist/tools/emulator/term.sh renode hifive1b /work/riot/RIOT/examples/default /work/riot/RIOT/dist/tools/pyterm/pyterm '-p "/tmp/riot_default_hifive1b.N6dXi/uart" -b "115200" ' /tmp/riot_default_hifive1b.N6dXi/uart /tmp/riot_default_hifive1b.N6dXi 
Using Renode pid file /tmp/riot_default_hifive1b.N6dXi/emulator_pid
renode -e "set image_file '/work/riot/RIOT/examples/default/bin/hifive1b/default.elf'" -e "include @/work/riot/RIOT/boards/hifive1b/dist/board.resc" --pid-file /tmp/riot_default_hifive1b.N6dXi/emulator_pid --hide-log -e "logLevel 2  " -P 1234 --disable-xwt -e "emulation CreateUartPtyTerminal \"term\" \"/tmp/riot_default_hifive1b.N6dXi/uart\" true" -e "connector Connect sysbus.uart0 term" -e start
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2023-03-10 10:43:34,808 # Connect to serial port /tmp/riot_default_hifive1b.N6dXi/uart
Welcome to pyterm!
Type '/exit' to exit.
help
2023-03-10 10:43:37,068 # help
2023-03-10 10:43:37,068 # Command              Description
2023-03-10 10:43:37,068 # ---------------------------------------
2023-03-10 10:43:37,069 # pm                   interact with layered PM subsystem
2023-03-10 10:43:37,069 # ps                   Prints information about running threads.
2023-03-10 10:43:37,069 # reboot               Reboot the node
2023-03-10 10:43:37,069 # rtc                  control RTC peripheral interface
2023-03-10 10:43:37,070 # saul                 interact with sensors and actuators using SAUL
2023-03-10 10:43:37,070 # version              Prints current RIOT_VERSION
> 2023-03-10 10:43:50,844 # main(): This is RIOT! (Version: 2023.04-devel-636-g7ab8d6-pr/tools/renode_reset)
2023-03-10 10:43:50,844 # Welcome to RIOT!
2023-03-10 10:44:25,827 # main(): This is RIOT! (Version: 2023.04-devel-636-g7ab8d6-pr/tools/renode_reset)
2023-03-10 10:44:25,827 # Welcome to RIOT!


Reset the emulated board from another terminal::
$ EMULATE=1 make BOARD=hifive1b -C examples/hello-world reset --no-print-directory 
bash -c "{ sleep 0.2;echo machine RequestReset; } | telnet localhost 1234" || true
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
chine RequestReset
(SiFive-FE310) Connection closed by foreign host.
$ EMULATE=1 make BOARD=hifive1b -C examples/hello-world reset --no-print-directory 
bash -c "{ sleep 0.2;echo machine RequestReset; } | telnet localhost 1234" || true
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
chine RequestReset
(SiFive-FE310) Connection closed by foreign host.

One can see that the emulated RIOT application is rebooted twice.

Issues/PRs references

None

@github-actions github-actions bot added Area: build system Area: Build system Area: tools Area: Supplementary tools labels Mar 10, 2023
@aabadie aabadie added CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Mar 10, 2023
@riot-ci
Copy link

riot-ci commented Mar 10, 2023

Murdock results

✔️ PASSED

7ab8d61 tools/renode: add support for target reset

Success Failures Total Runtime
1 0 1 01m:05s

Artifacts

@benpicco
Copy link
Contributor

bors merge

bors bot added a commit that referenced this pull request Mar 10, 2023
19371: sys/usbus: check for the number of required and provided EPs in static configurations r=benpicco a=gschorcht

### Contribution description

This PR provides a static check at compile time whether the number of EPs required in a static configuration does not exceed the number of EPs provided by the USB device.

#### Background

In issue #19359 the problem was reported that `usbus_cdc_ecm` didn't work together with `stdio_cdc_acm` on some STM32 boards. The reason for some of the boards was simply that the application tried to allocate more EPs than available and simply ignored this and just didn't work.

#### Solution

Since `auto_init_usb` uses a static configuration with exactly one USBUS stack instance and one USB device, at least in case `auto_init` is used a static check can be carried out to make sure that the number of EPs required by the application doesn't exceed the number of EPs provided by the USB device. For this purpose, each `usbus_*` module defines the number of IN and OUT EPs required by that module. Each USB device driver defines the number of EPs provided by USB device if it differs from the default of 8 EPs. During the auto initialization the total number of required IN and OUT EPs is then compared with the number of EPs provided by the USB device using a static assert.

### Testing procedure

1. Green CI
2. Compilation of
   ```python
   USEMODULE='stdio_cdc_acm' BOARD=nucleo-f439zi make -j8 -C tests/usbus_cdc_ecm
   ```
   should lead to compilation error
   ```python
   sys/auto_init/usb/auto_init_usb.c:81:1: error: static assertion failed: "Number of required IN endpoints exceeded"
    _Static_assert(USBUS_EP_IN_REQUIRED_NUMOF <= USBDEV_NUM_ENDPOINTS,
    ^~~~~~~~~~~~~~
   Makefile.base:146: recipe for target 'tests/usbus_cdc_ecm/bin/nucleo-f439zi/auto_init_usbus/auto_init_usb.o' failed
   ```
   while compilation of
   ```
   USEMODULE='stdio_cdc_acm' BOARD=nucleo-f767zi make -j8 -C tests/usbus_cdc_ecm
   ```
   should work.

### Issues/PRs references

Fixes issue #19359 partially.

19374: makefiles/boards/stm32: fix DFU_USB_ID handling r=benpicco a=gschorcht

### Contribution description

This PR fixes the still existing problem that an application can't be flashed to a STM32 board if it uses `riotboot_dfu` with default  VID/PID (1209:7d02).

In PR #18964 item 1, the problem was already described that an application can't be flashed on a board that is using `riotboot_dfu`. Using for example
```python
FEATURES_REQUIRED+=riotboot USEMODULE+=usbus_dfu make -C examples/saul BOARD=nucleo-f767zi \
PROGRAMMER=dfu-util all riotboot/flash-slot0
```
always leads to error
```python
/home/gs/src/RIOT-Xtensa-ESP.esp-idf-4.4/makefiles/boards/stm32.inc.mk:28: *** DFU_USB_ID is not set.  Stop.
/home/gs/src/RIOT-Xtensa-ESP.esp-idf-4.4/makefiles/boot/riotboot.mk:87: recipe for target 'riotboot/bootloader/binfile' failed
```
even if `DFU_USB_ID` variable is set as described in documentation.
```python
FEATURES_REQUIRED+=riotboot USEMODULE+=usbus_dfu make -C examples/saul BOARD=nucleo-f767zi \
PROGRAMMER=dfu-util DFU_USB_ID=1209:7d02 all riotboot/flash-slot0
```
The reason is that the variable `DFU_USB_ID` isn't exported and the check https://github.com/RIOT-OS/RIOT/blob/8dc8bf35678493ecc8ef110e2f0359a67c03894c/makefiles/boards/stm32.inc.mk#L27-L29 sees an empty `DFU_USB_ID` variable here. It prevents to use `dfu-util` event though the following `dfu-util.mk` will generate a default value for this variable from the `USB_VID` and `USB_PID` variables if necessary.

Commit 6a76b94 of PR #18964 tried to fix this problem but wasn't merged for any reason.

To fix this problem, the check is completely removed. If a board such as `weact-f4x1cx` uses a DFU boorloader and requires a certain VID/PID combination, board's makefile is responsible to set `DFU_USB_ID` variable.

### Testing procedure

It is not necessary to use a real boad, checking the compilation process is sufficient.

1. Using default VID/PID as described in documentation:
   ```python
   FEATURES_REQUIRED+=riotboot USEMODULE+=usbus_dfu make -C examples/saul BOARD=nucleo-f767zi \
   PROGRAMMER=dfu-util all riotboot/flash-slot0
   ```
   can't be compiled without this PR but calls `dfu-util` correctly with this PR using the default VID/PID:
   ```python
   dfu-util --device 1209:7d02 --alt 0 --download examples/saul/bin/nucleo-f767zi/riotboot_files/slot0.1678440536.bin
   ```
2. Using a VID/PID as described in documentation:
   ```python
   FEATURES_REQUIRED+=riotboot USEMODULE+=usbus_dfu make -C examples/saul BOARD=nucleo-f767zi \
   DFU_USB_ID=1209:affe PROGRAMMER=dfu-util all riotboot/flash-slot0
   ```
   can't be compiled without this PR but calls `dfu-util` correctly with this PR using the default VID/PID:
   ```python
   dfu-util --device 1209:affe --alt 0 --download examples/saul/bin/nucleo-f767zi/riotboot_files/slot0.1678440536.bin
   ```
3. Compiling a board with DFU bootloader
   ```python
   make -C examples/saul flash BOARD=weact-f411ce
   ```
   should still call dfu-util with correct VID/PID:
   ```python
   dfu-util --device 0483:df11 --alt 0 --download /home/gs/src/RIOT-Xtensa-ESP.esp-idf-4.4/examples/saul/bin/weact-f411ce/saul_example.bin  --dfuse-address 0x8000000:leave
   ```
### Issues/PRs references



19375: tools/renode: add support for target reset r=benpicco a=aabadie



19376: boards/stm32f4discovery: use default port to access stdio via cdc acm r=benpicco a=aabadie



19377: pkg/tinyusb: fix default VID/PID configuration r=benpicco a=gschorcht

### Contribution description

This PR fixes the default VID/PID configuration if tinyUSB board reset feature is used.

While reviewing PR #19086 I was wondering why `esp32s2-wemos-mini` requires to set `USB_VID`/`USB_PID` explicitly to  `USB_VID_TESTING`/`USB_PID_TESTING`. The reason was that tinyUSB board reset feature wasn't declared as RIOT internal.

### Testing procedure

Flashing `esp32s2-wemos-mini` should still work.
```
BOARD=esp32s2-wemos-mini make -C tests/shell flash
```
The VID/PID should be `1209:7d00` and not `1209:7d01`.

### Issues/PRs references



Co-authored-by: Gunar Schorcht <[email protected]>
Co-authored-by: Alexandre Abadie <[email protected]>
@bors
Copy link
Contributor

bors bot commented Mar 10, 2023

Build failed (retrying...):

@bors
Copy link
Contributor

bors bot commented Mar 10, 2023

Build succeeded:

@bors bors bot merged commit 8c23917 into RIOT-OS:master Mar 10, 2023
@MrKevinWeiss MrKevinWeiss added this to the Release 2023.04 milestone Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants