Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Using pc-ble-driver-py on Raspberry Pi

This is a duplicate of this issue of pc-ble-driver-py repository.

While using pc-ble-driver-py on MacBook without problem, I face Error 13 when opening device on Raspberry Pi.
[OS]
latest stock RASPBIAN STRETCH LITE Version:June 2018
setup wifi & ssh

[DK]
PCA10028 V 1.1.0
PCA10040 V 0.9.0

[Command Line History]
--- on PC ---
scp -pr ~/Downloads/JLink_Linux_V632h_arm/ [email protected]:/home/pi
--- on Raspberry Pi ---
sudo cp /home/pi/JLink_Linux_V632h_arm/99-jlink.rules /etc/udev/rules.d/
sudo apt-get update
sudo apt-get dist-upgrade
mkdir /home/pi/boost
cd /home/pi/boost
wget https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.bz2
tar jxvf boost_1_65_1.tar.bz2
sudo apt install cmake swig git make gcc g++ libudev-dev python python-dev python-pip
export BOOST_ROOT=/home/pi/boost/boost_1_65_1/
cd $BOOST_ROOT
./bootstrap.sh
./b2 toolset=gcc cxxflags=-fPIC cflags=-fPIC address-model=32 link=static --with-thread --with-system --with-regex --with-date_time --with-chrono
cd /home/pi
git clone https://github.com/NordicSemiconductor/pc-ble-driver-py.git
cd pc-ble-driver-py/
git submodule init
git submodule update
cd build/
cmake -G "Unix Makefiles" ..
make
pip install wrapt
cd ../python/
cp pc_ble_driver_py/examples/advertising.py .
nano advertising.py # turn off auto flasher
python ./advertising.py NRF52 /dev/ttyACM0

[Result]
pi@raspberrypi:~/pc-ble-driver-py/python $ python ./advertising.py NRF52 /dev/ttyACM0
Serial port used: /dev/ttyACM0
Traceback (most recent call last):
File "./advertising.py", line 79, in
main(sys.argv[2])
File "./advertising.py", line 55, in main
driver.open()
File "/home/pi/pc-ble-driver-py/python/pc_ble_driver_py/ble_driver.py", line 127, in wrapper
raise NordicSemiException('Failed to {}. Error code: {}'.format(wrapped.name, err_code))
pc_ble_driver_py.exceptions.NordicSemiException: Failed to open. Error code: 13

  • add information printed from BLEDriver.log_message_handler:

    Serial port used: /dev/ttyACM0
    Successfully opened /dev/ttyACM0. Baud rate: 115200. Flow control: none. Parity: none.

    1/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    State change: STATE_START -> STATE_RESET

    2/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    1 -> []
    type: RESERVED_5 reliable: no seq#:0 ack#:0 payload_length:0 data_integrity:0 err_code:0
    3/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    State change: STATE_RESET -> STATE_UNINITIALIZED

    4/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    2 -> [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    3 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    5/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    4 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    6/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    5 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    7/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    6 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    8/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    7 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    9/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    8 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    10/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    9 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    11/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    10 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    12/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    11 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    13/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    12 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    14/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    13 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    15/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    14 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    16/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    15 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    17/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    16 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    18/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    17 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    19/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    18 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    20/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    19 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    21/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    20 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    22/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    21 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    23/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    22 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    24/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    23 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    25/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    24 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    26/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    25 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    27/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    26 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    28/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    27 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    29/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    28 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    30/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    29 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    31/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    30 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    32/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    31 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    33/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    32 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    33 -> [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    34/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    34 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    35 -> [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    35/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    36 -> [02 7d ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC_RESP]
    37 -> [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    State change: STATE_UNINITIALIZED -> STATE_FAILED

    36/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    37/ 0 <- [01 7e ]
    type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0
    [SYNC]
    Traceback (most recent call last):
    File "/home/pi/pc-ble-driver-py/python/pc_ble_driver_py/examples/heart_rate_collector.py", line 187, in <module>
    main(serial_port)
    File "/home/pi/pc-ble-driver-py/python/pc_ble_driver_py/examples/heart_rate_collector.py", line 149, in main
    collector.open()
    File "/home/pi/pc-ble-driver-py/python/pc_ble_driver_py/examples/heart_rate_collector.py", line 67, in open
    self.adapter.driver.open()
    File "/home/pi/.local/lib/python2.7/site-packages/pc_ble_driver_py/ble_driver.py", line 127, in wrapper
    raise NordicSemiException('Failed to {}. Error code: {}'.format(wrapped.__name__, err_code))
    pc_ble_driver_py.exceptions.NordicSemiException: Failed to open. Error code: 13

  • Hi Xavier,

    Please check out this thread, it looks like it could be the same issue.

    (or this)

  • Thanks for those links, but unfortunately they doesn't help much.

    The problem is actually about the interface MCU. We circumvented by connecting nRF directly to Raspberry Pi and it works as expected. It's not a piece of good news for people who simply wants to quickly test serialization with DK and Raspberry Pi, but for my case the problem was solved.

  • Xavier, can you elaborate on your solution? I am at the same point as you were getting the Error Code 13. How did you connect nRF directly to the Pi?

  • Key points to run examples on RPI (w/ DK):


    1. no need JLink software
    --- DK flashing ---
    2. flash nRF on DK by PC, I just tried the 115200 version
    --- pc-ble-driver-py ---
    3. compile boost from source, version <= 1.65.1
    4. install pc-ble-driver-py from source
    --- HW part ---
    5. cut solder bridges on DK to isolate nRF UART pins from interface MCU
    6. wire connect nRF UART to RPI GPIOs
    --- RPI part ---
    7. enable RPI UART w/ HWFC
    --- Python part ---
    8. turn off auto flashing if you with to try examples
    9. make sure UART setting matches connectivity FW that was already flashed in step 2
    10. run examples by explicitly assign UART that is enabled in previous step 

    to flash / erase afterward :

    1. cut solder bridges on DK to isolate SWD pins from interface MCU
    2. wire connect nRF SWD pins (TPs on DK) to RPI GPIO
    3. bitbang SWD on RPI & do your job with it

    Hope this helps

Related