Hot!PIC32MX USB and SPI module don't work at the same time

Author
Tank2005
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2018/10/09 01:45:37
  • Location: 0
  • Status: offline
2019/01/20 03:40:40 (permalink)
0

PIC32MX USB and SPI module don't work at the same time

My environment is MPLAB IDE 5.05, XC32 2.10 and Harmony 2.06 for PIC32MX230F064B on Windows 10(64bit).
 
When I enabled USB driver and 2 SPI(as I2S from a reference clock) drivers from Harmony Configurator, SPI signals doesn't work correctly even if a usb is not initialized.
 
(*From above, SCK1, SCK2, SDO1, SDO2)
 

I tried "FVBUSONIO = OFF" according to past answers, this problem was slightly reduced but it is not completely.
 
Signals seems to be correct if I disable Harmony's USB driver or disable either of the SPI drivers.
 
#include "app.h"
 
APP_DATA appData;
 
#define I2S_START 0
#define I2S_COUNT 2
#define I2S_BUFFER_SIZE 32
#define I2S_BUFFER_COUNT 4
 
typedef struct _I2SData
{
DRV_HANDLE handle;
int mode;
int pos;
uintptr_t context;
DRV_I2S_BUFFER_HANDLE bufHandle[I2S_BUFFER_COUNT];
char send[I2S_BUFFER_COUNT][I2S_BUFFER_SIZE];
char recv[I2S_BUFFER_COUNT][I2S_BUFFER_SIZE];
} I2SData;
 
I2SData i2s[I2S_COUNT];
 
void App_BufferEventHandler(DRV_I2S_BUFFER_EVENT event, DRV_I2S_BUFFER_HANDLE bufferHandle, uintptr_t contextHandle)
{
if(DRV_I2S_BUFFER_EVENT_COMPLETE == event){
} else if(DRV_I2S_BUFFER_EVENT_ERROR == event) {
} else if(DRV_I2S_BUFFER_EVENT_ABORT == event){
}
}
 
bool InitI2S()
{
int mode = DRV_IO_INTENT_READWRITE;
I2SData *ip; int i, j, k; DRV_HANDLE h;
for(i = I2S_START; i < I2S_COUNT; i++){
ip = &i2s[i];

h = DRV_I2S_Open(DRV_I2S_INDEX_0 + i, mode | DRV_IO_INTENT_NONBLOCKING);
if(h == DRV_HANDLE_INVALID) return false;

DRV_I2S_TransmitErrorIgnore(h, true);
DRV_I2S_ReceiveErrorIgnore(h, true);
DRV_I2S_BufferEventHandlerSet(h, App_BufferEventHandler, ip->context);

for(j = 0; j < I2S_BUFFER_COUNT; j++){
for(k = 0; k < I2S_BUFFER_SIZE; k++){
ip->send[j][k] = 0xAC;
}
}

ip->mode = mode;
ip->handle = h;
}
return true;
}
 
void I2STrans(I2SData *d)
{
switch(d->mode){
case DRV_IO_INTENT_READ:
DRV_I2S_BufferAddRead(d->handle, &d->bufHandle[d->pos], d->recv[d->pos], I2S_BUFFER_SIZE);
break;
case DRV_IO_INTENT_WRITE:
DRV_I2S_BufferAddWrite(d->handle, &d->bufHandle[d->pos], d->send[d->pos], I2S_BUFFER_SIZE);
break;
default:
DRV_I2S_BufferAddWriteRead(d->handle, &d->bufHandle[d->pos], d->send[d->pos], d->recv[d->pos], I2S_BUFFER_SIZE);
break;
}
 
d->pos++;
if(d->pos == I2S_BUFFER_COUNT) d->pos = 0;
}
 
void APP_Initialize ( void )
{
int i;
for(i = I2S_START; i < I2S_COUNT; i++){
memset(&i2s[i], 0, sizeof(I2SData));
}
appData.state = APP_STATE_INIT;
}
 
void APP_Tasks ( void )
{
switch ( appData.state ) {
case APP_STATE_INIT:
{
InitI2S();
appData.state = APP_STATE_SERVICE_TASKS;
break;
}
 
case APP_STATE_SERVICE_TASKS:
{
int i;
for(i = I2S_START; i < I2S_COUNT; i++){
I2STrans(&i2s[i]);
}
break;
}
 
default:
{
break;
}
}
}

 
 
post edited by Tank2005 - 2019/02/16 01:14:22

Attached Image(s)

#1

6 Replies Related Threads

    Tank2005
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2018/10/09 01:45:37
    • Location: 0
    • Status: offline
    Re: PIC32MX USB and SPI module don't work at the same time 2019/02/15 06:19:11 (permalink)
    0
    I uploaded a full project arhive here. Anyone?
    #2
    Paul PortSol
    Super Member
    • Total Posts : 376
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: 0
    • Status: offline
    Re: PIC32MX USB and SPI module don't work at the same time 2019/02/15 07:05:54 (permalink)
    0
    Try Larger Heap?
    #3
    Tank2005
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2018/10/09 01:45:37
    • Location: 0
    • Status: offline
    Re: PIC32MX USB and SPI module don't work at the same time 2019/02/16 01:15:19 (permalink)
    0
    Thank you for your replying.
    What does 'heap' refer to. Compiler options, Harmony's SPI queue size or USB endpoint size?
    #4
    Paul PortSol
    Super Member
    • Total Posts : 376
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: 0
    • Status: offline
    Re: PIC32MX USB and SPI module don't work at the same time 2019/02/18 07:53:35 (permalink)
    0
    MHC setting at very bottom, see attached [MHC-Heap.jpg]
     
     
     
     

    Attached Image(s)

    #5
    Paul PortSol
    Super Member
    • Total Posts : 376
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: 0
    • Status: offline
    Re: PIC32MX USB and SPI module don't work at the same time 2019/02/18 08:12:18 (permalink)
    0
    Just for reference: MHC-Heap-UsbHost_20190218PR.zip
    #6
    Tank2005
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2018/10/09 01:45:37
    • Location: 0
    • Status: offline
    Re: PIC32MX USB and SPI module don't work at the same time 2019/02/18 21:16:27 (permalink)
    0
    I prepared some heaps, but unfortunately I could not solve this problem.
     
    The test project I uploaded does not initialize the USB driver(USB_DEVICE_Open 
    was not call) in "app.c". In other words, spi signals becomes unstable only when the framework sets USBPWR = 1.

    Attached Image(s)

    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5