1c3086949SMatthias Ringwald# BTstack Port for Renesas Eval Kit EK-RA6M4 with DA14531 2c3086949SMatthias Ringwald 3c3086949SMatthias RingwaldThis port uses the [Renesas EK-RA6M4](https://www.renesas.com/us/en/products/microcontrollers-microprocessors/ra-cortex-m-mcus/ek-ra6m4-evaluation-kit-ra6m4-mcu-group) and a Renesas DA14531 Controller on the [MikroeE BLE Tiny Click board](https://www.mikroe.com/ble-tiny-click) 4c3086949SMatthias Ringwald 5c3086949SMatthias RingwaldRenesas e2 Studio (Eclise-based) was used with the FSP HAL and without an RTOS to generate project sources. 6c3086949SMatthias RingwaldThen, a new CMake buildfile was created to allow for cross-platform development and compilation of all examples. 7c3086949SMatthias RingwaldFor easy debugging, Ozone project files are generated as well. 8c3086949SMatthias Ringwald 9c3086949SMatthias Ringwald## Hardware 10c3086949SMatthias Ringwald 11c3086949SMatthias Ringwald### Renesas Eval Kit EK-RA6M4: 12c3086949SMatthias Ringwald- The RA6 contains a build in J-Link programmer which supports debut output via SEGGER RTT. 13c3086949SMatthias Ringwald- It uses the MikroBus port for the DA1451 14c3086949SMatthias Ringwald 15c3086949SMatthias Ringwald| MikroBus | MCU | Function | 16c3086949SMatthias Ringwald|----------|-------|---------------------| 17c3086949SMatthias Ringwald| J21/2 | P115 | RESET (active high) | 18c3086949SMatthias Ringwald| P21/3 | P205 | RTS | 19c3086949SMatthias Ringwald| J21/4 | P204 | CTS | 20c3086949SMatthias Ringwald| J22/4 | P613 | TX | 21c3086949SMatthias Ringwald| J22/3 | P614 | RX | 22c3086949SMatthias Ringwald 23c3086949SMatthias Ringwald- UART RTS: Manual RTS control in UART callback handler. MikroBus slot with UART 7 does not have RTSCTS7 24c3086949SMatthias Ringwald on the pin used by BLE Tiny Click module. 25c3086949SMatthias Ringwald- BSP 26c3086949SMatthias Ringwald``` 27c3086949SMatthias Ringwald// 0x1000 main stack 28c3086949SMatthias Ringwald#define BSP_CFG_STACK_MAIN_BYTES (0x1000) 29c3086949SMatthias Ringwald 30c3086949SMatthias Ringwald// printf allocates memory from the heap 31c3086949SMatthias Ringwald#define BSP_CFG_HEAP_BYTES (0x800) 32c3086949SMatthias Ringwald``` 33c3086949SMatthias Ringwald 34c3086949SMatthias Ringwald### Renesas DA14531 Module on MikroE BLE Tiny Click board with 35c3086949SMatthias Ringwald- The board comes with some demo application and needs to be programmed with an HCI firmware to use it with a regular Bluetooth stack. 36c3086949SMatthias Ringwald- Firmware details: 37c3086949SMatthias Ringwald - Keil uVision project `DA145xx_SDK/x.x.xx.xxxx/projects/target_apps/hci` on Windows 38c3086949SMatthias Ringwald 39c3086949SMatthias Ringwald``` 40c3086949SMatthias Ringwald// Config: user_periph_setup.h 41c3086949SMatthias Ringwald#define UART1_TX_PORT GPIO_PORT_0 42c3086949SMatthias Ringwald#define UART1_TX_PIN GPIO_PIN_6 43c3086949SMatthias Ringwald#define UART1_RX_PORT GPIO_PORT_0 44c3086949SMatthias Ringwald#define UART1_RX_PIN GPIO_PIN_5 45c3086949SMatthias Ringwald#define UART1_RTSN_PORT GPIO_PORT_0 46c3086949SMatthias Ringwald#define UART1_RTSN_PIN GPIO_PIN_7 47c3086949SMatthias Ringwald#define UART1_CTSN_PORT GPIO_PORT_0 48c3086949SMatthias Ringwald#define UART1_CTSN_PIN GPIO_PIN_8 49c3086949SMatthias Ringwald#define UART1_BAUDRATE UART_BAUDRATE_460800 50c3086949SMatthias Ringwald#define UART1_DATABITS UART_DATABITS_8 51c3086949SMatthias Ringwald 52c3086949SMatthias Ringwald// Config: user_config.h 53c3086949SMatthias Ringwaldstatic const sleep_state_t app_default_sleep_mode = ARCH_SLEEP_OFF; 54c3086949SMatthias Ringwald``` 55c3086949SMatthias Ringwald 56c3086949SMatthias Ringwald- Firmware installation: 57c3086949SMatthias Ringwald - Connect GND (pin 5) and VCC (pin 6) with jumper wires to the RA6 dev board. 58c3086949SMatthias Ringwald - Connect it with a ARM-Cortex 10-pin connector to a J-Link device 59c3086949SMatthias Ringwald - Start [SmartBond Flash Programmer](https://www.renesas.com/kr/en/software-tool/smartbond-flash-programmer) 60c3086949SMatthias Ringwald - The Programmer should auto-detect the DA14531 via the J-Link. 61c3086949SMatthias Ringwald - Select `firmware/hci_531_rx05_tx06_rts07_cts08_468000.hex` as firmware file and click `Program` 62c3086949SMatthias Ringwald 63c3086949SMatthias Ringwald## Software 64c3086949SMatthias Ringwald 65c3086949SMatthias RingwaldThe port provides a CMake project file that uses the installed Arm Gnu Toolchain. 66c3086949SMatthias Ringwald 67c3086949SMatthias Ringwald- Install [Arm GNU Toolchain](https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain) 68c3086949SMatthias Ringwald- Install [CMake](https://cmake.org) 69c3086949SMatthias Ringwald- Install [Ninja](https://ninja-build.org) 70c3086949SMatthias Ringwald- To compile, go to the port folder: 71c3086949SMatthias Ringwald 72c3086949SMatthias Ringwald `cd btstack/port/renesas-ek-ra6me4a-da14531` 73c3086949SMatthias Ringwald 74c3086949SMatthias Ringwald- Create a build folder and go to build folder 75c3086949SMatthias Ringwald 76c3086949SMatthias Ringwald `mkdir build && cd build` 77c3086949SMatthias Ringwald 78c3086949SMatthias Ringwald- Create Ninja build files 79c3086949SMatthias Ringwald 80c3086949SMatthias Ringwald `cmake -G Ninja ..` 81c3086949SMatthias Ringwald 82c3086949SMatthias Ringwald- Build all examples 83c3086949SMatthias Ringwald 84c3086949SMatthias Ringwald `ninja` 85c3086949SMatthias Ringwald 86c3086949SMatthias RingwaldThis will build all examples as .elf files as well as .jdebug Ozone debug project files 87c3086949SMatthias RingwaldAlternatively, the CMakeLists.txt can be used to compile using Make (`cmake -G "Unix Makefiles" ..` and `make`) or 88c3086949SMatthias Ringwaldor use the project in most modern IDEs (CLion, Visual Studio, Visual Studio Code, ...) 89c3086949SMatthias Ringwald 90c3086949SMatthias Ringwald 91c3086949SMatthias Ringwald## Run Example Project using Ozone 92c3086949SMatthias Ringwald 93c3086949SMatthias RingwaldAfter building the examples, the generated .elf file can be used with Ozone. 94c3086949SMatthias RingwaldStart Ozone and open the provided .jdebug file. The debug output is readily available in the RTT Terminal. 95c3086949SMatthias Ringwald 96c3086949SMatthias Ringwald 97c3086949SMatthias Ringwald## Debug output 98c3086949SMatthias Ringwald 99c3086949SMatthias RingwaldAll debug output is send via SEGGER RTT. 100c3086949SMatthias Ringwald 101c3086949SMatthias RingwaldIn src/btstack_config.h resp. in example/btstack_config.h of the generated projects. 102c3086949SMatthias Ringwald 103c3086949SMatthias RingwaldAlso, the full packet log with addtional log information can be enabled in src/hal_entry.c by uncommenting the hci_dump_init(...) call. 104c3086949SMatthias Ringwald 105c3086949SMatthias RingwaldThe console output can then be converted into .pklg files by running tool/create_packet_log.py. The .pklg file can be 106c3086949SMatthias Ringwaldanalyzed with the macOS X PacketLogger or WireShark. 107c3086949SMatthias Ringwald 108c3086949SMatthias Ringwald 109c3086949SMatthias Ringwald## Setup 110c3086949SMatthias Ringwald 111*6bbe12baSMatthias Ringwald 112c3086949SMatthias Ringwald 113c3086949SMatthias Ringwald## Updating HAL Configuration 114c3086949SMatthias Ringwald- Start Renesas RA v3.7.0/e2-studio on Windows and open `e2-project` 115c3086949SMatthias Ringwald- Open `configuration.xml` to get to "FSP Configuration" perspective 116c3086949SMatthias Ringwald - to add modules, click "New Stack" 117c3086949SMatthias Ringwald - module is configured in "Properties" view (usually below next to 'Problems' etc) 118c3086949SMatthias Ringwald- Press button re-generates sources 119c3086949SMatthias Ringwald- Copy folder `e2-project` into this port 120c3086949SMatthias Ringwald- Check diff for unexpected changes 121c3086949SMatthias Ringwald- If needed: 122c3086949SMatthias Ringwald - Update CMakeLists.txt to add new modules 123c3086949SMatthias Ringwald - Add code to enable ('open') new module in `R_BSP_WarmStart` of `port/hal_entry.c` 124