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

boards/b-l475e-iot01a: Add SPI2 and SPI3 buses #17885

Merged
merged 2 commits into from
Mar 31, 2022

Conversation

dp1
Copy link
Contributor

@dp1 dp1 commented Mar 30, 2022

Contribution description

This PR adds support for the missing SPI2 and SPI3 buses on the b-l4753-iot0a1 board.
SPI2 is exposed on the PMOD connector, SPI3 is used internally to communicate with the radio modules onboard

Testing procedure

SPI3 was tested by interfacing with the bluetooth module with the following code:

#include <stdio.h>

#include "clk.h"
#include "board.h"
#include "periph_conf.h"
#include "timex.h"
#include "xtimer.h"
#include "periph/gpio.h"
#include "periph/spi.h"
#include "fmt.h"

spi_t spi = SPI_DEV(2);
gpio_t cs = GPIO_PIN(PORT_D, 13);
gpio_t rst = GPIO_PIN(PORT_A, 8);
gpio_t ble_int = GPIO_PIN(PORT_E, 6);


uint8_t txbuf[256];
uint8_t rxbuf[256];
char hexbuf[256];

void ble_int_cb(void *arg) {
    (void)arg;

    puts("Interrupt called");
}

bool ble_data_present(void) {
    return gpio_read(ble_int) != 0;
}

void ble_init(void) {
    // Keep BLE in reset
    gpio_init(rst, GPIO_OUT);
    gpio_write(rst, 0);
    xtimer_usleep(5000);

    spi_init(spi);
    spi_init_cs(spi, cs);

    gpio_init_int(ble_int, GPIO_IN_PD, GPIO_RISING, ble_int_cb, NULL);
    gpio_irq_enable(ble_int);

    // Take BLE out of reset
    gpio_set(rst);
    xtimer_usleep(5000);
}

int main(void) {

    ble_init();

    txbuf[0] = 0x0A;
    txbuf[1] = 0;
    txbuf[2] = 0;
    txbuf[3] = 0;
    txbuf[4] = 0;

    while(1) {
        spi_acquire(spi, cs, SPI_MODE_0, SPI_CLK_5MHZ);
        spi_transfer_bytes(spi, cs, false, txbuf, rxbuf, 5);
        spi_release(spi);

        printf("data present: %d\n", ble_data_present());
        fmt_bytes_hex(hexbuf, txbuf, 5);
        printf("TX: %s\n", hexbuf);
        fmt_bytes_hex(hexbuf, rxbuf, 5);
        printf("RX: %s\n", hexbuf);
        puts("");

        xtimer_sleep(1);
    }
}

SPI2 is exposed on the PMOD connector, SPI3 is used internally to
communicate with the radio modules onboard
@github-actions github-actions bot added the Area: boards Area: Board ports label Mar 30, 2022
@dp1 dp1 changed the title boards/b-l4753-iot0a1: Add SPI2 and SPI3 buses boards/b-l475-iot0a1: Add SPI2 and SPI3 buses Mar 30, 2022
@dp1 dp1 changed the title boards/b-l475-iot0a1: Add SPI2 and SPI3 buses boards/b-l475e-iot0a1: Add SPI2 and SPI3 buses Mar 30, 2022
@dp1 dp1 changed the title boards/b-l475e-iot0a1: Add SPI2 and SPI3 buses boards/b-l475e-iot01a: Add SPI2 and SPI3 buses Mar 30, 2022
@aabadie aabadie added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 30, 2022
@aabadie
Copy link
Contributor

aabadie commented Mar 30, 2022

Nice. Are you planning to write a driver for BLE ?

@dp1
Copy link
Contributor Author

dp1 commented Mar 30, 2022

Indeed that's the plan, by adding the SPI/HCI interface used by the chip to NimBLE which seems to be quite feature rich already (and already handles another chip via SPI, so it shouldn't be too hard).

@github-actions github-actions bot added the Area: tools Area: Supplementary tools label Mar 30, 2022
@dp1
Copy link
Contributor Author

dp1 commented Mar 30, 2022

I added a new commit to disable the warnings about undocumented macros, just like it's done for the DMA_[0-3]_ISR macros

@aabadie
Copy link
Contributor

aabadie commented Mar 30, 2022

Also you should update your last commit message to something like tools/doccheck: update exclude patterns for b-l475e-iot01a. This way we clearly know what it is about.

@dp1 dp1 force-pushed the b-l475e-iot01a_add-spi23-buses branch from 050669e to 446b48d Compare March 30, 2022 15:14
Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

ACK

Thanks!

@aabadie aabadie enabled auto-merge March 30, 2022 15:18
@aabadie aabadie merged commit 237f0ab into RIOT-OS:master Mar 31, 2022
@dp1 dp1 deleted the b-l475e-iot01a_add-spi23-buses branch March 31, 2022 06:46
@OlegHahm OlegHahm added this to the Release 2022.04 milestone Apr 8, 2022
@dp1
Copy link
Contributor Author

dp1 commented May 31, 2022

Indeed that's the plan, by adding the SPI/HCI interface used by the chip to NimBLE which seems to be quite feature rich already (and already handles another chip via SPI, so it shouldn't be too hard).

Just as an FYI if somebody finds this PR and is looking for SPBTLE-RF support: Integrating the chip in NimBLE proved to be harder than I thought. Given the limited time I had, I ended up porting another library to RIOT, which you can find here: SPBTLE-RF-RIOT. It doesn't support all the roles, but if you need Beacon and Observer functionality it's good to go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants