Use MC Demo to write user data to external QSPI Flash when use usb audio mode

Sub forums for various specialist XMOS applications. e.g. USB audio, motor control and robotics.
careyl
Junior Member
Posts: 7
Joined: Mon Aug 14, 2017 9:10 am

Use MC Demo to write user data to external QSPI Flash when use usb audio mode

Post by careyl »

Dear All

I am now use xcore-200 MC AUDIO , my application use usb2.0, 4 channel input and 2 channel output, I also have some data to storage, means power-down save , so i want to use the external QSPI flash on board to save my user data.

this is my flash test code:

Code: Select all

#if 1
#define START_LOC 0x100     // Start location of text data in data partition
#define TEXT_SIZE 29        // Size of text


int flash_connect() {
  int res;
  //res = fl_connectToDevice(p_qflash, deviceSpecs, 1);
  res = fl_connectToDevice(&p_qflash, flash_devices, 1);
  //res = fl_connectToDevice(p_flash);
  if( res != 0 ) {
    return(0);
  }
  return 1;
}

void test_flash( void )
{
  /*Array to store the data to be written to the flash*/
  unsigned char my_data[256],my_data1[256], buffer[4096];

  /*Variables forbuffering, counting iterations,etc*/
  unsigned int temp, i;
  printstrln( "2" );

  //Initialise the my_data array
  for ( i = 0; i < 256; i++ ){
    my_data[i] = 0x00;
    my_data1[i] = 0x00;
  }

  //Write "Hello World" to the my_data data array

  my_data[0] = '!';
  my_data[1] = '!';
  my_data[2] = '*';
  my_data[3] = '*';
  my_data[4] = ' ';
  my_data[5] = 'H';
  my_data[6] = 'a';
  my_data[7] = 'p';
  my_data[8] = 'p';
  my_data[9] = 'y';
  my_data[10] = ' ';
  my_data[11] = 'N';
  my_data[12] = 'e';
  my_data[13] = 'w';
  my_data[14] = ' ';
  my_data[15] = 'Y';
  my_data[16] = 'e';
  my_data[17] = 'a';
  my_data[18] = 'r';
  my_data[19] = ' ';
  my_data[20] = '2';
  my_data[21] = '0';
  my_data[22] = '1';
  my_data[23] = '8';
  my_data[24] = ' ';
  my_data[25] = '^';
  my_data[26] = '^';
  my_data[27] = '$';
  my_data[28] = '$';
//  my_data[29] = '\0';

  if ( !flash_connect() ){
        printstrln( "1" );
        return;
      }
  
  temp = fl_getPageSize();

  printstr( "FLASH page size: " );
  printuint(temp);
  printstrln( " bytes." );

  temp = fl_getFlashSize();
    printstr( "FLASH size: " );
    printuint(temp);
    printstrln( " bytes." );

    // Get the FLASH page size
    temp = fl_getPageSize();
    printstr( "FLASH page size: " );
    printuint(temp);
    printstrln( " bytes." );

    // Get the FLASH data partition size
    temp = fl_getDataPartitionSize();
    printstr( "FLASH data partition size: " );
    printuint(temp);
    printstrln( " bytes." );

    // Get the FLASH data pages
    temp = fl_getNumDataPages();
    printstr( "FLASH number of pages in data partition: " );
    printuintln( temp );

    // Get the FLASH data sectors
    temp = fl_getNumDataSectors();
    printstr( "FLASH number of sectors in data partition: " );
    printuintln( temp );

    // Get the FLASH data sector size
    temp = fl_getDataSectorSize(0);
    printstr( "FLASH data sector size: " );
    printuint(temp);
    printstrln( " bytes." );

    // Wipe the data partition
     if ( 0 != fl_eraseAllDataSectors() ){
      printstrln( "Could not erase the data partition" );
      return;
    }

    if ( 0 !=  fl_writeData(START_LOC, TEXT_SIZE, my_data, buffer) ){
        printstrln( "Could not write the data partition" );
        return;
      }

      printstrln( "Data partition written!" );

      // Read from the data partition
      if ( 0 !=  fl_readData(START_LOC, TEXT_SIZE, my_data1) ){
        printstrln( "Could not read the data partition" );
        return;
      }

      // Return the contents of the data partition to the user
      printstr( "Data partition read! Data: " );
      printstrln( my_data1 );
}

#endif//if 1
then in main:

Code: Select all

on tile[0]:
{
    test_flash();
}
then i use foobar to paly music, here comes the question, foobar shows palyback error: unrecoverable playback error: Could not creat ASIO buffer.


User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm
Contact:

Post by Bianco »

In the code you provide you only call functions to access the flash memory, not any USB/Audio code?
careyl
Junior Member
Posts: 7
Joined: Mon Aug 14, 2017 9:10 am

