Hot!PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode

Author
eevanah
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2017/11/23 02:43:55
  • Location: 0
  • Status: offline
2017/11/27 23:39:53 (permalink)
0

PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode

Hi all! 
I am writing a USB audio application that sends audio from host to speakers. I have been using mac_audio_hi_res application that came with MPLAB Harmony as an example, on PIC32MZ Evaluation board. If I understand correctly, USB host at some point sends data packet to the microchip, based on which interface alternate setting is set. Following is a portion of the code that sets appData.activeInterfaceAlternateSetting
 
void APP_USBDeviceAudioEventHandler
(
    USB_DEVICE_AUDIO_V2_INDEX iAudio ,
    USB_DEVICE_AUDIO_V2_EVENT event ,
    void * pData,
    uintptr_t context
)
{
// A lot of code omitted here for clarity
switch (event)
{
     case USB_DEVICE_AUDIO_V2_EVENT_INTERFACE_SETTING_CHANGED:
          //We have received a request from USB host to change the Interface-Alternate setting.
          interfaceInfo = (USB_DEVICE_AUDIO_V2_EVENT_DATA_SET_ALTERNATE_INTERFACE *)pData;
          appData.activeInterfaceAlternateSetting = interfaceInfo->interfaceAlternateSetting;
          appData.state = APP_USB_INTERFACE_ALTERNATE_SETTING_RCVD;
     break;
}
}

 
Then in APP_Tasks function that runs repeatedly, there is a portion that puts the app in idle state if appData.activeInterfaceAlternateSetting = 0 (APP_USB_SPEAKER_PLAYBACK_NONE) or starts reading/streaming audio data if appData.activeInterfaceAlternateSetting = 1 (APP_USB_SPEAKER_PLAYBACK_STEREO):
 
case APP_USB_INTERFACE_ALTERNATE_SETTING_RCVD:
      if (appData.activeInterfaceAlternateSetting == APP_USB_SPEAKER_PLAYBACK_NONE)
      {
            // A lot of code omitted here for clarity
             appData.state = APP_IDLE;
      }
      else if(appData.activeInterfaceAlternateSetting == APP_USB_SPEAKER_PLAYBACK_STEREO)
      {
            DRV_CODEC_MuteOff(appData.codecClient.handle);
            appData.state = APP_SUBMIT_READ_REQUEST;
       }

 
Everything works well in mac_audio_hi_res example code when I program the device. BUT, in the debug mode appData.activeInterfaceAlternateSetting is always 0 (APP_USB_SPEAKER_PLAYBACK_NONE) and the app is idle. Does anyone have any thoughts about why this is happening? Interestingly, it used to be set to 1 (APP_USB_..._STEREO) even in the debug mode, but it suddenly stopped working. I reinstalled MPLAB IDE and Harmony, but the problem persists.
 
I've been stuck for a while - hope to get some ideas on how to continue.
 
Thanks!
#1

