cancel
Showing results for 
Search instead for 
Did you mean: 

ST25R3916b connected to nRF52840 via SPI. Problems to Integrate RFAL-Library in Embedded Studio.

pososos
Associate II

Hi,

I go my own hardware, that connects the ST25R3916b-aq chip to a nRF52840 Bluetooth Module and its SPI bus.  (and the I2C bus, just in case).

Im using the Segger Embedded Studio with the nRF5 SDK for programming.

Because and the communication is quite complex for the SPI, I want to use the RFAL library.

If I just import it to my project, its missing the platform.h file. That file includes the "stm32f4xx_hal.h" and that can't work for my nRF52840. Where do i go from here?

I know the basics of C coding, but im new to nRF and would really apreciate some help to get me in the right direction.

Thank you!

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
1 ACCEPTED SOLUTION

Accepted Solutions

@pososos wrote:

Does anyone know if that has been done before?


Probably the Nordic forum would be the best place to ask that - that's where you'll find the people working with nRF devices!

View solution in original post

4 REPLIES 4
Andrew Neil
Evangelist III

@pososos wrote:

I know the basics of C coding, but I'm new to nRF and would really apreciate some help to get me in the right direction.


Are you familiar with working on STM32? or any other microcontroller?

 

Perhaps it would be easier for you to start by getting this to work with an STM32?

Then you'd have a known-working setup as reference from which to start your port to nRF...

 

Ulysses HERNIOSUS
ST Employee

Hi pososos,

 

please see the documentation. stsw-st25rfal002 references the UM2890RF/NFC abstraction layer (RFAL) and contained in the package is also an rfal.chm file both detailing the porting.

(rfal_)platform.h is the central file which you will need to adapt for configuring rfal and the interface to the host MCU.

 

Ulysses

pososos
Associate II

Ok thank you, i found the mandatory functions that i need to provide:
RFAL (RF Abstraction Layer) 
Interfaces to the user specific platform hardware driver (MCU HAL)
A few interfaces for the HW drivers must be provided:

  • platformProtectST25RComm() Protects the unique access to ST25R communication channel - IRQ disable on single thread environment (MCU) ; Mutex lock on a multi thread environment (mandatory)
  • platformUnprotectST25RComm() 
      Unprotects the unique access to ST25R communication channel - IRQ enable on a single thread environment (MCU) ; Mutex unlock on a multi thread environment (mandatory)
  • platformGpioSet( port, pin ) 
      Sets GPIO to logical high state (mandatory)
  • platformGpioClear( port, pin ) 
      Sets GPIO to logical low state (mandatory)
  • platformGpioToogle( port, pin ) 
      Toogles GPIO logical state (mandatory)
  • platformGpioIsHigh( port, pin ) 
      Checks if the state of a GPIO is in logical high state (mandatory)
  • platformGpioIsLow( port, pin ) 
      Checks if the state of a GPIO is in logical low state (mandatory)
  • platformTimerCreate( t ) 
      Creates a timer that shall expire in the given time (t) expressed in milliseconds (mandatory)
          This shall calculate a timer/tick/reference to a timeout that will be expired after the time defined. It will return this timer/tick/reference expressed as an unsigned 32 bit variable. 
  • platformTimerIsExpired( timer ) 
      Checks if the timer previously created is expired (mandatory)
          This shall receive the timer/tick/reference returned by platformTimerCreate() and return true if expired. 
  • platformDelay( t ) 
      Delays/Blocks the MCU for the given time (t) in milliseconds (mandatory)
  • platformSpiSelect() 
      SPI SS \ CS: Chip|Slave Select (mandatory)
  • platformSpiDeselect() 
      SPI SS \ CS: Chip|Slave Deselect (mandatory)
  • platformSpiTxRx( txBuf, rxBuf, len ) 
      SPI Transceive (mandatory)
          This shall transmit/receive from/to the given buffers for the given amount of bytes (len). 
          The SPI Bus shall be clocked for the given number of bytes (len). 
          If transmission buffer (txBuff) equals NULL, only reception shall be done, leading to zeros on the MOSI line, and the MISO bytes into rxBuff 
          If reception buffer (rxBuff) equals NULL, only transmission shall be done, leading to transmission on the MOSI line, and data from MISO being ignored / not placed into the rxBuff

This is how I use the SPI from the nRF SDK:

 

#include "nrf_drv_spi.h"
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(ST25R3916B_SPI_INSTANCE);
static volatile bool spi_xfer_done = false;

void spi_event_handler(nrf_drv_spi_evt_t const * p_event, void * p_context)
{
    spi_xfer_done = true;
}

void configure_spi(void)
{
    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin   = NRF_GPIO_PIN_MAP(0,27);
    spi_config.miso_pin = NRF_GPIO_PIN_MAP(0,5);
    spi_config.mosi_pin = NRF_GPIO_PIN_MAP(0,26);;
    spi_config.sck_pin  = NRF_GPIO_PIN_MAP(0,6);
    spi_config.irq_priority = APP_IRQ_PRIORITY_HIGH;
    spi_config.mode = NRF_DRV_SPI_MODE_0;
    spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
    spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
    APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));
}

uint8_t st25r3916b_read_register(uint8_t reg)
{
    uint8_t read_cmd = 0x00 | (reg << 1);
    uint8_t data;
    nrf_drv_spi_transfer(&spi, &read_cmd, 1, &data, 1);
    return data;
}

void st25r3916b_write_register(uint8_t reg, uint8_t value)
{
    uint8_t write_cmd = 0x01 | (reg << 1);
    nrf_drv_spi_transfer(&spi, &write_cmd, 1, NULL, 0);
    nrf_drv_spi_transfer(&spi, &value, 1, NULL, 0);
}

 

For Example 

#define platformGpioSet( port, pin ) HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET) /*!< Turns the given GPIO High */
I would try to change that to my nRF functions.
This is how i set GPIO pins.
nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(1,8) ); 
nrf_gpio_pin_write(NRF_GPIO_PIN_MAP(1,8) , 0); 

Does anyone know if that has been done before?
Or may can help me with further information, how i can achieve that?
Thank You!


@pososos wrote:

Does anyone know if that has been done before?


Probably the Nordic forum would be the best place to ask that - that's where you'll find the people working with nRF devices!