Post by careyl »

Hi Bianco

Thank you for your reply.

It have Audio code in main, I use usb audio 2.0 software version 6.15.2

I only add test_flash(); in main

/* Main for USB Audio Applications */
int main()
{
chan c_mix_out;
#ifdef MIDI
chan c_midi;
#endif
#ifdef IAP
chan c_iap;
#ifdef IAP_EA_NATIVE_TRANS
chan c_ea_data;
#endif
#endif
#ifdef SU1_ADC_ENABLE
chan c_adc;
#else
#define c_adc null
#endif

#ifdef MIXER
chan c_mix_ctl;
#endif

#ifdef AUDIO_CFG_CHAN
chan c_aud_cfg;
#else
#define c_aud_cfg null
#endif

#ifdef SPDIF_RX
streaming chan c_spdif_rx;
#else
#define c_spdif_rx null
#endif

#ifdef ADAT_RX
chan c_adat_rx;
#else
#define c_adat_rx null
#endif

#if defined(SPDIF_TX) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
chan c_spdif_tx;
#endif


#if (defined (SPDIF_RX) || defined (ADAT_RX))
chan c_clk_ctl;
chan c_clk_int;
#else
#define c_clk_int null
#define c_clk_ctl null
#endif

#ifdef DFU
interface i_dfu dfuInterface;
#else
#define dfuInterface null
#endif

#if (NUM_PDM_MICS > 0)
chan c_pdm_pcm;
#endif

USER_MAIN_DECLARATIONS


par
{
on tile[XUD_TILE]:
par
{
#if (XUD_TILE == 0)
/* Check if USB is on the flash tile (tile 0) */
#ifdef DFU
[[distribute]]
DFUHandler(dfuInterface, null);
#endif
#endif
usb_audio_core(c_mix_out
#ifdef MIDI
, c_midi
#endif
#ifdef IAP
, c_iap
#ifdef IAP_EA_NATIVE_TRANS
, c_ea_data
#endif
#endif
#ifdef MIXER
, c_mix_ctl
#endif
, c_clk_int, c_clk_ctl, dfuInterface

);
}
/**/

//par{
on tile[0]:
//if(tested1 == 0)
//{
//thread_speed();
//tested1 = 1;
test_flash();
//}
//}

on tile[AUDIO_IO_TILE]: usb_audio_io(c_mix_out, c_adc
#if defined(SPDIF_TX) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
, c_spdif_tx
#endif
#ifdef MIXER
, c_mix_ctl
#endif
, c_aud_cfg, c_spdif_rx, c_adat_rx, c_clk_ctl, c_clk_int
#if XUD_TILE != 0
, dfuInterface
#endif
#if (NUM_PDM_MICS > 0)
, c_pdm_pcm
#endif

);

#if defined(SPDIF_TX) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
on tile[SPDIF_TX_TILE]:
{
thread_speed();
SpdifTxWrapper(c_spdif_tx);
}
#endif

#if defined(MIDI) && defined(IAP) && (IAP_TILE == MIDI_TILE)
/* MIDI and IAP share a core */
on tile[IAP_TILE]:
{
thread_speed();
usb_midi(p_midi_rx, p_midi_tx, clk_midi, c_midi, 0, c_iap, null, null, null);
}
#else
#if defined(MIDI)
/* MIDI core */
on tile[MIDI_TILE]:
{
thread_speed();
usb_midi(p_midi_rx, p_midi_tx, clk_midi, c_midi, 0, null, null, null, null);
}
#endif
#if defined(IAP)
on tile[IAP_TILE]:
{
thread_speed();
iAP(c_iap, null, null, null);
}
#endif
#endif

#ifdef SPDIF_RX
on tile[XUD_TILE]:
{
thread_speed();
SpdifReceive(p_spdif_rx, c_spdif_rx, 1, clk_spd_rx);
}
#endif

#ifdef ADAT_RX
on stdcore[XUD_TILE] :
{
set_thread_fast_mode_on();

#if(XUD_SERIES_SUPPORT == XUD_L_SERIES)
/* Can't use REF clock on L-series as this is usb clock */
set_port_clock(p_adat_rx, clk_adat_rx);
start_clock(clk_adat_rx);
#endif
while (1)
{
adatReceiver48000(p_adat_rx, c_adat_rx);
adatReceiver44100(p_adat_rx, c_adat_rx);
}
}
#endif

#if (NUM_PDM_MICS > 0)
on stdcore[PDM_TILE]: pcm_pdm_mic(c_pdm_pcm);
#endif
USER_MAIN_CORES
}

#ifdef SU1_ADC_ENABLE
xs1_su_adc_service(c_adc);
#endif

return 0;
}
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm
Contact:

Post by Bianco »

Are you printing through JTAG? This may mess with the timing of other threads because the whole core can be halted during communication with the host.
careyl
Junior Member
Posts: 7
Joined: Mon Aug 14, 2017 9:10 am

Post by careyl »

Hi Bianco

Yes,I have tried to mark all the printf in test_flash(), just use flash_connect

if ( !flash_connect() ){
printstrln( "1" );
return;
}

As follow:
#if 1
#define START_LOC 0x100 // Start location of text data in data partition
#define TEXT_SIZE 29 // Size of text


int flash_connect() {
int res;
//res = fl_connectToDevice(p_qflash, deviceSpecs, 1);
res = fl_connectToDevice(&p_qflash, flash_devices, 1);
//res = fl_connectToDevice(p_flash);
if( res != 0 ) {
return(0);
}
return 1;
}

void test_flash( void )
{
/*Array to store the data to be written to the flash*/
unsigned char my_data[256],my_data1[256], buffer[4096];

/*Variables forbuffering, counting iterations,etc*/
unsigned int temp, i;
printstrln( "2" );

//Initialise the my_data array
for ( i = 0; i < 256; i++ ){
my_data = 0x00;
my_data1 = 0x00;
}

//Write "Hello World" to the my_data data array

my_data[0] = '!';
my_data[1] = '!';
my_data[2] = '*';
my_data[3] = '*';
my_data[4] = ' ';
my_data[5] = 'H';
my_data[6] = 'a';
my_data[7] = 'p';
my_data[8] = 'p';
my_data[9] = 'y';
my_data[10] = ' ';
my_data[11] = 'N';
my_data[12] = 'e';
my_data[13] = 'w';
my_data[14] = ' ';
my_data[15] = 'Y';
my_data[16] = 'e';
my_data[17] = 'a';
my_data[18] = 'r';
my_data[19] = ' ';
my_data[20] = '2';
my_data[21] = '0';
my_data[22] = '1';
my_data[23] = '8';
my_data[24] = ' ';
my_data[25] = '^';
my_data[26] = '^';
my_data[27] = '$';
my_data[28] = '$';
// my_data[29] = '\0';

if ( !flash_connect() ){
printstrln( "1" );
return;
}
#if 0
temp = fl_getPageSize();

printstr( "FLASH page size: " );
printuint(temp);
printstrln( " bytes." );

temp = fl_getFlashSize();
printstr( "FLASH size: " );
printuint(temp);
printstrln( " bytes." );

// Get the FLASH page size
temp = fl_getPageSize();
printstr( "FLASH page size: " );
printuint(temp);
printstrln( " bytes." );

// Get the FLASH data partition size
temp = fl_getDataPartitionSize();
printstr( "FLASH data partition size: " );
printuint(temp);
printstrln( " bytes." );

// Get the FLASH data pages
temp = fl_getNumDataPages();
printstr( "FLASH number of pages in data partition: " );
printuintln( temp );

// Get the FLASH data sectors
temp = fl_getNumDataSectors();
printstr( "FLASH number of sectors in data partition: " );
printuintln( temp );

// Get the FLASH data sector size
temp = fl_getDataSectorSize(0);
printstr( "FLASH data sector size: " );
printuint(temp);
printstrln( " bytes." );

// Wipe the data partition
if ( 0 != fl_eraseAllDataSectors() ){
printstrln( "Could not erase the data partition" );
return;
}

if ( 0 != fl_writeData(START_LOC, TEXT_SIZE, my_data, buffer) ){
printstrln( "Could not write the data partition" );
return;
}

printstrln( "Data partition written!" );

// Read from the data partition
if ( 0 != fl_readData(START_LOC, TEXT_SIZE, my_data1) ){
printstrln( "Could not read the data partition" );
return;
}

// Return the contents of the data partition to the user
printstr( "Data partition read! Data: " );
printstrln( my_data1 );
#endif
}

#endif//if 1
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

Bianco's point about
Are you printing through JTAG?
is important to verify first - see here:

http://www.xcore.com/viewtopic.php?f=47 ... 751#p21751
careyl
Junior Member
Posts: 7
Joined: Mon Aug 14, 2017 9:10 am

Post by careyl »

I didn't use printf in flash test
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

It doesn't matter which print you call (printf, printstr) it all calls the same mechanism below.. If the mechanism below is interrupting other cores then it could be the source of your issue
careyl
Junior Member
Posts: 7
Joined: Mon Aug 14, 2017 9:10 am

Post by careyl »

Got it,so how could I close all the print?
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

I recommend enabling xscope (http://www.xcore.com/viewtopic.php?f=47 ... 751#p21751) so you can continue to use debug prints but with minimal intrusion to your code.
Post Reply