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

9160 SPI returns -5 IO error

ISSUE:    The spi driver does not seem to send/receive data and returns a (-5) error   IO-ERROR

QUESTION: What is the details of the error?

The "spi_transceiver" should perform the operation if length > 0 otherwise NOT assert the CS. The operation that is failing is a read 1 byte

RESULTS:

https://www.pctestinstruments.com/

the LPF are for the logic analyser

this can be downloaded then the timing etc can be measured

Pic of Failed SPI operation RED arrow attached. Using SDK 1.21. Schematics attached

As can be seen there is no clk activity, I'd expect that the SPI function will perform this regardless, for the number of bytes.

If the parameters are bad I'd expect an error, with no asserts on the CS etc.

 

The  following is the result of from the SW monitor:

 

(17:01:28.258)
(17:01:29.185) Socket_cb:4-1 <CR>
(17:01:29.185) socket_cb: accept success!<CR>
(17:01:29.185)     accepted conection. Calling HTTP_Server 1<CR>
(17:01:29.213) Socket_cb:6-2 <CR>
(17:01:29.213) socket_cb: recv success!<CR><CR>
(17:01:29.264) Socket_cb:7-2 <CR>
(17:01:29.299) socket_cb: send success!<CR><CR>
(17:01:29.331) Socket_cb:7-2 <CR>
(17:01:29.331) socket_cb: send success!<CR><CR>
(17:01:29.415) Socket_cb:7-2 <CR>
(17:01:29.451) socket_cb: send success!<CR><CR>
(17:01:29.451) (APP)(ERR)[spi_rw][225]spi_rw: HAL_SPI_TransmitReceive failed. error (-5)
(17:01:29.451)

 

 

My Source to write to SPI

 

/**********************************************************************************/
/*   function:    CM_wifi_server                                                  */
/*   parameters:    struct device * winc1500_dev                                  */
/*   returns:       int                                                           */
/*   Description: Init the wifi interface and turn on Access Point                */
/*--------------------------------------------------------------------------------*/
int winc1500_hw_initialize(struct device * winc1500_dev)
{
    winc1500.spiDev = device_get_binding(WINC1500_SPI);             // get spi1 device
    if (NULL == winc1500.spiDev)
      {
//     LOG_ERR("can not find device " WINC1500_SPI);
       printk("winc1500 cannot bind to %s\n", WINC1500_SPI);
        return -1;
      }

    // get chip select pin device
    winc1500.spi_cs_conf.gpio_dev = device_get_binding(WINC1500_CS_GPIO_NAME);
    if (NULL == winc1500.spi_cs_conf.gpio_dev)
    {
     //   LOG_ERR("can not find device " WINC1500_CS_GPIO_NAME);
         printk("winc1500 chip select cannot bind to %s\n", WINC1500_CS_GPIO_NAME);
        return -1;
    }
    // set chip select
    winc1500.spi_conf.cs = &winc1500.spi_cs_conf;

 
    /*Note  - interrupts are via io expander
    - refer CM_i2c_bb.c for WINC1500 interrupt setup*/
 
    return 0;
}

 

 


File: 

static sint8 spi_rw(uint8* pu8Mosi, uint8* pu8Miso, uint16 u16Sz)
{
//   HAL_StatusTypeDef status; 
sint8 status;
    int err;

/*----------------------------------------------------------------------------------*/
  // const struct spi_buf rx_buf[] = {
   struct spi_buf rx_buf[] = {
//                                    {
// //                                  .buf =   NULL,                /*  */
// //                                   .len =  1,
//                                     .buf = pu8Miso,
//                                    .len = u16Sz,
//
//  //                                 .buf =   pu8Mosi,                /*  */
//  //                                  .len =  u16Sz,
//                                    },
//
                                    {
                                    .buf = pu8Miso,
                                    .len = u16Sz,
                                    }
                                  };

     struct spi_buf_set rx = {
        .buffers = rx_buf,
        .count = sizeof(rx_buf) / sizeof(struct spi_buf)
                };

 /*----------------------------------------------------------------------------------*/
   struct spi_buf tx_buf [] = {
            {
            .buf = pu8Mosi,
            .len = u16Sz/sizeof(uint8)
            }
    };
    const struct spi_buf_set tx = {
            .buffers = tx_buf,
            .count = sizeof(tx_buf)/sizeof(struct spi_buf)
    };
/*----------------------------------------------------------------------------------*/
 

    /* Start SPI transaction - polling method */
    /* Transmit/Recieve */
    if (pu8Mosi == NULL)                                              /* Read Data */
    {
//   err = spi_read(winc1500.spiDev, &winc1500.spi_conf, &rx);
//        status = HAL_SPI_TransmitReceive(&hspiWifi,spiDummyBuf,pu8Miso,u16Sz,1000);
err = spi_transceive(winc1500.spiDev,&winc1500.spi_conf, NULL, &rx);

    }
    else if(pu8Miso == NULL)                                          /* Write Data */
    {
//    err = spi_write(winc1500.spiDev, &winc1500.spi_conf, &tx);
//        status = HAL_SPI_TransmitReceive(&hspiWifi,pu8Mosi,spiDummyBuf,u16Sz,1000);
 //       memset(spiDummyBuf,0, u16Sz);
     err = spi_transceive(winc1500.spiDev,&winc1500.spi_conf, &tx, NULL);
   }
    else
    {    
    err = spi_transceive(winc1500.spiDev,&winc1500.spi_conf, &tx, &rx);
//        status = HAL_SPI_TransmitReceive(&hspiWifi,pu8Mosi,pu8Miso,u16Sz,1000);
    }
    

    /* Handle Transmit/Recieve error */
    if (err != M2M_SUCCESS)
    {
        M2M_ERR("%s: HAL_SPI_TransmitReceive failed. error (%d)\n",__FUNCTION__,err);
        return status;
    }
   
 //     spi_select_slave(false);

    return M2M_SUCCESS;
}

 

