Sunday, June 16, 2019

An Ada Client & Server on the STM32WB55


Ada WB55 Client & Server

Following on from the last blog posting, I now have a client and server implementation in Ada. Mine is not quite as fancy as ST's, ST's allows role reversal where the client can run on the larger board (MB1355C) and the server on the USB dongle (MB1293C). I only support server on MB1355C and client on MB1293C.

Getting the code & building

You will need gnat2018 or gnat2019 from AdaCore:

https://www.adacore.com/download

Once that's installed, you will need some library code and the STM32 dir I use:

git clone https://github.com/morbos/Ada_Drivers_Library.git
git clone https://github.com/morbos/embedded-runtimes.git
git clone https://github.com/morbos/STM32.git
mv ../embedded-runtimes Ada_Drivers_Library
cd STM32/WB/WB55/cli_serv_wb55
make

Once make finishes you get 2 ELF32 files in the obj/Debug dir.

admin@ubuntu_1604:/tmp/STM32/WB/WB55/cli_serv_wb55$ make
rm -f obj/Debug/client_wb55x
(export LOADER=ROM_WB55x; gprbuild client_wb55x.gpr)
Link
   [link]         client_wb55x.adb
Memory region         Used Size  Region Size  %age Used
           flash:       93008 B         1 MB      8.87%
           sram1:      102792 B       192 KB     52.28%
          sram2a:          0 GB        32 KB      0.00%
          sram2b:          0 GB        32 KB      0.00%
(cd obj/Debug; arm-eabi-objdump -d client_wb55x >client_wb55x.lst; arm-eabi-objdump -s client_wb55x >client_wb55x.dmp; arm-eabi-gcc-nm -an client_wb55x >client_wb55x.nm; arm-eabi-objcopy -Obinary client_wb55x client_wb55x.bin)
rm -f obj/Debug/server_wb55x
(export LOADER=ROM_WB55x; gprbuild server_wb55x.gpr)
Link
   [link]         server_wb55x.adb
Memory region         Used Size  Region Size  %age Used
           flash:       93752 B         1 MB      8.94%
           sram1:      108056 B       192 KB     54.96%
          sram2a:          0 GB        32 KB      0.00%
          sram2b:          0 GB        32 KB      0.00%
(cd obj/Debug; arm-eabi-objdump -d server_wb55x >server_wb55x.lst; arm-eabi-objdump -s server_wb55x >server_wb55x.dmp; arm-eabi-gcc-nm -an server_wb55x >server_wb55x.nm; arm-eabi-objcopy -Obinary server_wb55x server_wb55x.bin)

Each of these ELF32 files can be flashed on the board.

Openocd

To flash the MB1355C use the ST-Link USB connector (the silkscreen is on the bottom of the board).

You will need openocd-0.10.0 that is on my github.

Modify the st_nucleo_wb.tcl in the tcl/board dir. You want to make sure the v2-1 line is uncommented. 

From:
# source [find interface/stlink-v2-1.cfg]
source [find interface/stlink-v2.cfg]

To:

source [find interface/stlink-v2-1.cfg]
#source [find interface/stlink-v2.cfg]

Then you can attach:

root@pi3:~/openocd-0.10.0/tcl# ../src/openocd -f board/st_nucleo_wb55.cfg Open On-Chip Debugger 0.10.0 Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD adapter speed: 2000 kHz adapter_nsrst_delay: 100 none separate none separate Info : Unable to match requested speed 2000 kHz, using 1800 kHz Info : Unable to match requested speed 2000 kHz, using 1800 kHz Info : clock speed 1800 kHz Info : STLINK v2 JTAG v32 API v2 SWIM v22 VID 0x0483 PID 0x374B Info : using stlink api v2 Info : Target voltage: 3.268721 Info : stm32wb.cpu: hardware has 6 breakpoints, 4 watchpoints

Flashing & Debug

admin@ubuntu_1604:/.share/CACHEDEV1_DATA/Ada/STM32/WB/WB55/cli_serv_wb55$ arm-eabi-gdb obj/Debug/server_wb55x
GNU gdb (GDB) 8.3 for GNAT Community 2019 [rev=gdb-8.3-ref-194-g3fc1095]
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
See your support agreement for details of warranty and support.
If you do not have a current support agreement, then there is absolutely
no warranty for this version of GDB.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=arm-eabi".
Type "show configuration" for configuration details.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from obj/Debug/server_wb55x...
(gdb) target extended-remote 10.0.1.241:3333
Remote debugging using 10.0.1.241:3333
0x0800e02e in system.bb.board_support.interrupts.power_down ()
    at /.share/CACHEDEV1_DATA/Ada/STM32/WB/WB55/cli_serv_wb55/Ada_Drivers_Library/embedded-runtimes/base_runtimes/ravenscar-full/gnarl-common/s-bbbosu.adb:402
402          Asm ("wfi", Volatile => True);
(gdb) monitor reset halt
Unable to match requested speed 2000 kHz, using 1800 kHz
Unable to match requested speed 2000 kHz, using 1800 kHz
adapter speed: 1800 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08010968 msp: 0x2001a620
(gdb) load
Loading section .text, size 0x121d0 lma 0x8000000
Loading section .ARM.extab, size 0xe34 lma 0x80121d0
Loading section .ARM.exidx, size 0xe98 lma 0x8013004
Loading section .rodata, size 0x31e8 lma 0x8013ea0
Loading section .data, size 0x78c lma 0x8017088
Start address 0x8010968, load size 96272
Transfer rate: 22 KB/sec, 10696 bytes/write.
(gdb) monitor reset init
Unable to match requested speed 2000 kHz, using 1800 kHz
Unable to match requested speed 2000 kHz, using 1800 kHz
adapter speed: 1800 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08010968 msp: 0x2001a620
Unable to match requested speed 2000 kHz, using 1800 kHz
Unable to match requested speed 2000 kHz, using 1800 kHz
adapter speed: 1800 kHz
(gdb) b main
Breakpoint 1 at 0x800060a: file b__server_wb55x.adb, line 276.
(gdb) b __gnat_last_chance_handler
Breakpoint 2 at 0x800065a: file /.share/CACHEDEV1_DATA/Ada/STM32/WB/lch_sfp/led/last_chance_handler.adb, line 48.
(gdb) c
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, main () at b__server_wb55x.adb:276
276       Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;
(gdb) 

To flash the MB1293C attach using the other text line of st_nucleo_wb.tcl and use a similar flashing process except flash the client_wb55


No comments:

Post a Comment