SPI dynamic drivers , running 2 clients issues

Author
pumperthruster
Starting Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2010/11/02 04:06:21
  • Location: 0
  • Status: offline
2017/08/13 02:40:46 (permalink)
0

SPI dynamic drivers , running 2 clients issues

MPBLAB 3.45, Harmony 1.06 , pic32mx795...
 
The demo code in harmony for accessing the eeprom chip , SST25VF020B, works correctly for me.
I also have a SPI thermomneter on my board, and I want to use the same SPI instance (SPI1), for both chips.
I assume this is 2 clients on one SPI instance, for dymanic drivers.
 
When running by themsleves , the eerom chip and the thermometer code works fine (dynamic mode), but when I try run the code together , I get the issue shown below...
 
Here is my Thermometer code:
 
case APP_STATE_INIT:
//open up a handle, this works correctly
appData.SPIHandle = DRV_SPI_Open(DRV_SPI_INDEX_0, DRV_IO_INTENT_READWRITE );

if(appData.SPIHandle != (uintptr_t)NULL)
{
// all good
appData.state = TEMP_SEND_SETUP_CMD;
}
else
SYS_CONSOLE_MESSAGE("Issue opening driver here... \r\n");
break;
case TEMP_SEND_SETUP_CMD:
 
//setup commands for thermometer
appData.TXbuffer[0] = 0x80; /* EEPROM Read Opcode */
appData.TXbuffer[1] = 0; /* Address - LSB */
appData.TXbuffer[2] = 0xf8; /* Address - MSB */
appData.TXbuffer[3] = 0; /* Dummy byte */

TEMPERATURE_CS=1;
//HERE THE CODE FAILS. I GET A SYSTEM CRASH ( _general_exception_handler)
appData.Write_Buffer_Handle = DRV_SPI_BufferAddWrite2(
appData.SPIHandle,(uint8_t *)&appData.TXbuffer[0], 4, NULL, NULL,NULL);
 
.......
 
ON stepping into the line of code above we go here...
DRV_SPI_BUFFER_HANDLE DRV_SPI_BufferAddWrite2 ( DRV_HANDLE handle, void *txBuffer,
size_t size, DRV_SPI_BUFFER_EVENT_HANDLER completeCB, void * context, DRV_SPI_BUFFER_HANDLE * jobHandle )
{
//And it is the line below the crashes...
DRV_SPI_CLIENT_OBJECT * pClient = (DRV_SPI_CLIENT_OBJECT *)handle;
struct DRV_SPI_DRIVER_OBJECT * pDrvObject = pClient->driverObject;
 
........
 
I cannot understand why it is crashes here..It is somehow interfering with the driver instance for the eeprom?
 
Further notes:
I have attached the following files below:
system_init, system_inturrupt, system_tasks,
 
 
#1

2 Replies Related Threads

    ravic
    think_do_repeat
    • Total Posts : 115
    • Reward points : 0
    • Joined: 2016/02/04 03:02:20
    • Location: Bangalore, KA, India
    • Status: offline
    Re: SPI dynamic drivers , running 2 clients issues 2017/08/13 20:54:44 (permalink)
    0
    You have to initialize SPI driver before SST related initialization.
     
    /*** SPI Driver Index 0 initialization***/

        SYS_INT_VectorPrioritySet(DRV_SPI_INT_VECTOR_IDX0, DRV_SPI_INT_PRIORITY_IDX0);
        SYS_INT_VectorSubprioritySet(DRV_SPI_INT_VECTOR_IDX0, DRV_SPI_INT_SUB_PRIORITY_IDX0);
        sysObj.spiObjectIdx0 = DRV_SPI_Initialize(DRV_SPI_INDEX_0, (const SYS_MODULE_INIT * const)&drvSpi0InitData);
        sysObj.drvSst25vf020b0 = DRV_SST25VF020B_Initialize(DRV_SST25VF020B_INDEX_0, (SYS_MODULE_INIT *)&drvSst25vf020b0InitData);



    Always carry latest and best tools, whether it is WAR or PROGRAMMING
    #2
    pumperthruster
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2010/11/02 04:06:21
    • Location: 0
    • Status: offline
    Re: SPI dynamic drivers , running 2 clients issues 2017/08/15 02:44:38 (permalink)
    3 (1)
    I found the error.
     
    In the file drv_sst25vf020b.c
    where we open up a handle to the SPI driver, we see
    case DRV_SST25VF020B_TASK_OPEN_SPI_DRIVER:
    {
    /* Open SPI Driver to read/write in NON Blocking mode with Exclusive privilage */
    hDriver->spiDriverOpenHandle =
    DRV_SPI_Open (hDriver->spiDriverModuleIndex, DRV_IO_INTENT_READWRITE | DRV_IO_INTENT_NONBLOCKING | DRV_IO_INTENT_EXCLUSIVE);
     
    DRV_IO_INTENT_EXCLUSIVE is our problem.
    We cannot allow the eeprom chip to have exclusive rights to the SPI,
    So, we change it to..
    hDriver->spiDriverOpenHandle =
    DRV_SPI_Open (hDriver->spiDriverModuleIndex, DRV_IO_INTENT_READWRITE | DRV_IO_INTENT_NONBLOCKING | DRV_IO_INTENT_ShARED);
     
    Now, we share the SPI resourse. 
    #3
    Jump to:
    © 2017 APG vNext Commercial Version 4.5