Problem running SPI driver on Vybrid

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Problem running SPI driver on Vybrid

2,420 次查看
n00b1024
Contributor III

I'm having some trouble running the SPI demo in MQX 4.0 (Freescale_MQX_4_0\mqx\examples\spi\iar\spi_vybrid_autoevb_a5) on the Vybrid. spifd = fopen (TEST_CHANNEL, NULL) isn't succeeding in opening the spi driver and is returning null. TEST_CHANNEL = "spi0:". Thoughts?

标记 (3)
0 项奖励
回复
7 回复数

1,541 次查看
Martin_
NXP Employee
NXP Employee

Make sure the "spi0:" device is installed. Startup code _bsp_enable_card() includes code that installs this IO device only if BSPCFG_ENABLE_SPI0 is defined as 1, (user_config.h.)

1,541 次查看
n00b1024
Contributor III

Martin,

Thanks for your reply. I set BSPCFG_ENABLE_SPI0 = 1, but fopen still isn't succeeding.

0 项奖励
回复

1,541 次查看
Martin_
NXP Employee
NXP Employee

Ok, but why ? Do you try to step in into the fopen() function with the debugger to see, which code line causes this ? Can you show call stack ? Did you recompile the BSP and PSP projects, then the application ?

0 项奖励
回复

1,541 次查看
n00b1024
Contributor III

Hi Martin,

I tried rebuilding the bsp and psp libraries, and then the SPI applications, but no joy.

Here's some code inside io_fopen. dev_ptr is set to (pointer)&kernel_data->IO_DEVICES.NEXT, and then presumably IO_DEVICES.NEXT is supposed to change when _lwsem_post((LWSEM_STRUCT_PTR)&kernel_data->IO_LWSEM) is called, but it doesn't, so io_fopen returns null.

   _lwsem_wait((LWSEM_STRUCT_PTR)&kernel_data->IO_LWSEM);

   dev_ptr = (IO_DEVICE_STRUCT_PTR)((pointer)kernel_data->IO_DEVICES.NEXT);

   while (dev_ptr != (pointer)&kernel_data->IO_DEVICES.NEXT) {

      dev_name_ptr = dev_ptr->IDENTIFIER;

      tmp_ptr      = (char _PTR_)open_type_ptr;

      while (*tmp_ptr && *dev_name_ptr &&

         (*tmp_ptr == *dev_name_ptr))

      {

         ++tmp_ptr;

         ++dev_name_ptr;

      } /* Endwhile */

      if (*dev_name_ptr == '\0') {

         /* Match */

         break;

      } /* Endif */

      dev_ptr = (IO_DEVICE_STRUCT_PTR)((pointer)dev_ptr->QUEUE_ELEMENT.NEXT);

   } /* Endwhile */

  

   _lwsem_post((LWSEM_STRUCT_PTR)&kernel_data->IO_LWSEM);

  

   if (dev_ptr == (pointer)&kernel_data->IO_DEVICES.NEXT) {

      return(NULL);

   } /* Endif */

Inside lwsem, there's some code that would change IO_DEVICES.NEXT, but the if statement isn't true, so that code there doesn't execute.

    if ((sem_ptr->VALUE >= 0) && (_QUEUE_GET_SIZE(&sem_ptr->TD_QUEUE)))

    {

        _QUEUE_DEQUEUE(&sem_ptr->TD_QUEUE, td_ptr);

        _BACKUP_POINTER(td_ptr, TD_STRUCT, AUX_QUEUE);

        _TIME_DEQUEUE(td_ptr, kernel_data);

        td_ptr->INFO = 0; /* Signal that post is activating the task */

        _TASK_READY(td_ptr, kernel_data);

        _CHECK_RUN_SCHEDULER(); /* Let higher priority task run */

    }

0 项奖励
回复

1,541 次查看
Martin_
NXP Employee
NXP Employee

then it seems "spi0:" device is not installed. try to to debug _bsp_enable_card(). step into _io_spi_install("spi0:", &_bsp_spi0_init); is this working ?

also you say you debug spi_vybrid_autoevb_a5 ? this BSP will be supported by MQX 4.0.2 which has not been released yet. you can wait for MQX 4.0.2 release in August.

0 项奖励
回复

1,541 次查看
n00b1024
Contributor III

Hi Martin,

Thanks for your advice. I'm running MQX 4.0.2 Beta1, which should (according to the release notes) support SPI. I stepped through the code and didn't see a reference to _bsp_enable_card. Stepping into _io_spi_install, I hit an error at the line below, right after the program initializes the low level driver:

error_code = driver_data->DEVIF->INIT(init_data_ptr->DEVIF_INIT, &(driver_data->DEVIF_DATA));


The error code returned is SPI_ERROR_CHANNEL_INVALID (0xA705).

0 项奖励
回复

1,541 次查看
Martin_
NXP Employee
NXP Employee

SPI is supported, but Vybrid AutoEVB BSP is not fully supported in the 4.0.2 Beta1 version.

There are multiple code lines in the spi low lever driver that can return SPI_ERROR_CHANNEL_INVALID. Which one do you hit ? Why don't you debug down to the lowest level until you see the return SPI_ERROR_CHANNEL_INVALID statement ?

By looking into the code I can see IO_ERROR returned by _bsp_dspi_io_init() in

\mqx\source\bsp\vybrid_autoevb_a5\init_gpio.c

compare to the same function in:

\mqx\source\bsp\twrvf65gs10_a5\init_gpio.c

you will see that you need to implement the pin routing in the _bsp_dspi_io_init() on your own.

0 项奖励
回复