16 Replies Related Threads

    eevanah
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2017/11/23 02:43:55
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2017/11/29 16:42:16 (permalink)
    0
    Ah, it turns out that I cannot debug step by step through the process of setting up the USB interface alternate settings. But, if I don't put any breakpoints there and instead my first breakpoint is somewhere where the reading of audio data starts, then I can continue debugging from there. I suppose connection between with the host is somehow lost if the wait is too long to adjust settings.
    Issue solved :)
     
    #2
    Wavelength
    Super Member
    • Total Posts : 294
    • Reward points : 0
    • Joined: 2012/08/13 08:33:08
    • Location: Cincinnati, Ohio USA
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2018/06/27 08:21:18 (permalink)
    0
    Hey just wondering if you ever got this to work?
     
    For me the thing works, but if you change the sample rate then the eval board and software fails and buzz and recovers sometimes and other times not at all.
     
    Because of that I listed in other posts that I think there is an errata with the PIC32MZ family in the I2S feed. As I spent 4 months trying to fix this problem. When I brought it up with Microchip head office in a conference call they said that the part does not handle sample rate changes on the fly.
     
    This was a bit unsettling as I have been using the PIC32MX270 and full speed USB (UAC1) with a dac chip and sample rates of 44.1, 48, 88.2 and 96 for the last couple years and never had any problem with sample rate change on the fly.
     
    Anyways, just wonder if you got this working as I have almost a 1/2 year invested in this and have to start over.
     
    Thanks,
    Gordon
    #3
    eevanah
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2017/11/23 02:43:55
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2018/07/19 14:34:39 (permalink)
    0
    Sorry for the delay, Gordon. I had the same problem with the evaluation board and demo - there is buzzing when the sample rate is changed on the fly! And Microchip support confirmed that the demo project mac_audio_hi_res is not meant to handle sample rate change on the fly. I was also told that usb_headset can handle it - however, that project didn't work for me at all. But I don't think this is an issue with PIC32MZ family - just with the demo code. However, I didn't find a simple fix for it. Something goes wrong with the reading/writing buffers and the framework used in the project is pretty complicated. 
     
    Wish I could be of more help... I hope you find a solution!
     
    #4
    Wavelength
    Super Member
    • Total Posts : 294
    • Reward points : 0
    • Joined: 2012/08/13 08:33:08
    • Location: Cincinnati, Ohio USA
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2018/07/20 05:59:17 (permalink)
    3 (1)
    Well sorry to say, but it is a problem with the PIC32MZ. After months of various try's it was the results I found that made them realize there was a problem with the I2S feed. The syncLRClock routine was the big indicator that there was a problem. This code originated from the PIC32MX270 code which BTW works fine.
     
    I used the following setup to find the word clock, data clock and data synch problem.
     
    MacBook Pro<==USB protocol analyzer==>BT eval board<---Tek MSO scope with I2S software
     
    If you just go along and don't change the sample rate this works just fine. If you change the sample rate then of course the I2S analyzer goes nuts because of the syncLRClock routine, because for 2000 interrupts the word clock is set in the middle of the stream. It basically never recovers from that.
     
    If you remove the syncLRClock routine and run the same test then the a couple things happen:
    a) The channels are swapped but the sound is ok.
    b) The word clock becomes unsynched to the data and cause noise.
    c) The dac chip can not even sync to the I2S data coming in and therefore mutes
     
    ~~~
     
    The big issue I have here is that 20 months ago the development team told Microchip that they had an issue with the word clock and had to put in this syncLRClock to fix it.
     
    Second when talking to the manager of that group in a conference call with the head brass, it was stated that nobody ever changes the sample rate on the fly and therefore it works fine. Which of course is totally inaccurate statement.
     
    Third this same manager said that the PIC32MX has the same problem. Well that is also wrong I have more than 100K units in the field and that has been tested by over 32 high end audio magazines. Plus these audiophiles are really anal, if there was any of the above problems, believe me we would have known it years ago.
     
    Forth they are not admitting or looking into the problem or adding it to the errata data sheet. They said they are too busy with other things to look at this now.
     
    I know of 5 companies with the same issue, nobody has come up with an answer. I probably have more than 300 hours into it now, even put the DAC chip in master mode and PIC32MZ in slave mode. That worked for like 10 minutes and then it died the same way. Which means to me that something outside of the I2S module is effecting this. If I was a betting man I would say it has something to do with the Frame Sync Control.
     
    Now realize this the SPI module is probably fine in all applications because you are probably not changing the BRG or the speed of the bit clock.
     
    I am still trying to determine the next best possibility. So far it looks like the ARM M7 maybe my best bet. Still 8 months down the drain.
     
    Thanks,
    Gordon
    #5
    eevanah
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2017/11/23 02:43:55
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2018/09/07 11:14:29 (permalink)
    0
    Hi Gordon,
     
    I am not an expert in this area (I am good at coding in general), so it is hard for me to comment in detail. We did struggle with sample rate change too for a very long time. Eventually Microchip said they will look into resolving that issue. In the meantime, we continued breaking apart Harmony framework and writing some code for handling USB data from scratch, and managed to fix the problem ourselves in the end. We used PIC32MZ and it works great now on both Mac and Win. One of the problems that was causing intermittent buzzing on sample rate change is that Harmony used the same chunk of memory to receive USB audio data and send the feedback to the host. That memory allocation was happening in one of the framework files - I can't quite remember which one... but it's not a hardware problem.
     
    I know it's not a detailed response, but perhaps it helps to know there were issues with Harmony framework. I hope that there's been some progress on your end too! 
     
    Best,
    Ivana
    #6
    JarekC
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2016/10/20 07:06:52
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2018/09/07 11:23:42 (permalink)
    0
    Ivana,
     
    Did you write all USB stack?
     
    Regards,
    JarekC
    #7
    eevanah
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2017/11/23 02:43:55
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2018/09/07 11:41:06 (permalink)
    0
    Not all of it - we mostly simplified what was already in Harmony framework. We wrote custom functions to initialize DMA and SPI though. 
    #8
    Wavelength
    Super Member
    • Total Posts : 294
    • Reward points : 0
    • Joined: 2012/08/13 08:33:08
    • Location: Cincinnati, Ohio USA
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2018/09/07 12:07:45 (permalink)
    0
    Ivana,
     
    Glad to hear it. But in my app I had moved the feedback out very early on and made a separate 4 byte area for that. I rewrote the feedback routine because for years I have been looking at feedback on MAC, Windows and Linux with protocol analyzers and came up with a registered algorithm that works better than the Class 1/2 definition. But also does not violate it.
     
    The problem that Jarek and I are talking about is the LRSync that was in the DMA ISR that forced the word clock to either a hard 1 or 0 in the ISR. This was done 2000 times in the DMA ISR with the comment, more is better. Since this was in the DMA ISR it was asyncrhonous to the SPI/I2S modules working of the word clock. This was in there because the engineers in India were having two problems. 1 was that the word clock went wonky and was not properly aligned with the data and bit clock. 2 was that the word clock would flip the channels and all of sudden the audio channels would be swapped on the output.
     
    In a meeting now a number of months ago, Microchip claimed they did not know that sample rate on the fly was something that anyone did. I presented a number of applications with their base code and with my updated code that showed the problem with the following apps: Bit Perfect, Audirvana, J River, Roon, Tidal, Quboz, Decibel and Pure Music.
     
    If your company actually succeeded with this and have tested this on the applications above I would seriously like to talk to you. You can PM me here or go to WavelengthAudio.com
     
    Thanks,
    Gordon
    #9
    eevanah
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2017/11/23 02:43:55
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2018/09/11 17:29:48 (permalink)
    0
    Ahh, I spoke to soon... there still seem to be some issues that need to be fixed :/ It's definitely a challenge! I wonder how long it will take Microchip to address these problems.
    #10
    Wavelength
    Super Member
    • Total Posts : 294
    • Reward points : 0
    • Joined: 2012/08/13 08:33:08
    • Location: Cincinnati, Ohio USA
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2018/09/12 06:31:59 (permalink)
    0
    Ivanah,
     
    I don't think there is anything that you can do that will make this work. I totally rewrote the MX2xx code about 2 years ago to make it asynchronous. I was also one of the developers for the XMOS product. I rewrote the code for the MZ in several versions including SLAVE mode. I have two I2S analyzers here one in my Prism dScope III and another a software module in my TEK MSO scope. It was easy to see the problem on sample change and the effect it had.
     
    I was told by Microchip that the SPI/I2S section was the same as the MX270 core. But as we can see from the errata sheet, sometimes other modules can have various effects on the SPI/I2S module. In this case I think it has something to do with either trying to make the SPI capable of higher rates. Or... the HS USB module is having an effect on it.
     
    The big problem here and what I keep stressing is that Microchip knew of this problem more than a year ago and has nothing to tell the development community about it or act on it to improve the processor line in the future.
     
    Again feel free to PM me if you want help with this or other audio related development.
     
    Thanks,
    Gordon
    #11
    kzeoprf
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2011/09/01 00:25:30
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2019/01/24 00:41:17 (permalink)
    0
    I compiled the mac_hi_res code to a custom board using pic32mz2048efh100 chip. I am connecting the usb to a win10 pc, it gets recognized but I get an error code 10 at driver level. My question if someone can answer is in your case for windows it works without any special driver or it need one?
    #12
    Wavelength
    Super Member
    • Total Posts : 294
    • Reward points : 0
    • Joined: 2012/08/13 08:33:08
    • Location: Cincinnati, Ohio USA
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2019/01/24 07:25:04 (permalink)
    0
    Kzeopf,
     
    Good luck with getting the MZ to work it has a complication in the I2S for which the word clock and bit clock will loose phase with the data.
     
    Windows 10 supports UAC output only and works fine. You can go to the Control Panel Sound and make sure it has the driver correctly installed. You may also want to make sure you have the latest version of code.
     
    Good luck but so far the complication of the MZ problem will not be addressed by Microchip. I went up the ladder and they don't feel it is worth it as it is not a market they are trying get into.
     
    Thanks,
    Gordon
    #13
    kzeoprf
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2011/09/01 00:25:30
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2019/02/18 07:24:28 (permalink)
    0
    Wavelength, thanks for helping.
    So far I have for windows 10:
    1)a working example of a usb2i2s for an pic32mx470ef256 up to 96Khz (192Khs works but I hear the music in strange way).This is a full speed usb audio version 1 example and the system clock to 92KHz. 
    2)Aworking example of the same code ported to a pic32MZ2048efh100, again working up to 96Khz and with the same results on 192Khz. The system clock is at 198Khz.
    3) I ported the code of mac_hi_res_audio example to pic32MZ2048efh100 (system clock is at 198Khz) the usb2 descriptors are recognized i.e the usbaudio2 driver is loaded but the device fails to start with error code 10.
    Have you succesfully tested this code for windows 10 (despite the any synchro problems), and succeded 192khz despite any problems, or you have the same behaviour ? If yes is there anything I have to change, any hint will be very helpfull, I can not find why this is failling to start?
    Thanks
    #14
    Wavelength
    Super Member
    • Total Posts : 294
    • Reward points : 0
    • Joined: 2012/08/13 08:33:08
    • Location: Cincinnati, Ohio USA
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2019/02/18 07:49:47 (permalink)
    0
    Ok let me answers these one at a time.

    1)a working example of a usb2i2s for an pic32mx470ef256 up to 96Khz (192Khs works but I hear the music in strange way).This is a full speed usb audio version 1 example and the system clock to 92KHz. 
     
    > In full speed audio the maximum stereo rate is limited to 96KHz. The calculation goes like this 6 (number of bytes in two channels at 24 bits) x 96 = 576 bytes. The limit for full speed is 1023 bytes per 1ms frame.
     
    > By system clock do you mean 92MHZ? Really better off to use 96MHZ.

    2)Aworking example of the same code ported to a pic32MZ2048efh100, again working up to 96Khz and with the same results on 192Khz. The system clock is at 198Khz.
     
    > Do you mean 198MHZ? The system clock has no reflection of the maximum sample rate. Also the full speed code is designated as UAC1 (USB Audio Class version 1 specification). This again is relegated to a maximum sample rate of 96KHz for the same reason above because the USB will be running in Full Speed not High Speed.

    3) I ported the code of mac_hi_res_audio example to pic32MZ2048efh100 (system clock is at 198Khz) the usb2 descriptors are recognized i.e the usbaudio2 driver is loaded but the device fails to start with error code 10.
    Have you succesfully tested this code for windows 10 (despite the any synchro problems), and succeded 192khz despite any problems, or you have the same behaviour ? If yes is there anything I have to change, any hint will be very helpfull, I can not find why this is failling to start?
     
    > Well this a total waste of time since all the MZ processors are flawed if you are going to change the sample rate to anything. If you want the host to resample the audio rate to one fixed rate on the MZ platform then maybe you could get the code to work. I spent almost a whole year on it and it was a total waste of time. Microchip informed me they never tested it correctly and thought that products under UAC2 (high speed USB audio specification) never changed sample rates. Which most modern applications do.
     
    You can debug the MZ high res code and get rid of the startup problem. I forget what the problem with that was. None of this is of course supported after I found all the problems Microchip dumped the mac_hi_res_audio product leaving it with a message that it may not work for you. Or anyone...
     
    Thanks, sorry I couldn't be more helpful. I would suggest if you need 192Khz sample rate that you look at alternative processors.
     
    Thanks,
    Gordon
    #15
    kzeoprf
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2011/09/01 00:25:30
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2019/02/18 08:02:06 (permalink)
    0
    Thanks, I am only trying because in this page states that is fisible: https://www.beis.de/Elektronik/DA2USB/DA2USB.html
    Anyway if you will remember in the meantime what was the startup problem, please give us a hint.
    Thanks again.
    #16
    JarekC
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2016/10/20 07:06:52
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB Audio - Cannot set correct interface alternate setting in debug mode 2019/02/18 13:11:13 (permalink)
    0
    PIC32MZ (USB HS+SPI) works fine.
    Bugs are in Harmony libraries (USB HS, SPI, DMA) and in example code but NOT in hardware.
    I have working USB Audio 2.0 code (44.1 ,48 ,88.2, 96, 176,4 192Khz), it is commercial project so I can't attach source code.
     
    Regards
    JarekC.DIY
     
     
    #17
    Jump to:
    © 2019 APG vNext Commercial Version 4.5