aovestdipaperino / NRF_I2SPlayer

7 stars 1 forks source link

How to get this to run? Does it only run with the mbed-enabled core? #1

Open simon-hauser opened 1 year ago

simon-hauser commented 1 year ago

Hi, I wanted to try your I2S player with my Xiao nrf52840 BLE Sense, programmed with the Arduino IDE. I could only get my hands on an Adafruit MAX98357A breakout, but that should be the same thing as the sparkfun. So I connected 3.3V and ground, and the Xiao pin 7 to SD, pin 8 to BCLK, and 9 to LRC, and uploaded the sketch with the mbed-enabled core. Should the code as it is produce some hearable sound? I heard nothing at all through my mini speaker (tested before that it works). Or did I miss something?

My second question is about using the mbed-enabled core. It only compiles with this core. Are you using specific functions that are only present in the mbed core, or could this also work in the non-mbed enabled version?

Many thanks for your help! Best regards

aovestdipaperino commented 1 year ago

Hi Simon

  1. I built it for the FreeRTOS core, but let me double check
  2. is it possible that you are using the logical pin numbers in the code instead of the physical pins? https://forum.seeedstudio.com/t/xiao-nrf52840-and-i2s/267502
aovestdipaperino commented 1 year ago

Can you also copy & paste the build errors you are encountering?

simon-hauser commented 1 year ago

Hi, Thanks for the quick response. I'm using the exact code from the repo, with PIN_SDOUT (44), PIN_SCK (45), and PIN_LRCK (46). From the post I concluded that these are pins 7, 8, and 9 on the board, with pin 7 being the one right next to the microphone. Is this correct?

Actually there are no build errors. Once I packed everything into an i2s_simple_wave folder, I can open the .ino file normally, and by using the 2.9.1 seeed nrf52 mbed-enabled board package, the code compiles without errors. I thought I would hear the "shot" sound as this is the one currently in the code, but no sound was hearable. I'm using an 8 ohm 2 watt speaker (that I tested with the PCM.h library on an Arduino Uno), which works there, so I assume it would also work with the adafruit amp. I couldn't test the amp itself as I don't have another hardware to use the I2S interface, but it's brand new so I assume it works...

However I encountered another problem after trying to upload your code. My Xiao bricked out, I believe right after the upload. It suddenly disconnected and reconnected with another COM port as the upload was finished (I think), but now I can't flash anything on it anymore as the IDE (and putty) says that they can't open the COM port anymore... I'm actually a bit stuck with this now, this is the first time I'm dealing with something like that. Have you ever had this problem? My knowledge in fixing this is very limited, at the moment my best guess is to somehow flash the bootloader, as this seems to be the way to unbrick it. Although it's strange that mine still shows up with a COM port, but somehow an inaccessible one...

simon-hauser commented 1 year ago

Also I technically have 2 more Xiao BLE Sense, but I'm a bit hesitant to try the code with another :P. It may not be related with the code itself, but I'm hoping to fix the bricked one first before trying the code again.

aovestdipaperino commented 1 year ago

Bricked unit: have you tried to put it in programming mode by quickly clicking the reset button on the board? A buggy firmware causes the board to crash and/or loop and it won't listen to COM commands anymore. For the worst bricking case I suggest:

  1. https://www.amazon.com/Iunius-Seeeduino-Expansion-Raspberry-Soldering/dp/B095Y9C1SD
  2. combined with a debugger like this: https://www.tindie.com/products/ataradov/cmsis-dap-compliant-swd-debugger/ If you can find the JLink mini EDU in stock anywhere, just buy it!

Then let's go from there -e

simon-hauser commented 1 year ago

I can double click the reset button, then the board shows up as a USB drive with 3 files in it. Somebody told me I can then drop a hex file there (e.g. compiled blink sketch) and the board should execute it, but that didn't work, if it even would work like this. Is there a way to fix it through the bootloader mode? I saw a tutorial on how to flash the bootloader with a Pi (or even EPS32), so I could try that. I also have a JLink compact that I could use.

