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

new simulated board: nrf52_bsim #9988

Merged
merged 12 commits into from
Oct 15, 2018
Merged

Conversation

aescolar
Copy link
Member

@aescolar aescolar commented Sep 14, 2018

new simulated board: nrf52_bsim
Added a new simulated board, which models the NRF52832 SOC.

Its main use is for workstation testing and simulation of
the BLE stack and any application which relies mostly on it.

It uses BabbleSim (http://Babblesim.github.io) for the radio
simulation.
And the NRF52 HW models hosted in that same GitHub organization:
https://github.com/BabbleSim/ext_NRF52_hw_models

For speed it uses the POSIX arch to (not) emulate the CPU.
It uses Vanilla Zephyr, with a couple of configuration differences:

  • It uses (like other POSIX arch boards) the system libC
  • It does not use the nrfx hosted by Zehpyr in ext/, but the one
    provided by the HW models.
    Otherwise it relies in the same drivers as the real NRF52 boards.

Quick hands on:

Assuming you want to have BabbleSim in ${HOME}/playground/bsim

mkdir -p ${HOME}/playground/bsim && cd ${HOME}/playground/bsim
# You need android's repo ( https://source.android.com/setup/develop/repo ) 
# Nordic guys: You need ssh access to GitHub.. (if you can't, do "repo init -u https://github.com/BabbleSim/manifest.git -m zephyr_ci.xml -b master")
repo init -u git@github.com:BabbleSim/manifest.git -m everything.xml -b master
repo sync
make everything -j 8
# patiently wait 1min

Now, you just go to Zephyr (pick this branch), and before compiling or running sanitycheck you set

export BSIM_OUT_PATH=${HOME}/playground/bsim/
export BSIM_COMPONENTS_PATH=${HOME}/playground/bsim/components/

You are good to go. Compile whatever you want targeting nrf52_bsim
The resulting exe can just be run stand alone without options (and you get a warning about not connecting to the BabbleSim phy)

If you want to see BLE activity (a bit more fun) you can either build each by hand and copy it out to the bsim/bin directory given them a reasonable name, or use a silly Makefile I left in bsim/components/ext_zephyr_app_builder/.
Assuming the second:

export BOARD=nrf52_bsim
export ZEPHYR_BASE=<wherever you have Zephyr>
cd ~/playground/bsim/components/ext_zephyr_app_builder/
make APP=samples/bluetooth/central_hr install
make APP=samples/bluetooth/peripheral install

And you run them:

cd ~/playground/bsim/bin/
./bs_nrf52_bsim_samples_bluetooth_peripheral -s=Hola -d=0 &
./bs_nrf52_bsim_samples_bluetooth_central_hr -s=Hola -d=1 &
./bs_2G4_phy_v1 -s=Hola -D=2 -sim_length=10e6 &

You should get something like so:

d_00: @00:00:00.000000  ***** Booting Zephyr OS v1.9.0-7263-g0affa09 *****
d_00: @00:00:00.000000  [bt] [INF] hci_vs_init: HW Platform: Nordic Semiconductor (0x0002)
d_00: @00:00:00.000000  [bt] [INF] hci_vs_init: HW Variant: nRF52x (0x0002)
d_00: @00:00:00.000000  [bt] [INF] hci_vs_init: Firmware: Standard Bluetooth controller (0x00) Version 1.13 Build 99
d_00: @00:00:00.000000  [bt] [WRN] bt_setup_id_addr: No static addresses stored in controller
d_01: @00:00:00.000000  ***** Booting Zephyr OS v1.9.0-7263-g0affa09 *****
d_00: @00:00:00.002528  [bt] [INF] bt_dev_show_info: Identity: e0:3b:58:29:c3:12 (random)
d_00: @00:00:00.002528  [bt] [INF] bt_dev_show_info: HCI: version 5.0 (0x09) revision 0x0000, manufacturer 0x05f1
d_00: @00:00:00.002528  [bt] [INF] bt_dev_show_info: LMP: version 5.0 (0x09) subver 0xffff
d_01: @00:00:00.000000  [bt] [INF] hci_vs_init: HW Platform: Nordic Semiconductor (0x0002)
d_01: @00:00:00.000000  [bt] [INF] hci_vs_init: HW Variant: nRF52x (0x0002)
d_01: @00:00:00.000000  [bt] [INF] hci_vs_init: Firmware: Standard Bluetooth controller (0x00) Version 1.13 Build 99
d_00: @00:00:00.004448  [bt] [WRN] irk_init: Using temporary IRK
d_00: @00:00:00.004448  Bluetooth initialized
d_01: @00:00:00.000000  [bt] [WRN] bt_setup_id_addr: No static addresses stored in controller
d_00: @00:00:00.005048  Advertising successfully started
d_01: @00:00:00.002528  [bt] [INF] bt_dev_show_info: Identity: cf:71:44:b1:06:6e (random)
d_01: @00:00:00.002528  [bt] [INF] bt_dev_show_info: HCI: version 5.0 (0x09) revision 0x0000, manufacturer 0x05f1
d_01: @00:00:00.002528  [bt] [INF] bt_dev_show_info: LMP: version 5.0 (0x09) subver 0xffff
d_01: @00:00:00.002528  Bluetooth initialized
d_01: @00:00:00.003488  Scanning successfully started
d_01: @00:00:00.007009  [DEVICE]: 7a:2c:95:7a:2c:95 (random), AD evt type 0, AD data len 29, RSSI -35
d_01: @00:00:00.007009  [AD]: 1 data_len 1
d_01: @00:00:00.007009  [AD]: 3 data_len 6
d_01: @00:00:00.115382  Connected: 7a:2c:95:7a:2c:95 (random)
d_00: @00:00:00.115884  Connected
d_01: @00:00:00.118849  [ATTRIBUTE] handle 10
d_01: @00:00:00.168728  [ATTRIBUTE] handle 11
d_01: @00:00:00.218848  [ATTRIBUTE] handle 13
d_01: @00:00:00.218848  [SUBSCRIBED]
d_01: @00:00:01.017424  [NOTIFICATION] data 0x080a34ab length 2
d_01: @00:00:02.017424  [NOTIFICATION] data 0x080a34ab length 2
[..]
d_01: @00:00:08.067424  [NOTIFICATION] data 0x080a34ab length 2
d_01: @00:00:09.117424  [NOTIFICATION] data 0x080a34ab length 2

Now you can go wild and run either (or both) in gdb, valgrind or whatever you fancy.

@aescolar aescolar added the DNM This PR should not be merged (Do Not Merge) label Sep 14, 2018
@aescolar aescolar requested a review from dbkinder as a code owner September 14, 2018 15:29
@aescolar aescolar removed the request for review from dbkinder September 14, 2018 15:35
@aescolar aescolar requested a review from dbkinder September 15, 2018 08:47
@aescolar
Copy link
Member Author

aescolar commented Sep 15, 2018

@dbkinder : The documentation cannot be built yet, I need to fix the kconfig of this board
But if you are ok with starting the review with only the rst files I'd be happy to get your feedback.

The documentation builds now.

@aescolar aescolar force-pushed the nrf52_bsim1 branch 3 times, most recently from 8d90325 to 323bacc Compare September 16, 2018 17:13
@aescolar aescolar force-pushed the nrf52_bsim1 branch 7 times, most recently from 15cb04c to 2f42c57 Compare September 16, 2018 19:57
@aescolar
Copy link
Member Author

aescolar commented Sep 17, 2018

@nashif : If we run coverage in both native_posix and this board, we have too many tests with coverage and they spill to the 2nd CI instance (at least in this run with 7 instances). As we only collect coverage data from the 1st instance, that would lead to the coverage reports jumping up and down.

@aescolar
Copy link
Member Author

The coverage results are here: https://codecov.io/gh/zephyrproject-rtos/zephyr/pull/9988

@aescolar aescolar added Enhancement Changes/Updates/Additions to existing features area: Bluetooth labels Sep 17, 2018
@carlescufi carlescufi requested a review from ioannisg September 17, 2018 15:09
@aescolar
Copy link
Member Author

aescolar commented Oct 4, 2018

recheck

Copy link
Collaborator

@ulfalizer ulfalizer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kconfig parts look fine.

@aescolar aescolar force-pushed the nrf52_bsim1 branch 2 times, most recently from 5c2a5b9 to 040b090 Compare October 5, 2018 17:45
@aescolar aescolar changed the title [DNM] new simulated board: nrf52_bsim new simulated board: nrf52_bsim Oct 5, 2018
@aescolar aescolar removed the DNM This PR should not be merged (Do Not Merge) label Oct 5, 2018
@aescolar
Copy link
Member Author

aescolar commented Oct 5, 2018

recheck

@aescolar
Copy link
Member Author

aescolar commented Oct 7, 2018

From my point of view this is ready to merge. So feel free to press the button.
I just made this new board not default to avoid adding too much extra load to the CI runs.

@@ -11,3 +11,19 @@ osource "$(SOC_DIR)/$(ARCH)/Kconfig"
osource "$(SOC_DIR)/$(ARCH)/*/Kconfig"

endmenu

# The helper symbols below are put here due to an unusual setup: The simulated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a better spot for this, we should not have soc specific kconfigs in a general file such as soc/Kconfig.
Also, I would do "select SOC_COMPATIBLE_NRF" in the SOC_FAMIL_NRF config instead of this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I would do "select SOC_COMPATIBLE_NRF" in the SOC_FAMIL_NRF config instead of this.

Ok.

Need a better spot for this, we should not have soc specific kconfigs in a general file such as soc/Kconfig.

Do you have a better place in mind? (please consider this comment from Ulf: #9988 (comment) )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, can't think of a better solution now, will revisit.

hal/nrf5/cntr.c
hal/nrf5/ecb.c
hal/nrf5/radio/radio.c
hal/nrf5/mayfly.c
hal/nrf5/ticker.c
)


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra new line

.shippable.yml Outdated
@@ -34,6 +34,16 @@ build:
if [ "$IS_PULL_REQUEST" = "true" ]; then
git rebase origin/${PULL_REQUEST_BASE_BRANCH};
fi
- >
export NRF_HW_MODELS_VERSION=`cat boards/posix/nrf52_bsim/hw_models_version`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better define this under global section

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can have this guy defined before the rebase just above.
But I moved it into its own line to make it more visible.

.shippable.yml Outdated
- >
export NRF_HW_MODELS_VERSION=`cat boards/posix/nrf52_bsim/hw_models_version`;
pushd . ;
export BSIM_OUT_PATH=/opt/bsim/ ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

.shippable.yml Outdated
export NRF_HW_MODELS_VERSION=`cat boards/posix/nrf52_bsim/hw_models_version`;
pushd . ;
export BSIM_OUT_PATH=/opt/bsim/ ;
export BSIM_COMPONENTS_PATH=${BSIM_OUT_PATH}/components/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@aescolar aescolar force-pushed the nrf52_bsim1 branch 2 times, most recently from 16c1046 to 0a3be6b Compare October 12, 2018 13:59
@aescolar
Copy link
Member Author

recheck

These tests rely on compiling with one of the provided
C libraries which are not compiled for any
of the POSIX ARCH boards => balcklist based on the arch
and not on the board

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
posix_flush_stdout() must be provided by any board
using CONFIG_NATIVE_POSIX_CONSOLE, not just by those using
CONFIG_NATIVE_POSIX_STDOUT_CONSOLE

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Simulated NRF boards based on the POSIX ARCH cannot directly
use the current SOC_*NRF options as these pull options from
the ARM CPU and other peripherals.
This commit adds a new set of hidden SOC_COMPATIBLE_* options to
be selected both by the real SOCs and the simulated ones.
In this manner we can have the common code depend on the
SOC_COMPATIBLE* options instead of the current ones where
neccessary.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>

(f) arm kconfig
Depend on the new SOC_COMPATIBLE_NRF symbol instead of the
SOC_FAMILY_NRF symbol.

This allows the driver to be used from the bsim simulated board

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Simplify the Kconfig dependency for the nrf timer driver.
CLOCK_CONTROL_NRF5 depends on the SOC_FAMILY_NRF already.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
The simulator symbol was renamed.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Depend on the new SOC_COMPATIBLE_NRF symbol instead of the
SOC_FAMILY_NRF symbol.

This allows the driver to be used from the bsim simulated board

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
To allow the BLE stack to be used both in the real nRF platforms
and simulated ones, change the used macros in the code to the
COMPATIBLE ones.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Added a new simulated board, which models the NRF52832 SOC.

Its main use is for workstation testing and simulation of
the BLE stack and any application which relies mostly on it.

It uses BabbleSim (http://Babblesim.github.io) for the radio
simulation.
And the NRF52 HW models hosted in that same GitHub organization:
https://github.com/BabbleSim/ext_NRF52_hw_models

For speed it uses the POSIX arch to (not) emulate the CPU.
It uses Vanilla Zephyr, with a couple of configuration differences:
* It uses (like other POSIX arch boards) the system libC
* It does not use the nrfx hosted by Zehpyr in ext/, but the one
  provided by the HW models.
Otherwise it relies in the same drivers as the real NRF52 boards.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
To ensure we can always go back in time, let's explicitly list the
NRF52 HW models version which should be used with each version of
the nrf52_bsim board

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
To be able to collect all coverage reports from the "native"
applications in the first CI instance, let's also place the
nrf52_bsim testcases first. The order now is:
 unit_testing
 native_posix
 *_bsim
 anything else

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Use the docker image which has BabbleSim precompiled

Fetch the NRF52 hardware models required by the nrf52_bsim board
and compile them.

Collect the coverage report from the nrf52_bsim board

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
@nashif nashif merged commit 96b38ad into zephyrproject-rtos:master Oct 15, 2018
@aescolar aescolar deleted the nrf52_bsim1 branch October 15, 2018 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth Enhancement Changes/Updates/Additions to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants