To use the Presense sdkspi4 from myapp

Asked 2 years ago, Updated 2 years ago, 127 views

I'm using Presense sdk v1.5.0 (VS code)

I created myapp by adding app

I want to use spi4 from myapp_main()

The image is as follows, but the inclusion doesn't go through.
I don't know how to use it at all

\#include "cxd56_spi.h"

spi_dev_s*spi4;

int myapp_main(int argc, char*argv[]){

  printf("myapp spi test\n";

  spi4 = cxd56_spibus_initialize(4);

  printf("freq%d\n", spi4->frequency);

  return 0;
}

In addition, I would like to read and write simultaneously, for example, 4 bytes.
I don't even know a single read/write function
First, loopback image

With Arduino IDE, I can do it with a linear approach.

Would you like to register with a nuttx driver?

ps. I wish it was in the sample code, but I couldn't find it

I would like to use DMA in the future

■SDK configuration
*CXD56xx Configuration
SPI*
>✔ CCXD56_SPI

* CXD56xx Configuration I SPI
SPI4*

>✔ CCXD56_SPI4

* CXD56xx Configuration SP SPII SPI4
DMAC support for SPI4TX*
>✔ CCXD56_DMAC_SPI4_TX

* CXD56xx Configuration SP SPII SPI4
DMAC support for SPI4 RX*
>✔ CCXD56_DMAC_SPI4_RX

spresense

2022-09-30 21:47

1 Answers

If you look at the driver implementation of the LCD using the SPI of the Presense,
It seems to work with the macro defined in spresense/nuttx/include/nuttx/spi/spi.h.
So I have two files to include.

include.
#include<nuttx/spi/spi.h>
# include<cxd56_spi.h>

I think I can go there by

This is the initialization process, but
If you want to use DMA, it seems that you need to configure DMA separately.

sdk/bsp/board/common/src/cxd56_ili9340.c: Excerpt from near line 347

spi=cxd56_spibus_initialize(DISPLAY_SPI);
      hdl=cxd56_dmachannel(DISPLAY_DMA_TXCH, DISPLAY_DMA_TX_MAXIZE);
      if(hdl)
        {
          conf.channel_cfg = DISPLAY_DMA_TXCH_CFG;
          conf.dest_width = CXD56_DMAC_WIDTH8;
          conf.src_width = CXD56_DMAC_WIDTH8;
          cxd56_spi_dmaconfig(DISPLAY_SPI, CXD56_SPI_DMAC_CHTYPE_TX, hdl, & conf);
        }
      hdl = cxd56_dmachannel(DISPLAY_MA_RXCH, DISPLAY_MA_RX_MAXIZE);
      if(hdl)
        {
          conf.channel_cfg = DISPLAY_DMA_RXCH_CFG;
          conf.dest_width = CXD56_DMAC_WIDTH8;
          conf.src_width = CXD56_DMAC_WIDTH8;
          cxd56_spi_dmaconfig(DISPLAY_SPI, CXD56_SPI_DMAC_CHTYPE_RX, hdl, & conf);
        }

The SPI mode and other settings seem to be using the macro defined in nuttx/spi/spi.h.

SPI_SETMODE(priv->spi, SPIDEV_MODE3);
      SPI_SETBITS (priv->spi, 8);
      SPI_HWFEATURES (priv->spi, 0);
      SPI_SETFREQUENCY (priv->spi,ILI9340_SPI_MAXFREQUENCY);

Also, to send and receive at the same time, you can use a macro called SPI_EXCHANGE().

Instructions are provided in the nuttx header.
nuttx/include/nuttx/spi/spi.h: line 377 to

/**********************************************************
 * Name—SPI_EXCHANGE
 *
 * Description:
 *   Exahange a block of data from SPI.Required.
 *
 * Input Parameters:
 *   dev-Device-specific state data
 *   txbuffer-A pointer to the buffer of data to be sent
 *   rxbuffer-A pointer to the buffer in which to receive data
 *   nwords - the length of data that to be exchanged in units of words.
 *              The wordsize is determined by the number of bits-per-word
 *              selected for the SPI interface.If nbits<=8, the data is
 *              packed into 8_t's; if nbits > 8, the data is packed into
 *              uint16_t's
 *
 * Returned Value:
 *   None
 *
 ****************************************************************************/

Finally, cxd56_spi.h gets an include error:
By default, the include path appears to be missing, and you can use it to pass through

around line 71 in the .vscode/application.mk directory of myapp CFLAGS and CXXFLAGS are defined, so
In the line that follows,

CFLAGS+=-I$(SDKTOP)/bsp/src
CXXFLAGS+=-I$(SDKTOP)/bsp/src

I think you can add the path by adding .

I hope it will be helpful.


2022-09-30 21:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.