According to your knowledge, with my situation (can't flash the board through COM port, but can access bootloader mode through double clicking), does this sound like I need to flash a new bootloader?

aovestdipaperino commented 1 year ago

The original bootloader - if you haven't replaced it yet - is quite buggy. I fixed those bugs so you can drop my bootloader in there while in USB mode. https://medium.com/@enzo-lombardi/adding-ota-firmware-update-support-to-xiao-ble-boards-3db6f034c1fa

There is a link to the hex in there.

aovestdipaperino commented 1 year ago

If in USB mode doesn't work, you can follow the Raspberry Pi tutorial or the JLink flashing tool. The only issue is that the SWD pins are on the bottom on the board, and that's where the expansion board helps a lot with the spring pins.

simon-hauser commented 1 year ago

grafik Should the bootloader work right away when I drop it in USB mode? Looks like I can successfully copy the file onto it, but nothing specific happens. The file is gone again after power cycle, and the board takes the same COM port again when connecting, but is still not accepting an upload from the Arduino IDE: the output says "waiting for upload port...", then eventually the upgrade target fails with the message "Serial port could not be opened on COM24. Reason: Cannot configure port, something went wrong. Original message: OSError(22, 'The semaphore timeout period has expired.', None, 121)"

I ordered an expansion board now, I anyway wanted one for another small project, but it will take a couple of days. I might try the Pi method in the meantime and probably would solder jumper wires to the SWD pads.

simon-hauser commented 1 year ago

Hi, Could you just quickly let me know if the bootloader should work as soon as I drop it in USB mode, or if need to somehow execute it? (this should also work with other compiled hex files, right?) Since this doesn't work, I would then move on to flashing a new bootloader.

simon-hauser commented 1 year ago

I managed to unbrick my XIAOs (another one also bricked out). The solution was to enter bootloader mode, then select this new COM port in the Arduino IDE and upload to this one. Very easy, and worked nicely. Now everything is back to normal.

So I could go back to testing the code. I tried the same wiring again, and the same result: Xiao gets flashed, but no sound is hearable, new COM port gets assigned to Xiao, and it bricks out. At least I know how to unbrick it now :P. I don't think this issue has something to do with the wiring yet, but I don't quite know why my Xiao doesn't like your code. Would you have any idea?

simon-hauser commented 1 year ago

Small update on my side. I think I actually wired the DAC wrong. My new wiring is that pin 7 (P1.12) goes into DIN, 8 (P1.13) to BLCK and 9 (P1.14) to LRC. The naming in the sketch is a bit unclear to me: does SDOUT correspond to DIN, and SCK to BLCK? The sparkfun DAC has the same naming as the adafruit (except LRCLK->LRC), so I'm hoping it's correct now.

There is definitely something weird going on with the serial communication when trying the sketch. Something doesn't quite work, but unfortunately I can't say what it is. Every time I try a version of the code I must use the "unbrick" upload solution described above. Once uploaded, because of the while(!Serial) delay(10);, I must open the serial monitor to continue. Interestingly, if I remove the while(!Serial) delay(10);, then the XIAO doesn't even show up as a COM device anymore, whereas I think it should just continue with the code without a serial connection. Also, with the while(!Serial) delay(10);, I must connect to "Seeed XIAO BLE - nrf52840" on the COM port, even though I have a BLE Sense (and I think you also tested it with a BLE Sense). It seems a bit strange to me that only that board selection works. Moreover, the port doesn't actually open, i.e. the Arduino IDE continues trying to open it but can't display any Serial.print commands, but still the code passes the while(!Serial) delay(10);. Currently, I can only debug with LEDs because the serial communication doesn't work. But I checked that the code hangs at line 17 when trying to initialize the I2S player. I don't know where exactly in there it hangs. The only thing I saw was in MP3BufferEncoder.cpp on line 9 you have a comment //BUG. Is maybe there something going south?

It could be nice if you can confirm that the current version of this code runs on your XIAO BLE Sense in Arduino IDE 2.1.0 in trying to eliminate software setup from the issue.

Please let me know what you about all of this :).

simon-hauser commented 1 year ago

Hi, I managed to get some sound out of the XIAO, but using another code.

However, I'd still love to try out your code again. I now know that my setup in general is working. Is there anything I can do to spark your interest again in trying to make it run on my XIAO :P ?

The most important thing for me right now would be to know if your code works for you in the current version and with the most updated library versions (Arduino IDE + mbed core). As described above, for me the code hangs on line 17.

I greatly appreciate your help!

aovestdipaperino commented 1 year ago

Sorry Simon, I will get back to you later this week! I've been traveling a bit

simon-hauser commented 1 year ago

Thanks for your reply! Alright, no worries :).

bulbitron commented 1 year ago

Hi everyone, I'm trying to connect an inmp441 microphone via i2s to the Xiao nrf52840 BLE Sense device and I was doing some research on how to do it, it seems there's a mess with the Xiao nrf52840 BLE Sense pins, and I'm not sure how to connect it correctly, I could put Any link to this code that Simon comments? Thank you very much in advance.

simon-hauser commented 1 year ago

Hi @bulbitron . I was trying the code from here https://forum.arduino.cc/t/i2s-wav-playback-on-nrf52840/1058134/8. For now just distorted sound, I didn't do more progress yet there. I also didn't yet check if the code of this repo here and of the link share some similarities. Curious to hear if it will work out for you :).

simon-hauser commented 1 year ago

Hi Enzo, I'm finally back at this. I just managed to flash a new bootloader onto my bricked xiao sense, but unfortunately it didn't solve the issues. Everything works fine when connecting it, but the Arduino IDE doesn't manage to upload any code, either due to a COM 'PermissionError', but more often due to a 'The semaphore timeout period has expired' error. I tried both the original and your bootloader, different USB ports and cables, no luck so far. Not sure if I'll manage to recover it. Besides this bricked one however, I have two working xiaos with which I could do tests with your code. To me, it still would be most interesting to know if the code works for you in the current version on this repo. If no, I did some limited debugging leading into the initialization of the I2S player and MP3BufferEncoder.cpp (see post above).

I'd still really like to get this to work :). cheers

simon-hauser commented 1 year ago

Hi Enzo, Sorry for the spam :P.

I finally managed to get clean audio output with I2S. I'm using a simpler code and decoded an audio file myself. With this, I might be able to check again your code and remove the (buggy?) MP3Decoder part and just use the I2S player part.

Right now the most pressing issue is if you think this can also work on the non-mbed core. I don't really have an idea on how to go about this, so any help/hint is appreciated.

cheers

bulbitron commented 1 year ago

https://devzone.nordicsemi.com/f/nordic-q-a/15713/i2s-32-bit-word-size correct me if I'm wrong, but if this has not been corrected in the new nordic sdks with the nrfx libraries, I think this problem still exists