Nordic/Zephyr/CES functions


extern int z_impl_spi_transceive(struct device * dev, const struct spi_config * config, const struct spi_buf_set * tx_bufs, const struct spi_buf_set * rx_bufs);
static inline int spi_transceive(struct device * dev, const struct spi_config * config, const struct spi_buf_set * tx_bufs, const struct spi_buf_set * rx_bufs)
{
#ifdef CONFIG_USERSPACE
    if (z_syscall_trap()) {
        return (int) arch_syscall_invoke4(*(uintptr_t *)&dev, *(uintptr_t *)&config, *(uintptr_t *)&tx_bufs, *(uintptr_t *)&rx_bufs, K_SYSCALL_SPI_TRANSCEIVE);
    }
#endif
    compiler_barrier();
    return z_impl_spi_transceive(dev, config, tx_bufs, rx_bufs);
}



File:   spi.h

__syscall int spi_transceive(struct device *dev,
                 const struct spi_config *config,
                 const struct spi_buf_set *tx_bufs,
                 const struct spi_buf_set *rx_bufs);

static inline int z_impl_spi_transceive(struct device *dev,
                       const struct spi_config *config,
                       const struct spi_buf_set *tx_bufs,
                       const struct spi_buf_set *rx_bufs)
{
    const struct spi_driver_api *api =
        (const struct spi_driver_api *)dev->driver_api;

    return api->transceive(dev, config, tx_bufs, rx_bufs);
}

Parents
  • Hello Archna,

    Archna-Glyn said:
    I have uploaded the x3 files proj.conf, Kconfig and Makelist to help understand the link to 91060. Would this help?

    Unfortunately, I am not able to see any attachments from you in this case.

    Anyway, could you please try the following? There is a Wi-Fi sample included in the Zephyr part of NCS, without any content in its main() function. Please add the following lines to main():

    const struct device *dev = DEVICE_DT_GET_ANY(atmel_winc1500);
    
    if (dev == NULL) {
        /* No such node, or the node does not have status "okay". */
        printk("\nError: no device found.\n");
        return;
    }

    In prj.conf, add:

    CONFIG_WIFI_WINC1500=y

    In subfolder “boards”, please create an overlay file nrf9160dk_nrf9160ns.overlay (in case you are using the non-secure build, otherwise without ns) and add the following content (modify pins accordingly):

    &spi3 {
    	winc1500@0 {
    		status = "ok";
    		compatible = "atmel,winc1500";
    		reg = <0x0>;
    		label = "winc1500";
    		spi-max-frequency = <4000000>;
    		irq-gpios = <&gpio0 7 1>;
    		reset-gpios = <&gpio0 8 1>;
    		enable-gpios = <&gpio0 12 0>;
    	};
    };
    

    To make this work, the Atmel HAL drivers have to be included in NCS. This can be done by adding "- hal_atmel" to name-allowlist of west.yml. After that, please run "west update" within the ncs-folder before building the application. If device binding succeeds, you should not get any error message printed in the Terminal.

    Regards,

    Markus

Reply
  • Hello Archna,

    Archna-Glyn said:
    I have uploaded the x3 files proj.conf, Kconfig and Makelist to help understand the link to 91060. Would this help?

    Unfortunately, I am not able to see any attachments from you in this case.

    Anyway, could you please try the following? There is a Wi-Fi sample included in the Zephyr part of NCS, without any content in its main() function. Please add the following lines to main():

    const struct device *dev = DEVICE_DT_GET_ANY(atmel_winc1500);
    
    if (dev == NULL) {
        /* No such node, or the node does not have status "okay". */
        printk("\nError: no device found.\n");
        return;
    }

    In prj.conf, add:

    CONFIG_WIFI_WINC1500=y

    In subfolder “boards”, please create an overlay file nrf9160dk_nrf9160ns.overlay (in case you are using the non-secure build, otherwise without ns) and add the following content (modify pins accordingly):

    &spi3 {
    	winc1500@0 {
    		status = "ok";
    		compatible = "atmel,winc1500";
    		reg = <0x0>;
    		label = "winc1500";
    		spi-max-frequency = <4000000>;
    		irq-gpios = <&gpio0 7 1>;
    		reset-gpios = <&gpio0 8 1>;
    		enable-gpios = <&gpio0 12 0>;
    	};
    };
    

    To make this work, the Atmel HAL drivers have to be included in NCS. This can be done by adding "- hal_atmel" to name-allowlist of west.yml. After that, please run "west update" within the ncs-folder before building the application. If device binding succeeds, you should not get any error message printed in the Terminal.

    Regards,

    Markus

Children
No Data
Related