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

A little fixes for making work SAMD51 with I2S #85

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

A little fixes for making work SAMD51 with I2S #85

wants to merge 3 commits into from

Conversation

nekuneko
Copy link

@nekuneko nekuneko commented Feb 4, 2019

A little fixes for making work SAMD51 with I2S

@nekuneko
Copy link
Author

nekuneko commented Feb 4, 2019

It's still uncomplete, it is needed to modify DMA utility

@ladyada
Copy link
Member

ladyada commented Feb 4, 2019

thanks! if you can also please remove the "// <--- ERROR SAMD51" comments?

@nekuneko
Copy link
Author

nekuneko commented Feb 4, 2019

Of course, sorry for that! Probably there are more bugs ^^"

@tgvarik
Copy link

tgvarik commented Feb 4, 2019

Trying to build these changes for the Feather M4 Express, I still get compiler errors about undeclared VARIANT_GCLK1_FREQ at I2S.cpp:459, among other undeclared clock-related errors. So the fixes to enableClock() and disableClock() don't work for that board.

I'm continuing to poke around and see if I can work out a fix.

@tgvarik
Copy link

tgvarik commented Feb 4, 2019

Adding

#ifndef VARIANT_GCLK1_FREQ
#define VARIANT_GCLK1_FREQ (48000000UL)
#endif

to I2S.h is sufficient to get the changes to compile for the Feather M4, but that's a hack. The call to I2S.begin() then hangs, which I think is expected with current changes.

@nekuneko
Copy link
Author

nekuneko commented Feb 4, 2019

Note that VARIANT_GCLK1_FREQ constant is defined on variant.h file of the board. Please check you have an updated version of Adafruit SAMD core, I have version 1.2.9. Here you have this file location on Windows:

Adafruit Metro M4:
C:\Users\User\AppData\Local\Arduino15\packages\adafruit\hardware\samd\1.2.9\variants\metro_m4\variant.h

Adafruit Feather M4:
C:\Users\User\AppData\Local\Arduino15\packages\adafruit\hardware\samd\1.2.9\variants\feather_m4\variant.h

At the very begining of the file you must find this code:

#ifndef _VARIANT_FEATHER_M4_
#define _VARIANT_FEATHER_M4_

// The definitions here needs a SAMD core >=1.6.10
#define ARDUINO_SAMD_VARIANT_COMPLIANCE 10610

/*----------------------------------------------------------------------------
 *        Definitions
 *----------------------------------------------------------------------------*/

/** Frequency of the board main oscillator */
#define VARIANT_MAINOSC		(32768ul)

/** Master clock frequency */
#define VARIANT_MCK			  (120000000ul)

#define VARIANT_GCLK0_FREQ (120000000UL)
#define VARIANT_GCLK1_FREQ (48000000UL)
#define VARIANT_GCLK2_FREQ (100000000UL)

This file is linked during compilation (it defines all your board pinout) so that constant cannot be missing at all.

@tgvarik
Copy link

tgvarik commented Feb 5, 2019

There's the problem. I'm using PlatformIO and PlatformIO is still on 1.2.3. PlatformIO doesn't have a self-service way to update, so... platformio/platformio-pkg-framework-arduinosam#8

@tgvarik
Copy link

tgvarik commented Feb 5, 2019

I've done a bit more tinkering and I'm able to see some clock signals, just not the ones I expect. If I configure the I2S singleton thusly:

I2S = I2SClass(I2S_DEVICE, I2S_CLOCK_GENERATOR, PIN_I2S_SDO, PIN_I2S_SCK, PIN_I2S_FS);

...then PIN_I2S_SCK ends up getting the serial clock at the expected frequency. But PIN_I2S_FS is getting the MCLK, not the frame select clock. So now I'm digging into the port config.

(Actually, if I just use those pins as they're defined in variant.h for my board, the Feather M4 Express, I don't get any clock on any pins. But if I map them to other pins I get them. I'm not too concerned about that right now, so I'm focusing on the other issue right now.)

@@ -145,9 +147,15 @@ int I2SClass::begin(int mode, long sampleRate, int bitsPerSample, bool driveCloc
i2sd.setSlotSize(_deviceIndex, bitsPerSample);
i2sd.setDataSize(_deviceIndex, bitsPerSample);

#if defined(__SAMD51__)
pinPeripheral(_sckPin, PIO_I2S);
pinPeripheral(_fsPin, PIO_I2S);
Copy link

@tgvarik tgvarik Apr 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As written, I get the bit sync clock (sampleRate * 2 * bitsPerSample) on the pin identified by _sckPin and the master clock (sampleRate * 256) on the pin identified by _fsPin. And with my mic connected to these pins nothing comes out of the mic's data pin. However, if I add another statement after these two:

pinPeripheral(10, PIO_I2S); // just used pin 10 for testing

I then in addition to the above I also get the frame sync clock (sampleRate) on the new pin (pin 10 in this case). And if I wire up the new pin to my mic instead of the old pin (_fsPin), I get data out of my mic's data pin.

Despite seeing data coming out of the mic on the scope, I'm still getting all zeros reading it in my sketch, but this is progress of a kind.

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.

3 participants