void hardware_init(void) { uint8_t i; /* enable clock for PORTs */ for (i = 0; i < PORT_INSTANCE_COUNT; i++) { CLOCK_SYS_EnablePortClock(i); } #if (SD_CARD_APP) #if ((defined TWR_K64F120M) || (defined FRDM_K64F) || (defined TWR_K60D100M) || (defined TWR_K21F120M) || (defined TWR_K65F180M)) /* configure detect pin as gpio (alt1) */ uint32_t port = GPIO_EXTRACT_PORT(sdhcCdPin[0].pinName); uint32_t pin = GPIO_EXTRACT_PIN(sdhcCdPin[0].pinName); PORT_Type * portBase = g_portBase[port]; PORT_HAL_SetMuxMode(portBase, pin, kPortMuxAsGpio); configure_sdhc_pins(BOARD_SDHC_INSTANCE); #endif #endif /* Init board clock */ BOARD_ClockInit(); dbg_uart_init(); }
/*! * \cond DOXYGEN_PRIVATE * \brief Initialization - called from init task, usually for io initialization. */ int _bsp_init(void) { uint32_t result = MQX_OK; /** Cache settings **/ _DCACHE_ENABLE(0); _ICACHE_ENABLE(0); /* Disable MPU if present on device. This dirty hack is done to workaround missing MPU_DRV_Disable() function in KSDK */ #ifdef MPU_INSTANCE_COUNT for(int i = 0; i < MPU_INSTANCE_COUNT; i++) { MPU_HAL_Disable(g_mpuBase[i]); } #endif /****************************************************************************** Install interrupts for UART driver and setup debug console ******************************************************************************/ #if BSPCFG_ENABLE_IO_SUBSYSTEM _bsp_nio_stdio_install(); #else /* BSPCFG_ENABLE_IO_SUBSYSTEM */ #if !defined(PEX_MQX_KSDK) dbg_uart_init(); #endif #endif /* BSPCFG_ENABLE_IO_SUBSYSTEM */ return result; }
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTA_IDX); CLOCK_SYS_EnablePortClock(PORTC_IDX); CLOCK_SYS_EnablePortClock(PORTD_IDX); CLOCK_SYS_EnablePortClock(PORTE_IDX); /* Init board clock */ BOARD_ClockInit(); dbg_uart_init(); /*Set Flexio clock source*/ CLOCK_HAL_SetLircCmd(MCG, true); CLOCK_HAL_SetLircSelMode(MCG,kMcgliteLircSel2M); CLOCK_SYS_SetFlexioSrc(0U, kClockFlexioSrcMcgIrClk); configure_flexio_pins(0U,4U);/*if enable TX output to check IRDA encode data waveform--PTD4 */ configure_flexio_pins(0U,5U); /*if enable RX output to check IRDA decode waveform--PTD5 */ configure_flexio_pins(0U,6U); /*IRDA RX pin -- PTD6 */ configure_flexio_pins(0U,7U); /*IRDA TX pin -- PTD7 */ configure_cmp_pins(0U); /*CMP out as Flexio trigger source if enabled*/ }
/*! * @brief Main function */ int main (void) { // RX buffers //! @param receiveBuff Buffer used to hold received data uint8_t receiveBuff; // Initialize standard SDK demo application pins hardware_init(); // Call this function to initialize the console UART. This function // enables the use of STDIO functions (printf, scanf, etc.) dbg_uart_init(); // Print the initial banner PRINTF("\r\nHello World!\n\n\r"); while(1) { // Main routine that simply echoes received characters forever // First, get character receiveBuff = GETCHAR(); // Now echo the received character PUTCHAR(receiveBuff); } }
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTA_IDX); /* Init board clock */ BOARD_ClockInit(); dbg_uart_init(); }
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTA_IDX); CLOCK_SYS_EnablePortClock(PORTD_IDX); CLOCK_SYS_EnablePortClock(PORTE_IDX); configure_i2c_pins(0U); /* Init board clock */ BOARD_ClockInit(); dbg_uart_init(); }
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTA_IDX); CLOCK_SYS_EnablePortClock(PORTB_IDX); CLOCK_SYS_EnablePortClock(PORTC_IDX); configure_i2c_pins(BOARD_I2C_COMM_INSTANCE); /* Init board clock */ BOARD_ClockInit(); dbg_uart_init(); }
int main(void) { /* Initialize board hardware */ hardware_init(); OSA_Init(); /* Initialize debug serial interface */ dbg_uart_init(); /* Call example task */ ltc_example_task(); while(1); }
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTA_IDX); CLOCK_SYS_EnablePortClock(PORTB_IDX); configure_tpm_pins(0); /* Init board clock */ BOARD_ClockInit(); /* Select the clock source for the TPM counter */ CLOCK_SYS_SetTpmSrc(BOARD_TPM_INSTANCE, kClockTpmSrcIrc48M); dbg_uart_init(); }
/* main Note: Program entry, do nessary initialization and lanuch scheduler, in baremetal OSA, it simplely call all tasks in sequence */ int main(void) { OSA_Init(); hardware_init(); dbg_uart_init(); comm_init(); audio_init(); usb_init(); OS_Task_create(usb_user_task, NULL, 9L, 3000L, "usb task", NULL); OSA_Start(); return 1; }
/*! * @brief main function */ int main (void) { // Configure board specific pin muxing hardware_init(); // Initialize UART terminal dbg_uart_init(); while(1) { demo_state_machine(); // User menu, viewable through serial terminal } }
void hardware_init(void) { uint16_t i; /* enable clock for PORTs */ for (i = 0; i < PORT_INSTANCE_COUNT; i++) { CLOCK_SYS_EnablePortClock(i); } /* Init board clock */ BOARD_ClockInit(); dbg_uart_init(); }
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTA_IDX); CLOCK_SYS_EnablePortClock(PORTB_IDX); CLOCK_SYS_EnablePortClock(PORTC_IDX); CLOCK_SYS_EnablePortClock(PORTD_IDX); CLOCK_SYS_EnablePortClock(PORTE_IDX); /* Init board clock */ BOARD_ClockInit(); dbg_uart_init(); GPIO_DRV_Init(switchPins, ledPins); }
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTA_IDX); CLOCK_SYS_EnablePortClock(PORTC_IDX); CLOCK_SYS_EnablePortClock(PORTD_IDX); /* Init board clock */ BOARD_ClockInit(); dbg_uart_init(); // Configure SPI pins configure_spi_pins(1U); }
/*! * @brief The i2c slave * The function runs i2c slave with interrupt active mode. Slave receive data from * master and echo back to master */ void main(void) { // Number byte data will be transfer uint32_t count = 0; // Buffer store data to transfer uint8_t dataBuff[100] = {0}; // state of slave i2c_slave_state_t slave; // user configuration i2c_slave_user_config_t userConfig = { .address = 0x7FU, .slaveCallback = NULL, .callbackParam = NULL, .slaveListening = false, #if FSL_FEATURE_I2C_HAS_START_STOP_DETECT .startStopDetect = false, #endif #if FSL_FEATURE_I2C_HAS_STOP_DETECT .stopDetect = false, #endif }; // Initialize hardware hardware_init(); // Configure pin for i2c slave configure_i2c_pins(BOARD_I2C_COMM_INSTANCE); // Initialize uart to debug dbg_uart_init(); // Initialize OSA OSA_Init(); printf("Slave is running ..."); // Initialize slave I2C_DRV_SlaveInit(BOARD_I2C_COMM_INSTANCE, &userConfig, &slave); // Loop transfer while(1) { // Slave receive 1 byte from master I2C_DRV_SlaveReceiveDataBlocking(BOARD_I2C_COMM_INSTANCE, (uint8_t*)&count, 1, OSA_WAIT_FOREVER); // Slave receive buffer from master I2C_DRV_SlaveReceiveDataBlocking(BOARD_I2C_COMM_INSTANCE, dataBuff, count, 1000); // Slave send buffer received from master I2C_DRV_SlaveSendDataBlocking(BOARD_I2C_COMM_INSTANCE, dataBuff, count, 1000); } }
_WEAK_FUNCTION(void hardware_init(void)) { uint8_t i; /* enable clock for PORTs */ for (i = 0; i < PORT_INSTANCE_COUNT; i++) { CLOCK_SYS_EnablePortClock(i); } /* Init board clock */ BOARD_ClockInit(); /* In case IO sub is turned off, dbg console should be used for printing */ #if !BSPCFG_ENABLE_IO_SUBSYSTEM dbg_uart_init(); #endif }
/*! * @brief The i2c slave * The function runs i2c slave with polling mode (HAL layer). Slave receive data * from master and echo back to master */ void main(void) { // Number byte data will be transfer uint32_t count = 0; // Buffer store data to transfer uint8_t dataBuff[50] = {0}; // slave address uint16_t address = 0x7FU; // i2c slave base address I2C_Type * baseAddr = (I2C_Type*)I2C0_BASE; // Initialize hardware hardware_init(); // Configure pin for i2c slave configure_i2c_pins(BOARD_I2C_COMM_INSTANCE); // Initialize uart to debug dbg_uart_init(); printf("Slave is running ..."); /* Enable clock for I2C.*/ CLOCK_SYS_EnableI2cClock(BOARD_I2C_COMM_INSTANCE); /* Init instance to known state. */ I2C_HAL_Init(baseAddr); /* Set slave address.*/ I2C_HAL_SetAddress7bit(baseAddr, address); /* Enable the peripheral operation.*/ I2C_HAL_Enable(baseAddr); // Loop transfer while(1) { // count is length of string I2C_HAL_SlaveReceiveDataPolling(baseAddr, (uint8_t*)&count, 1); // Slave receive buffer from master I2C_HAL_SlaveReceiveDataPolling(baseAddr, dataBuff, count); // Slave send buffer received from master I2C_HAL_SlaveSendDataPolling(baseAddr, dataBuff, count); } }
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTB_IDX); CLOCK_SYS_EnablePortClock(PORTC_IDX); configure_cmp_pins(0); /* Board don't have pull up resister, so internal resister need to be enabled */ PORT_HAL_SetMuxMode(PORTB,2U,kPortMuxAsGpio); PORT_HAL_SetPullMode(PORTB,2U,kPortPullUp); PORT_HAL_SetPullCmd(PORTB,2U,true); /* Init board clock */ BOARD_ClockInit(); dbg_uart_init(); }
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTA_IDX); CLOCK_SYS_EnablePortClock(PORTB_IDX); CLOCK_SYS_EnablePortClock(PORTC_IDX); CLOCK_SYS_EnablePortClock(PORTE_IDX); #ifdef BOARD_XTAL0_CLK_FREQUENCY #endif configure_sdcard_spi_pins(1U); GPIO_DRV_Init(sdcardCardDectionPin, NULL); /* Init board clock */ BOARD_ClockInit(); dbg_uart_init(); }
int main(void) #endif { hardware_init(); OSA_Init(); dbg_uart_init(); #if !(USE_RTOS) APP_init(); #endif OS_Task_create(Task_Start, NULL, 4L, 3000L, "task_start", NULL); OSA_Start(); #if !defined(FSL_RTOS_MQX) return 1; #endif }
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTA_IDX); CLOCK_SYS_EnablePortClock(PORTC_IDX); CLOCK_SYS_EnablePortClock(PORTD_IDX); CLOCK_SYS_EnablePortClock(PORTE_IDX); /* Init board clock */ BOARD_ClockInit(); dbg_uart_init(); //Configure flexio clock src and pin mux CLOCK_SYS_SetFlexioSrc(0,(clock_flexio_src_t)1); configure_flexio_pins(0,5); /*FLEXIO pin 5 simulated as UART TX*/ configure_flexio_pins(0,4); /*FLEXIO pin 4 simulated as UART RX*/ //Configure lpuart pin mux configure_lpuart_pins(1); }
void main(void) #endif #endif { hardware_init(); OSA_Init(); dbg_uart_init(); #if !(USE_RTOS) APP_init(); #endif OS_Task_create(Task_Start, NULL, 4L, 1000L, "task_start", NULL); OSA_Start(); #if (!defined(FSL_RTOS_MQX))&(defined(__CC_ARM) || defined(__GNUC__)) return 1; #endif }
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTE_IDX); CLOCK_SYS_EnablePortClock(PORTF_IDX); CLOCK_SYS_EnablePortClock(PORTI_IDX); CLOCK_SYS_EnablePortClock(PORTL_IDX); /* enable XBAR clock */ CLOCK_SYS_EnableXbarClock(0); /* Init board EXTAL 32.768KHz clock */ BOARD_InitRtcOsc(); /* configure MCG mode as FEE, FLL 24MHz 1:1:1 */ CLOCK_SYS_SetConfiguration(&clkFll24MCfg); /* init debug uart */ dbg_uart_init(); configure_xbar_pins(0U); }
void hardware_init(void) { /* Board specific RDC settings */ BOARD_RdcInit(); /* Board specific clock settings */ BOARD_ClockInit(); /* initialize debug uart */ dbg_uart_init(); configure_pwm_pins(PWM2); configure_pwm_pins(PWM3); RDC_SetPdapAccess(RDC, rdcPdapPwm2, 3 << (BOARD_DOMAIN_ID * 2), false, false); RDC_SetPdapAccess(RDC, rdcPdapPwm3, 3 << (BOARD_DOMAIN_ID * 2), false, false); /* Configure GPIOS */ configure_platform_gpio(); /* Enable Interrupts */ NVIC_EnableIRQ(BOARD_ENC_IRQ); /* In this example, we need to grasp board I2C exclusively */ RDC_SetPdapAccess(RDC, BOARD_I2C_RDC_PDAP, 3 << (BOARD_DOMAIN_ID * 2), false, false); /* Select I2C clock derived from OSC clock(24M) */ CCM_UpdateRoot(CCM, BOARD_I2C_CCM_ROOT, ccmRootmuxI2cOsc24m, 0, 0); /* Enable I2C clock */ CCM_EnableRoot(CCM, BOARD_I2C_CCM_ROOT); CCM_ControlGate(CCM, BOARD_I2C_CCM_CCGR, ccmClockNeededRunWait); /* I2C Pin setting */ configure_i2c_pins(BOARD_I2C_BASEADDR); /* RDC MU*/ RDC_SetPdapAccess(RDC, BOARD_MU_RDC_PDAP, 3 << (BOARD_DOMAIN_ID * 2), false, false); /* Enable clock gate for MU*/ CCM_ControlGate(CCM, BOARD_MU_CCM_CCGR, ccmClockNeededRun); }
/*! * @brief RTC in alarm mode. * * This function demostrates how to use RTC as an alarm clock. */ void main(void) { uint32_t sec; uint32_t currSeconds; rtc_datetime_t date; // Init hardware. hardware_init(); // Call this function to initialize the console UART. This function // enables the use of STDIO functions (printf, scanf, etc.) dbg_uart_init(); printf("RTC example: set up time to wake up an alarm\r\n"); // Init RTC RTC_DRV_Init(RTC_INSTANCE); // Set a start date time and start RT. date.year = 2014U; date.month = 12U; date.day = 25U; date.hour = 19U; date.minute = 0; date.second = 0; // Set RTC time to default RTC_DRV_SetDatetime(RTC_INSTANCE, &date); while (1) { // Get date time. RTC_DRV_GetDatetime(RTC_INSTANCE, &date); // print default time printf("Current datetime: %04hd-%02hd-%02hd %02hd:%02hd:%02hd\r\n", date.year, date.month, date.day, date.hour, date.minute, date.second); // Convert current date time to seconds RTC_HAL_ConvertDatetimeToSecs(&date, &currSeconds); // Get alarm time from user sec = 0; printf("Please input the number of second to wait for alarm \r\n"); printf("The second must be positive value\r\n"); while (sec < 1) { scanf("%d",&sec); } // Add curr_seconds sec += currSeconds; // Convert sec to date type RTC_HAL_ConvertSecsToDatetime(&sec, &date); // Set alarm time if(!RTC_DRV_SetAlarm(RTC_INSTANCE, &date, true)) { printf("Failed to set alarm. \r\n"); continue; } // Print alarm time printf("Alarm will be occured at: %04hd-%02hd-%02hd %02hd:%02hd:%02hd\r\n", date.year, date.month, date.day, date.hour, date.minute, date.second); // Wait until alarm occures while(busyWait) {} printf("\r\n Alarm occured !!!! "); } }
/*! * @brief Watchdog main routine * Run a simple application which enables watchdog, then * continuously refreshes the watchdog to prevent CPU reset * Upon SW1 button push, the watchdog will expire after * approximately 2 seconds and issue reset */ void main(void) { // Configure watchdog. const wdog_user_config_t wdogConfig = { .timeoutValue = 2048U,// Watchdog overflow time is about 2s .windowValue = 0, // Watchdog window value, 0-disable window function .clockPrescalerValue = kWdogClockPrescalerValueDevide1, // Watchdog clock prescaler .updateRegisterEnable = true, // Update register enabled .clockSource = kClockWdogSrcLpoClk, // Watchdog clock source is LPO 1KHz .workInWaitModeEnable = true, // Enable watchdog in wait mode .workInStopModeEnable = true, // Enable watchdog in stop mode .workInDebugModeEnable = false,// Disable watchdog in debug mode }; // Init hardware. hardware_init(); // Init OSA layer. OSA_Init(); // Call this function to initialize the console UART. This function // enables the use of STDIO functions (printf, scanf, etc.) dbg_uart_init(); // Init pinsfor switch and led. GPIO_DRV_Init(switchPins, ledPins); // Initialize wdog before the WDOG timer has a chance //to reset the device // Turn LED1 on; LED1_ON; WDOG_DRV_Init(&wdogConfig); // If not wdog reset, clear reset count if (!(RCM->SRS0 & RCM_SRS0_WDOG_MASK)) { WDOG_DRV_ClearResetCount(); printf("\r\n WDOG example \r\n"); } // Check if WDOG reset occurred , disable WDOG and turn off LED1. if (WDOG_DRV_GetResetCount()) { printf("\r\n WDOG reset count %ld",WDOG_DRV_GetResetCount()); } printf("\r\n Press SW1 to expire watchdog "); // Continue to run in loop to refresh watchdog until SW1 is pushed while (1) { // Check for SW1 button push.Pin is grounded when button is pushed. if (0 != is_key_pressed()) { while (1) { // Button has been pushed,blink LED // showing that the watchdog is about to expire. LED1_TOGGLE; OSA_TimeDelay(BLINK_TIME); } } // Restart the watchdog so it doesn't reset. WDOG_DRV_Refresh(); OSA_TimeDelay(100u); } }
int main (void) { /*************************************************************************** * RX buffers **************************************************************************/ /*! @param receiveBuff Buffer used to hold received data */ uint8_t receiveBuff[19] = {0}; /* Initialize standard SDK demo application pins */ hardware_init(); /* Configure the UART TX/RX pins */ configure_uart_pins(BOARD_DEBUG_UART_INSTANCE); #ifdef USE_STDIO_FUNCTIONS /* Call this function to initialize the console UART. This function enables the use of STDIO functions (printf, scanf, etc.) */ dbg_uart_init(); /* Print the initial banner */ printf("\r\nHello World!\n\n\r"); while(1) { /******************************************** * Main routine that simply echoes received * characters forever *********************************************/ /* First, get character. */ receiveBuff[0] = getchar(); /* Now echo the received character */ putchar(receiveBuff[0]); } #else /*************************************************************************** * UART configuration and state structures **************************************************************************/ /*! @param uartConfig UART configuration structure */ /*! @param uartState UARt state structure which is used internally by the*/ /*! by the UART driver to keep track of the UART states */ uart_user_config_t uartConfig; uart_state_t uartState; /*************************************************************************** * TX buffers **************************************************************************/ /*! @param sourceBuff Buffer used to hold the string to be transmitted */ uint8_t sourceBuff[19] = {"\r\nHello World!\n\n\r"}; /* Configure the UART for 115200, 8 data bits, No parity, and one stop bit*/ uartConfig.baudRate = 115200; uartConfig.bitCountPerChar = kUart8BitsPerChar; uartConfig.parityMode = kUartParityDisabled; uartConfig.stopBitCount = kUartOneStopBit; /* Must call the OSA Init function to use Communication drivers */ OSA_Init(); /* Initialize the UART module */ UART_DRV_Init(BOARD_DEBUG_UART_INSTANCE, &uartState, &uartConfig); /* Print the initial banner */ UART_DRV_SendDataBlocking(BOARD_DEBUG_UART_INSTANCE, sourceBuff, 17, 200); while(1) { /******************************************** * Main routine that simply echoes received * characters forever *********************************************/ /* First, get character. */ UART_DRV_ReceiveDataBlocking(BOARD_DEBUG_UART_INSTANCE, receiveBuff, 1, OSA_WAIT_FOREVER); /* Now, stuff the buffer for the TX side and send the character*/ sourceBuff[0] = receiveBuff[0]; /* Now echo the received character */ UART_DRV_SendDataBlocking(BOARD_DEBUG_UART_INSTANCE, sourceBuff, 1, 200); } #endif }
/*! * @brief DSPI master Polling. * * Thid function uses DSPI master to send an array to slave * and receive the array back from slave, * thencompare whether the two buffers are the same. */ int main(void) { uint32_t i; uint32_t loopCount = 1; SPI_Type * dspiBaseAddr = (SPI_Type*)SPI0_BASE; uint32_t dspiSourceClock; uint32_t calculatedBaudRate; dspi_device_t masterDevice; dspi_command_config_t commandConfig = { .isChipSelectContinuous = false, .whichCtar = kDspiCtar0, .whichPcs = kDspiPcs0, .clearTransferCount = true, .isEndOfQueue = false }; // Init hardware hardware_init(); // Init OSA layer, used in DSPI_DRV_MasterTransferBlocking. OSA_Init(); // Call this function to initialize the console UART. This function // enables the use of STDIO functions (printf, scanf, etc.) dbg_uart_init(); // Print a note. printf("\r\n DSPI board to board polling example"); printf("\r\n This example run on instance 0 "); printf("\r\n Be sure DSPI0-DSPI0 are connected "); // Configure SPI pins. configure_spi_pins(DSPI_MASTER_INSTANCE); // Enable DSPI clock. CLOCK_SYS_EnableSpiClock(DSPI_MASTER_INSTANCE); // Initialize the DSPI module registers to default value, which disables the module DSPI_HAL_Init(dspiBaseAddr); // Set to master mode. DSPI_HAL_SetMasterSlaveMode(dspiBaseAddr, kDspiMaster); // Configure for continuous SCK operation DSPI_HAL_SetContinuousSckCmd(dspiBaseAddr, false); // Configure for peripheral chip select polarity DSPI_HAL_SetPcsPolarityMode(dspiBaseAddr, kDspiPcs0, kDspiPcs_ActiveLow); // Disable FIFO operation. DSPI_HAL_SetFifoCmd(dspiBaseAddr, false, false); // Initialize the configurable delays: PCS-to-SCK, prescaler = 0, scaler = 1 DSPI_HAL_SetDelay(dspiBaseAddr, kDspiCtar0, 0, 1, kDspiPcsToSck); // DSPI system enable DSPI_HAL_Enable(dspiBaseAddr); // Configure baudrate. masterDevice.dataBusConfig.bitsPerFrame = 8; masterDevice.dataBusConfig.clkPhase = kDspiClockPhase_FirstEdge; masterDevice.dataBusConfig.clkPolarity = kDspiClockPolarity_ActiveHigh; masterDevice.dataBusConfig.direction = kDspiMsbFirst; DSPI_HAL_SetDataFormat(dspiBaseAddr, kDspiCtar0, &masterDevice.dataBusConfig); // Get DSPI source clock. dspiSourceClock = CLOCK_SYS_GetSpiFreq(DSPI_MASTER_INSTANCE); calculatedBaudRate = DSPI_HAL_SetBaudRate(dspiBaseAddr, kDspiCtar0, TRANSFER_BAUDRATE, dspiSourceClock); printf("\r\n Transfer at baudrate %lu \r\n", calculatedBaudRate); while(1) { // Initialize the transmit buffer. for (i = 0; i < TRANSFER_SIZE; i++) { sendBuffer[i] = i + loopCount; } // Print out transmit buffer. printf("\r\n Master transmit:"); for (i = 0; i < TRANSFER_SIZE; i++) { // Print 16 numbers in a line. if ((i & 0x0F) == 0) { printf("\r\n "); } printf(" %02X", sendBuffer[i]); } // Reset the receive buffer. for (i = 0; i < TRANSFER_SIZE; i++) { receiveBuffer[i] = 0; } // Restart the transfer by stop then start again, this will clear out the shift register DSPI_HAL_StopTransfer(dspiBaseAddr); // Flush the FIFOs DSPI_HAL_SetFlushFifoCmd(dspiBaseAddr, true, true); // Clear status flags that may have been set from previous transfers. DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxComplete); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiEndOfQueue); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoUnderflow); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoFillRequest); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoOverflow); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoDrainRequest); // Clear the transfer count. DSPI_HAL_PresetTransferCount(dspiBaseAddr, 0); // Start the transfer process in the hardware DSPI_HAL_StartTransfer(dspiBaseAddr); // Send the data to slave. for (i = 0; i < TRANSFER_SIZE; i++) { // Write data to PUSHR DSPI_HAL_WriteDataMastermodeBlocking(dspiBaseAddr, &commandConfig, sendBuffer[i]); // Delay to wait slave is ready. OSA_TimeDelay(1); } // Delay to wait slave is ready. OSA_TimeDelay(10); // Restart the transfer by stop then start again, this will clear out the shift register DSPI_HAL_StopTransfer(dspiBaseAddr); // Flush the FIFOs DSPI_HAL_SetFlushFifoCmd(dspiBaseAddr, true, true); //Clear status flags that may have been set from previous transfers. DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxComplete); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiEndOfQueue); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoUnderflow); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoFillRequest); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoOverflow); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoDrainRequest); // Clear the transfer count. DSPI_HAL_PresetTransferCount(dspiBaseAddr, 0); // Start the transfer process in the hardware DSPI_HAL_StartTransfer(dspiBaseAddr); // Receive the data from slave. for (i = 0; i < TRANSFER_SIZE; i++) { // Write command to PUSHR. DSPI_HAL_WriteDataMastermodeBlocking(dspiBaseAddr, &commandConfig, 0); // Check RFDR flag while (DSPI_HAL_GetStatusFlag(dspiBaseAddr, kDspiRxFifoDrainRequest)== false) {} // Read data from POPR receiveBuffer[i] = DSPI_HAL_ReadData(dspiBaseAddr); // Clear RFDR flag DSPI_HAL_ClearStatusFlag(dspiBaseAddr,kDspiRxFifoDrainRequest); // Delay to wait slave is ready. OSA_TimeDelay(1); } // Print out receive buffer. printf("\r\n Master receive:"); for (i = 0; i < TRANSFER_SIZE; i++) { // Print 16 numbers in a line. if ((i & 0x0F) == 0) { printf("\r\n "); } printf(" %02X", receiveBuffer[i]); } // Check receiveBuffer. for (i = 0; i < TRANSFER_SIZE; ++i) { if (receiveBuffer[i] != sendBuffer[i]) { // Master received incorrect. printf("\r\n ERROR: master received incorrect "); return -1; } } printf("\r\n DSPI Master Sends/ Recevies Successfully"); // Wait for press any key. printf("\r\n Press any key to run again"); getchar(); // Increase loop count to change transmit buffer. loopCount++; } }
int main (void) { uint8_t msg; uint32_t timeout = 0; uint32_t var; volatile uint16_t count; OSA_Init(); hardware_init(); dbg_uart_init(); configure_spi_pins(HW_SPI0); printf("dspi_edma_test_slave\r\n"); printf("\r\nDemo started...\r\n"); // Initialize configuration edma_init(); edma_dspi_rx_setup(kEDMAChannel2, (uint32_t)&g_slaveRxBuffer); dspi_slave_setup(HW_SPI0, SPI_BAUDRATE); printf("Press space bar to begin.\r\n"); msg = 'A'; while(msg != ' ') { msg = getchar(); } printf("\r\nDemo started...\r\n"); // Slave only have PCS0 PORT_HAL_SetMuxMode(PORTC_BASE, 0u, kPortMuxAlt7); // Enable eDMA channels requests to initiate DSPI transfers. EDMA_HAL_SetDmaRequestCmd(DMA_BASE, kEDMAChannel2, true); DSPI_HAL_StartTransfer(SPI0_BASE); // Waiting transfer complete printf("waiting transfer complete...\r\n"); while((bReceivedFlag == false) & (timeout < 50)) { OSA_TimeDelay(100); timeout++; } if(bReceivedFlag == false) { printf("No date received, please check connections\r\n"); } printf("received data:\r\n"); for(count = 0; count < TEST_DATA_LEN; count++) { var = g_slaveRxBuffer[count]; printf("%08X\t", (unsigned int)var); if((count + 1) % 4 == 0) { printf("\r\n"); } } printf("\r\nEnd of demo.\r\n"); }
/*! * @brief DSPI slave Polling. * * This function sends back received buffer from master through DSPI interface. */ int main(void) { uint32_t i; SPI_Type * dspiBaseAddr = (SPI_Type*)SPI0_BASE; dspi_slave_user_config_t slaveConfig; // Init hardware hardware_init(); // Init OSA layer, used in DSPI_DRV_MasterTransferBlocking. OSA_Init(); // Call this function to initialize the console UART. This function // enables the use of STDIO functions (printf, scanf, etc.) dbg_uart_init(); // Configure SPI pins. configure_spi_pins(DSPI_SLAVE_INSTANCE); // Print a note. printf("\r\n DSPI board to board polling example"); printf("\r\n This example run on instance 0 "); printf("\r\n Be sure DSPI0-DSPI0 are connected "); // Enable clock for DSPI CLOCK_SYS_EnableSpiClock(DSPI_SLAVE_INSTANCE); // Reset the DSPI module, which also disables the DSPI module DSPI_HAL_Init(dspiBaseAddr); // Set to slave mode. DSPI_HAL_SetMasterSlaveMode(dspiBaseAddr, kDspiSlave); // Set data format slaveConfig.dataConfig.clkPhase = kDspiClockPhase_FirstEdge; slaveConfig.dataConfig.clkPolarity = kDspiClockPolarity_ActiveHigh; slaveConfig.dataConfig.bitsPerFrame = 8; DSPI_HAL_SetDataFormat(dspiBaseAddr, kDspiCtar0, &(slaveConfig.dataConfig)); // DSPI system enable DSPI_HAL_Enable(dspiBaseAddr); // Disable FIFO operation. DSPI_HAL_SetFifoCmd(dspiBaseAddr, false, false); while(1) { printf("\r\n Slave example is running..."); // Reset the receive buffer. for (i = 0; i < TRANSFER_SIZE; i++) { receiveBuffer[i] = 0; } // Restart the transfer by stop then start again, this will clear out the shift register DSPI_HAL_StopTransfer(dspiBaseAddr); // Flush the FIFOs DSPI_HAL_SetFlushFifoCmd(dspiBaseAddr, true, true); // Clear status flags that may have been set from previous transfers DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxComplete); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiEndOfQueue); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoUnderflow); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoFillRequest); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoOverflow); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoDrainRequest); // Clear the transfer count DSPI_HAL_PresetTransferCount(dspiBaseAddr, 0); // Start the transfer process in the hardware DSPI_HAL_StartTransfer(dspiBaseAddr); for (i = 0; i < TRANSFER_SIZE; i++) { // Check RFDR flag while (DSPI_HAL_GetStatusFlag(dspiBaseAddr, kDspiRxFifoDrainRequest)== false) {} // Read data from POPR receiveBuffer[i] = DSPI_HAL_ReadData(dspiBaseAddr); // Clear RFDR flag DSPI_HAL_ClearStatusFlag(dspiBaseAddr,kDspiRxFifoDrainRequest); } // Restart the transfer by stop then start again, this will clear out the shift register DSPI_HAL_StopTransfer(dspiBaseAddr); // Flush the FIFOs DSPI_HAL_SetFlushFifoCmd(dspiBaseAddr, true, true); // Clear status flags that may have been set from previous transfers DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxComplete); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiEndOfQueue); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoUnderflow); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiTxFifoFillRequest); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoOverflow); DSPI_HAL_ClearStatusFlag(dspiBaseAddr, kDspiRxFifoDrainRequest); // Clear the transfer count DSPI_HAL_PresetTransferCount(dspiBaseAddr, 0); // Start the transfer process in the hardware DSPI_HAL_StartTransfer(dspiBaseAddr); // Send the data to slave. for (i = 0; i < TRANSFER_SIZE; i++) { // Write data to PUSHR DSPI_HAL_WriteDataSlavemodeBlocking(dspiBaseAddr, receiveBuffer[i]); } // Print out receive buffer. printf("\r\n Slave receive:"); for (i = 0; i < TRANSFER_SIZE; i++) { // Print 16 numbers in a line. if ((i & 0x0F) == 0) { printf("\r\n "); } printf(" %02X", receiveBuffer[i]); } } }