text: /*
   * Copyright (c) 2016, Freescale Semiconductor, Inc.
   * Copyright 2016-2017 NXP
   * All rights reserved.
   *
   * SPDX-License-Identifier: BSD-3-Clause
   */
  
  #include "fsl_spi.h"
  #include "pin_mux.h"
  #include "board.h"
  #include "fsl_debug_console.h"
  
  #include <stdbool.h>
  /*******************************************************************************
   * Definitions
   ******************************************************************************/
  #define EXAMPLE_SPI_MASTER          SPI3
  #define EXAMPLE_SPI_MASTER_IRQ      FLEXCOMM3_IRQn
  #define EXAMPLE_SPI_MASTER_CLK_SRC  kCLOCK_Flexcomm3
  #define EXAMPLE_SPI_MASTER_CLK_FREQ CLOCK_GetFlexCommClkFreq(3)
  #define EXAMPLE_SPI_SSEL            2
  #define EXAMPLE_SPI_SPOL            kSPI_SpolActiveAllLow
  
  /*******************************************************************************
   * Prototypes
   ******************************************************************************/
  
  /*******************************************************************************
   * Variables
   ******************************************************************************/
  #define BUFFER_SIZE (64)
  static uint8_t srcBuff[BUFFER_SIZE];
  static uint8_t destBuff[BUFFER_SIZE];
  /*******************************************************************************
   * Code
   ******************************************************************************/
  
  int main(void)
  {
      spi_master_config_t userConfig = {0};
      uint32_t srcFreq               = 0;
      uint32_t i                     = 0;
      uint32_t err                   = 0;
      spi_transfer_t xfer            = {0};
  
      /* attach 12 MHz clock to FLEXCOMM0 (debug console) */
      CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
  
      /* attach 12 MHz clock to SPI3 */
      CLOCK_AttachClk(kFRO12M_to_FLEXCOMM3);
  
      /* reset FLEXCOMM for SPI */
      RESET_PeripheralReset(kFC3_RST_SHIFT_RSTn);
  
      BOARD_InitPins();
      BOARD_BootClockPLL150M();
      BOARD_InitDebugConsole();
      PRINTF("\n\rMaster Start...\n\r");
      /*
       * userConfig.enableLoopback = false;
       * userConfig.enableMaster = true;
       * userConfig.polarity = kSPI_ClockPolarityActiveHigh;
       * userConfig.phase = kSPI_ClockPhaseFirstEdge;
       * userConfig.direction = kSPI_MsbFirst;
       * userConfig.baudRate_Bps = 500000U;
       */
      SPI_MasterGetDefaultConfig(&userConfig);
      srcFreq            = EXAMPLE_SPI_MASTER_CLK_FREQ;
      userConfig.sselNum = (spi_ssel_t)EXAMPLE_SPI_SSEL;
      userConfig.sselPol = (spi_spol_t)EXAMPLE_SPI_SPOL;
      SPI_MasterInit(EXAMPLE_SPI_MASTER, &userConfig, srcFreq);
  
      /* Init Buffer*/
      for (i = 0; i < BUFFER_SIZE; i++)
      {
          srcBuff[i] = i;
      }
  
      /*Start Transfer*/
      xfer.txData      = srcBuff;
      xfer.rxData      = destBuff;
      xfer.dataSize    = sizeof(destBuff);
      xfer.configFlags = kSPI_FrameAssert;
      SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &xfer);
  
      /*Check if the data is right*/
      for (i = 0; i < BUFFER_SIZE; i++)
      {
          if (srcBuff[i] != destBuff[i])
          {
              err++;
              PRINTF("The %d is wrong! data is %d\n\r", i, destBuff[i]);
          }
      }
      if (err == 0)
      {
          PRINTF("Succeed!\n\r");
      }
  
      while (1)
      {
      }
  }
  