Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix board not detected after unplug replug #1

Closed

Conversation

Roosta078
Copy link

I experienced an issue where the headphones would connect be detected by my computer only in BOOTSEL mode. I can flash once in BOOTSEL mode, and it behaves normally until you reboot the computer or unplug/re-plug the device. This behavior was noted on both Linux and Windows. The device does not show up in dmesg when plugged in, which means the device fails very early. For reference on this, see this video for how little is required to show up in dmesg/device manager.

After research, it seems to be the same issue as issue1304 in the pico-sdk repo for the RP2040 Zero. To summarize, the RP2040 SPI clock gets set higher that the flash chip is rated for. This causes the MCU to get held up and not attempt to boot. The solution is to reduce the SPI clock speed so that this does not happen.

My implementation is to define a board header file, specific to the Ploopy Headphone Amplifier Board. It was named to align with the naming convention found in pico-sdk/src/boards/include/. It modifies the configuration that is currently used (pico.h), to have a lower SPI clock. Additional modifications specific to this board can also be made in this file.

@Roosta078
Copy link
Author

Roosta078 commented Jun 30, 2023

Further research has found that another valid solution is to increase the external oscillator startup delay, as discussed in pico-sdk#401 and leave PICO_FLASH_SPI_CLKDIV at 2. By setting PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64, it seems that the clock has enough time to stabilize before we start, compared with the default value of 1. These correspond with delays of 64.7ms and 1.01ms at startup.

Both of these solutions worked equally well for me. I'm open to hear thoughts on which solution may be best

@Roosta078
Copy link
Author

headphones_0416210.zip
Build for those interested in trying out

@ploopyco
Copy link

Originally from here:

Changing PICO_FLASH_SPI_CLKDIV is not preferable. While doing the original dev work, I'd found that reading from flash was unreliable at PICO_FLASH_SPI_CLKDIV values other than 2. I suspect the reason why is that the RP2040 is significantly overclocked, resulting in SPI speeds that are slightly different between actual chips.

I hadn't experimented with PICO_XOSC_STARTUP_DELAY_MULTIPLIER during dev. If it works, I'd go with that.

@Roosta078
Copy link
Author

I made the change. PICO_FLASH_SPI_CLKDIV is left unmodified. PICO_XOSC_STARTUP_DELAY_MULTIPLIER is set to 64. Replugging behavior works properly for me.
@keeb-time could you confirm that this build still works properly for you as well?
headphones_dc0a348.zip

@keeb-time
Copy link

This build works flawlessly so far, I've had no issues with the amp on plug or unplug

@ploopyco
Copy link

I also tested PICO_XOSC_STARTUP_DELAY_MULTIPLIER=64 and it works to eliminate the issue of the DAC failing after an unplug and replug. I plan on integrating this.

@george-norton
Copy link
Owner

@ploopyco have fixed this is their recent firmware builds:
https://github.com/ploopyco/headphones/blob/fd6cbf54d50ba38cd1d3ac8606a676754dc89562/firmware/code/CMakeLists.txt#L65

Thanks very much for your help with this @Roosta078.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants