Hi,
I have a device based on the board nrf9160 with an external peripheral which is the flash LE25U40CMDTWG and that communicates with the controller through the next pins (configuration on the dts):
&spi3 {
compatible = "nordic,nrf-spim";
status = "okay";
sck-pin = <23>;
mosi-pin = <27>;
miso-pin = <24>;
};
I'm creating a driver of the flash and, according its datasheet, when I send some commands I should receive in the rx buffer some responses from the peripheral. I attach an example of the most important parts of the code:
#include "le25u40cmdtwg.h"
#include <logging/log.h>
#include "string.h"
#include "../../hw_config.h"
/**
* DEFINES
*/
#define MODULE_NAME le25u40cmdtwg
LOG_MODULE_REGISTER(MODULE_NAME, LOG_LEVEL_INF);
static le25u40cmdtwg_t* config;
const struct device* spi_dev;
static volatile bool spim_xfer_done; /**< Flag used to indicate that SPIM instance completed the transfer. */
#define SPI_INSTANCE 3
static const struct spi_config spi_cfg = {
.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_MODE_CPOL | SPI_MODE_CPHA,
.frequency = 4000000,
.slave = 0,
};
/**
* @brief SPI user event handler.
* @param event
*/
void spim_event_handler(nrfx_spim_evt_t const* p_event, void* p_context) {
if (p_event->type == NRFX_SPIM_EVENT_DONE) {
spim_xfer_done = true;
printk("Transfer completed.");
}
}
void le25u40cmdtwg_init(le25u40cmdtwg_t* le25u40cmdtwg) {
config = le25u40cmdtwg;
}
uint8_t le25u40cmdtwg_spiTransfer(le25u40cmdtwg_t* le25u40cmdtwg) {
int err;
static uint8_t tx_buffer[20];
tx_buffer[0] = le25u40cmdtwg->command;
static uint8_t rx_buffer[] = "IFMMP GSPN BCDEFGHI!";
struct spi_buf tx_buf = {.buf = tx_buffer, .len = sizeof(tx_buffer)};
struct spi_buf_set tx = {.buffers = &tx_buf, .count = 1};
struct spi_buf rx_buf = {
.buf = rx_buffer,
.len = sizeof(rx_buffer),
};
struct spi_buf_set rx = {.buffers = &rx_buf, .count = 1};
// nrf_gpio_pin_clear(LE25U40CMDTWG_SPI_CS_PIN);
err = gpio_pin_configure(le25u40cmdtwg->gpio_dev, LE25U40CMDTWG_SPI_CS_PIN, 0U);
err |= spi_transceive(le25u40cmdtwg->spi_dev, &spi_cfg, &tx, &rx);
if (err) {
printk("SPI error: %d\n", err);
} else {
printk("TX sent: %p\n", tx_buf.buf);
}
err |= gpio_pin_configure(le25u40cmdtwg->gpio_dev, LE25U40CMDTWG_SPI_CS_PIN, 1U);
return err;
}
The initialization of the spi is as follows on the main.c of the project:
const struct device *spi_dev;
spi_dev = device_get_binding(SPI3_LABEL);
if (spi_dev == NULL) {
LOG_ERR("Could not bind SPI 3");
return;
}
My question is, after using the API spi_transceive(), it returns err=0, which from the SW point of view means that the execution was correct and the tx buffer contains the command as I would expect it, but the rx buffer of the function le25u40cmdtwg_spiTransfer() keeps always empty. Due to the design of the board, I cannot use any external HW as a logical analyzer for testing if the frames are being correctly sent through the MISO/MOSI lines of the spi configuration.
Is there any other way of testing, from SW point of view, if the flash is at least receiving the commands that I send?
Is there anything on my driver that could be clearly wrong and could cause that the Rx buffer keeps always empty?
Many thanks in advance,
Ángel