This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrfx_spim driver buffer length variable declaration problem.

Hi,

I want to use tne NRFX SPIM  module for reading and writing an external spi flash (at25df011) .

I looked at the example in order to reuse it or base my application on it.

In the spi buffer parameter declaration, i find "

<Code>

#define TEST_STRING "Nordic123456789012345678901234567890"
static uint8_t       m_tx_buf[] = TEST_STRING;           /**< TX buffer. */
static uint8_t       m_rx_buf[sizeof(TEST_STRING) + 1];  /**< RX buffer. */
static const uint8_t m_length = sizeof(m_tx_buf);        /**< Transfer length. */

</Code>

and in the transfer descriptor,

<Code>

nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TRX(m_tx_buf, m_length, m_rx_buf, m_length);

</Code>

However, i am wondering why the parameter m_length is declared so - "const uint8_t"

Here the test string is predefined and hence the length does not change. But in a real program, where I have to send variable number of

data bytes to the flash, this is causing a problem. I am not allowed to set the length to the required value.

The SPI driver only requires the Tx buffer to be a constant pointer, the length is not treated as constant below in the driver...

If  try to make it variable - removing the "const" in the declaration, it does not compile, reporting error that the identifier needs to be a constant.

I found a workaround where a pointer is used to modify the value of length and it compiles with a warning. 

Is there a better way to resolve this?

Regards

Chary BS

Parents Reply Children
No Data
Related