/** * \brief Application entry point for ssc_dam_audio example. * * \return Unused (ANSI-C compatibility). */ int main( void ) { uint16_t data = 0; /* Disable watchdog */ WDT_Disable( WDT ) ; /* Enable I and D cache */ SCB_EnableICache(); SCB_EnableDCache(); /* Output example information */ printf("-- SSC DMA Audio Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); /* Configure systick for 1 ms. */ printf( "Configure system tick to get 1ms tick period.\n\r" ) ; if ( TimeTick_Configure( ) ) { printf("-F- Systick configuration error\n\r" ) ; } /* Configure all pins */ PIO_Configure(pinsSsc, PIO_LISTSIZE(pinsSsc)); /* Configure SSC */ SSC_Configure(AUDIO_IF , 0 , SSC_MCK ); SSC_ConfigureReceiver(AUDIO_IF,I2S_SLAVE_RX_SETTING,I2S_SLAVE_RX_FRM_SETTING); SSC_DisableReceiver(AUDIO_IF); SSC_ConfigureTransmitter(AUDIO_IF,I2S_SLAVE_TX_SETTING,I2S_SLAVE_TX_FRM_SETTING); SSC_DisableTransmitter(AUDIO_IF); /* Configure DMA */ Dma_configure(); /* Configure and enable the TWI (required for accessing the DAC) */ PMC_EnablePeripheral(ID_TWIHS0); TWI_ConfigureMaster(TWIHS0, TWI_CLOCK, BOARD_MCK); TWID_Initialize(&twid, TWIHS0); /* Configure TWI interrupts */ NVIC_ClearPendingIRQ(TWIHS0_IRQn); NVIC_EnableIRQ(TWIHS0_IRQn); /* check that WM8904 is present */ WM8904_Write(&twid, WM8904_SLAVE_ADDRESS, 22, 0); data=WM8904_Read(&twid, WM8904_SLAVE_ADDRESS, 0); if( data != 0x8904){ printf("WM8904 not found!\n\r"); while(1); } /* Initialize the audio DAC */ WM8904_Init(&twid, WM8904_SLAVE_ADDRESS, PMC_MCKR_CSS_SLOW_CLK); /* Enable the DAC master clock */ PMC_ConfigurePCK2(PMC_MCKR_CSS_SLOW_CLK, PMC_MCKR_PRES_CLK_1 ); printf("Insert Line-in cable with PC Headphone output\n\r"); PlayRecording(); while ( 1 ); }
/** * \brief getting-started Application entry point. * * \return Unused (ANSI-C compatibility). */ extern int main(void) { uint32_t id_offset = 0; uint32_t fifo_entries; uint32_t button_state = BUTTON_PUSHED; uint32_t button_state2 = BUTTON_NOT_PUSHED; uint32_t can_mode = CAN_STANDARD; /* Disable watchdog */ WDT_Disable(WDT); /* Output example information */ printf("\n\r-- Controller Area Network (CAN) Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r\n\r", __DATE__, __TIME__); printf("-- LED0 toggles on CAN message reception\n\r"); printf("-- LED1 toggles on CAN message transmission\n\r"); printf("-- CAN message transmission stopped while SW0 is pushed\n\r"); printf("-- SW1 pushes alternate between standard CAN and CAN-FD\n\r"); SCB_EnableICache(); SCB_EnableDCache(); /* Configure systick for 1 ms. */ TimeTick_Configure(); /* Configure Board LED's */ LED_Configure(0); #if 2 == LED_NUM LED_Configure(1); #endif /* Configure Timer/Counter for 250msec Tick */ _ConfigureTc(); /* Configure Board Push-buttons */ // SW1 is a ERASE system function, switch it to port function MATRIX->CCFG_SYSIO |= (1u << 12); /* have to disable the pull down on PB12 for SW1 before the pull up can be enabled */ PIOB->PIO_PPDDR = 1 << 12; PIO_Configure(pushbutton, PIO_LISTSIZE(pushbutton)); /* Adjust pio denounce filter parameters, uses 10 Hz filter. */ PIO_SetDebounceFilter(&pushbutton[0], 10); #if 2 == BUTTON_NUM PIO_SetDebounceFilter(&pushbutton[1], 10000); #endif SystemCoreClockUpdate(); MCAN_Init(&mcan1Config); MCAN_InitFdBitRateSwitchEnable(&mcan1Config); MCAN_InitTxQueue(&mcan1Config); MCAN_InitLoopback(&mcan1Config); // remove to disable loop back mode MCAN_Enable(&mcan1Config); MCAN_IEnableMessageStoredToRxDedBuffer(&mcan1Config, CAN_INTR_LINE_1); txMailbox0 = (uint32_t *)MCAN_ConfigTxDedBuffer(&mcan1Config, TX_BUFFER_0, MSG_ID_0, CAN_STD_ID, CAN_DLC_1); txMailbox1 = (uint32_t *)MCAN_ConfigTxDedBuffer(&mcan1Config, TX_BUFFER_1, MSG_ID_1, CAN_EXT_ID, CAN_DLC_8); MCAN_ConfigRxBufferFilter(&mcan1Config, RX_BUFFER_0, FILTER_0, MSG_ID_0, CAN_STD_ID); MCAN_ConfigRxBufferFilter(&mcan1Config, RX_BUFFER_1, FILTER_0, MSG_ID_1, CAN_EXT_ID); MCAN_ConfigRxClassicFilter(&mcan1Config, CAN_FIFO_0, FILTER_1, MSG_ID_2, CAN_STD_ID, MSG_ID_2_MASK); while (1) { if (tick) { tick = 0; if (PIO_Get(&pushbutton[0]) == BUTTON_NOT_PUSHED) { if (button_state2 == BUTTON_NOT_PUSHED) { /* periodically transmit messages while SW0 is not pushed */ // send standard ID from a dedicated buffer *txMailbox0 = MSG_ID_0_DATA1; // write data into CAN mailbox MCAN_SendTxDedBuffer(&mcan1Config, TX_BUFFER_0); // send data txdCntr++; // send extended ID from a dedicated buffer *txMailbox1 = MSG_ID_1_DATA1_4; // write data into CAN mailbox *(txMailbox1 + 1) = MSG_ID_1_DATA5_8; // write data into CAN mailbox MCAN_SendTxDedBuffer(&mcan1Config, TX_BUFFER_1); // send the data txdCntr++; // send from Tx Queue MCAN_AddToTxFifoQ(&mcan1Config, MSG_ID_2 + id_offset, CAN_STD_ID, CAN_DLC_1, &txData[0]); txdCntr++; // increment the offset so we send different ID's within the // range defined by the mask id_offset = (id_offset + 1) & (uint32_t) ~MSG_ID_2_MASK; // update data being sent for next time txData[0]++; button_state2 = BUTTON_NOT_PUSHED; } } else { if (button_state2 == BUTTON_NOT_PUSHED) button_state2 = BUTTON_PUSHED; else button_state2 = BUTTON_NOT_PUSHED; } } /* poll for TX'd message complete */ if (MCAN_IsTxComplete(&mcan1Config)) { MCAN_ClearTxComplete(&mcan1Config); if (MCAN_IsBufferTxd(&mcan1Config, TX_BUFFER_0)) { #if 2 == LED_NUM LED_Toggle(1); #endif } } /* Poll for new CAN messages in RX FIFO */ do { fifo_entries = MCAN_GetRxFifoBuffer(&mcan1Config, CAN_FIFO_0, (Mailbox64Type *) &rxMailbox2); if (fifo_entries > 0) rxdCntr++; } while (fifo_entries > 1); /* SW1 used to alternate between standard CAN and CAN-FD operation */ #if 2 == BUTTON_NUM if (PIO_Get(&pushbutton[1]) == BUTTON_NOT_PUSHED) { #else if (1) { #endif button_state = BUTTON_NOT_PUSHED; } else { if (button_state == BUTTON_NOT_PUSHED ) { // Switch on a NOT PUSHED to PUSHED edge button_state = BUTTON_PUSHED; if (can_mode == CAN_STANDARD) { can_mode = CAN_FD; MCAN_RequestFdBitRateSwitch( &mcan1Config ); } else { can_mode = CAN_STANDARD; MCAN_RequestIso11898_1( &mcan1Config ); } } } #ifdef POLLKEYBOARD /* poll for keyboard entry */ if (DBG_IsRxReady()) { keyboard = DBG_GetChar(); if (((char) keyboard == 'L' ) || ( (char) keyboard == 'l')) { if (loopback == 1) { MCAN_LoopbackOff(&mcan1Config); loopback = 0; } else { MCAN_LoopbackOn(&mcan1Config); loopback = 1; } } } #endif } }
/** * \brief usart-hw-handshaking Application entry point.. * * Configures USART in hardware handshaking mode and * Timer Counter 0 to generate an interrupt every second. Then, start the first * transfer on the USART and wait in an endless loop. * * \return Unused (ANSI-C compatibility). */ int main( void ) { char pbaud_time[8]; uint32_t BytesRead, BytesToRead, baudrate, timeout, TxBytesLeft; uint8_t AppBufferRollOver = 0; uint8_t *pTxBuff; /* Disable watchdog*/ WDT_Disable(WDT); printf("-- USART Hardware Handshaking Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME); /* Enable I and D cache */ SCB_EnableICache(); SCB_EnableDCache(); /* Configure USART pins*/ PIO_Configure(pins, PIO_LISTSIZE(pins)); /* Configure systick for 1 ms. */ TimeTick_Configure(); NVIC_SetPriority(XDMAC_IRQn , XDMA_NVIC_PRIO); printf("\n\rEnter required baudrate:"); gets(pbaud_time); baudrate = (atoi(pbaud_time)) ? (atoi(pbaud_time)): 921600; printf("\n\rEnter required timeout (in microsec):"); gets(pbaud_time); timeout = atoi(pbaud_time); if (timeout > 1000) { timeout /= 1000; timeout = ((timeout * baudrate) / 1000); } else { timeout = (timeout * baudrate) / 1000000; } timeout = (timeout) ? ((timeout > MAX_RX_TIMEOUT) ? MAX_RX_TIMEOUT : timeout) \ : MAX_RX_TIMEOUT; printf("\n\r"); /* Configure USART */ _ConfigureUsart(baudrate, timeout); printf("\n\r"); /*Enable Rx channel of USART */ USARTD_EnableRxChannels(&Usartd, &UsartRx); #ifdef FULL_DUPLEX /*Enable Tx channel of USART */ USARTD_EnableTxChannels(&Usartd, &UsartTx); #endif /* Start receiving data and start timer*/ USARTD_RcvData(&Usartd); /*Initialize Ring buffer */ pUsartBuffer = (RignBuffer_t *)malloc(sizeof(RignBuffer_t)); _initCircularBuffer(pUsartBuffer); pTxBuff = &FirstAppBuff[0]; TxBytesLeft = 0; #ifdef USE_MD5_CHECK md5_init(&pms); #endif //USE_MD5_CHECK #ifdef FULL_DUPLEX printf( "\n\r-I- USART is in Full Duplex mode \n\r"); #else printf( "\n\r-I- USART is in Half Duplex mode \n\r"); #endif printf( "\n\r-I- Please send a file to serial port (USART0) \n\r"); BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer while (1) { #ifdef USE_MD5_CHECK if (DBG_IsRxReady()) { ch = DBG_GetChar(); if (ch == 'm') { uint8_t i; md5_finish(&pms, md5); printf("\r\nmd5:"); for (i = 0; i < sizeof(md5);i++) printf("%.2x",md5[i]); printf("\r\n"); md5_init(&pms); TotalbytesReceived = 0; } } #endif /* Check Application buffer (100 KB)overflow */ if (((PingPongBufferFlag == 0) && (pTxBuff+BytesToRead) >= &FirstAppBuff[APP_BUFFER]) || (( PingPongBufferFlag == 1) && (pTxBuff+BytesToRead) >= &SecondAppBuff[APP_BUFFER])) { AppBufferRollOver = 1; // Roll over and start copying to the beginning of Application buffer to avoid errors if (PingPongBufferFlag) BytesToRead = (&SecondAppBuff[APP_BUFFER] - pTxBuff); else BytesToRead = (&FirstAppBuff[APP_BUFFER] - pTxBuff); memory_barrier(); } /* Read ring buffer */ BytesRead = RingBufferRead(pUsartBuffer, pTxBuff, BytesToRead); memory_sync(); TxBytesLeft += BytesRead; // number of bytes to send via USART Tx #ifdef USE_MD5_CHECK if (BytesRead > 0) md5_append(&pms,pTxBuff,BytesRead); #endif /* check if one of the application buffer is full and ready to send */ if (AppBufferRollOver && (TxBytesLeft == APP_BUFFER)) { AppBufferRollOver = 0; TxBytesLeft = 0; BytesRead = 0; BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer while (!UsartTx.dmaProgress); if (PingPongBufferFlag) { PingPongBufferFlag = 0; pTxBuff = &FirstAppBuff[0]; } else { PingPongBufferFlag = 1; pTxBuff = &SecondAppBuff[0]; } memory_sync(); #ifdef FULL_DUPLEX USARTD_SendData(&Usartd); #endif } /* otherwise keep storing in same application buffer from Rx DMA's ring buffer */ else { BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer pTxBuff += BytesRead; #ifdef FULL_DUPLEX /* Check for Tx timeout, if there is timeout then send the bytes left (less than 100 KB) in application buffer */ if ((GetDelayInTicks(TimeOutTimer, GetTicks()) == USART_TX_TIMEOUT) && TxBytesLeft) { // wait for any eventual USART Tx in progress while (!UsartTx.dmaProgress); FlushTxBuffer(TxBytesLeft); TimeOutTimer = GetTicks(); PingPongBufferFlag = 0; TxBytesLeft = 0; BytesRead = 0; BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer pTxBuff = &FirstAppBuff[0]; _UpdateTxConfig((uint32_t)&FirstAppBuff[0], APP_BUFFER); TRACE_INFO_WP(" TX Tiemout \n\r"); } #endif } } }
/** * \brief gmac_uip_telnetd example entry point. * * \return Unused (ANSI-C compatibility). */ int main(void) { uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; uint32_t i; struct uip_eth_addr OrigiGMacAddr; /* Disable watchdog */ WDT_Disable(WDT); SCB_EnableICache(); SCB_EnableDCache(); TimeTick_Configure(); printf("-- GMAC uIP Telnetd Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME); /* Configure systick for 1 ms. */ TimeTick_Configure(); /* Configure TWI pins. */ PIO_Configure(twiPins, PIO_LISTSIZE(twiPins)); /* Enable TWI */ PMC_EnablePeripheral(BOARD_ID_TWI_EEPROM); TWI_ConfigureMaster(BOARD_BASE_TWI_EEPROM, TWCK, BOARD_MCK); TWID_Initialize(&twid, BOARD_BASE_TWI_EEPROM); /* Display MAC & IP settings */ TWID_Read(&twid, AT24MAC_SERIAL_NUM_ADD, 0x9A, 1, OrigiGMacAddr.addr, PAGE_SIZE, 0); if ((OrigiGMacAddr.addr[0] == 0xFC) && (OrigiGMacAddr.addr[1] == 0xC2) && (OrigiGMacAddr.addr[2] == 0x3D)) { for (i = 0; i < 6; i++) GMacAddress.addr[i] = OrigiGMacAddr.addr[i]; } printf("-- MAC %x:%x:%x:%x:%x:%x\n\r", GMacAddress.addr[0], GMacAddress.addr[1], GMacAddress.addr[2], GMacAddress.addr[3], GMacAddress.addr[4], GMacAddress.addr[5]); #ifndef __DHCPC_H__ printf(" - Host IP %d.%d.%d.%d\n\r", HostIpAddress[0], HostIpAddress[1], HostIpAddress[2], HostIpAddress[3]); printf(" - Router IP %d.%d.%d.%d\n\r", RoutIpAddress[0], RoutIpAddress[1], RoutIpAddress[2], RoutIpAddress[3]); printf(" - Net Mask %d.%d.%d.%d\n\r", NetMask[0], NetMask[1], NetMask[2], NetMask[3]); #endif /* System devices initialize */ gmac_tapdev_setmac((uint8_t *)GMacAddress.addr); gmac_tapdev_init(); clock_init(); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); /* Init uIP */ uip_init(); #ifdef __DHCPC_H__ printf("P: DHCP Supported\n\r"); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_setnetmask(ipaddr); #else /* Set the IP address of this host */ uip_ipaddr(ipaddr, HostIpAddress[0], HostIpAddress[1], HostIpAddress[2], HostIpAddress[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, RoutIpAddress[0], RoutIpAddress[1], RoutIpAddress[2], RoutIpAddress[3]); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, NetMask[0], NetMask[1], NetMask[2], NetMask[3]); uip_setnetmask(ipaddr); #endif uip_setethaddr(GMacAddress); _app_init(); while (1) { uip_len = gmac_tapdev_read(); if (uip_len > 0) { if (BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out(); gmac_tapdev_send(); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) gmac_tapdev_send(); } } else if (timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for (i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out(); gmac_tapdev_send(); } } #if UIP_UDP for (i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out(); gmac_tapdev_send(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if (timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } }
extern int main( void ) { volatile uint32_t delay; uint8_t i; uint8_t SNo[16]; Async async; /* Disable watchdog */ WDT_Disable( WDT ) ; /* Enable I and D cache */ SCB_EnableICache(); SCB_EnableDCache(); CallBackFired = 0; /* Output example information */ printf("-- TWI EEPROM Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); TimeTick_Configure(); /* Configure TWI pins. */ PIO_Configure(pins, PIO_LISTSIZE(pins)); PMC_EnablePeripheral(BOARD_ID_TWI_EEPROM); /* Configure TWI */ twi_dma.pTwid = malloc(sizeof(Twid)); twi_dma.pTwiDma = malloc(sizeof(sXdmad)); TWI_ConfigureMaster(BOARD_BASE_TWI_EEPROM, TWCK, BOARD_MCK); TWID_Initialize(&twid, BOARD_BASE_TWI_EEPROM); TWID_DmaInitialize(&twi_dma, BOARD_BASE_TWI_EEPROM, 0); TWID_Read(&twid, AT24MAC_SERIAL_NUM_ADD, 0x80, 1, SNo, PAGE_SIZE, 0); /* Erase all page */ memset(pData, 0, PAGE_SIZE); for(i=0; i< EEPROM_PAGES; i++) { printf("-I- Filling page #%d with zeroes ...\r\n", i); TWID_Write(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0); /* Wait at least 10 ms */ Wait(10); } printf("\r\n"); _fillBuffer(pData); /* Synchronous operation */ for(i=0; i< EEPROM_PAGES; i++) { printf("\n\r-I- Filling page #%d with checkerboard pattern ...\r", i); TWID_DmaWrite(&twi_dma, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0); /* Wait at least 10 ms */ Wait(10); } printf("\r\n"); /* Read back data */ memset(pData, 0, PAGE_SIZE); for(i=0; i< EEPROM_PAGES; i++) { printf("-I- Reading page #%d... ", i); TWID_DmaRead(&twi_dma, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0); /* Wait at least 10 ms */ Wait(10); _checkReadBuffer(pData); } printf("\r\n"); /* Configure TWI interrupts */ NVIC_ClearPendingIRQ(TWIHS0_IRQn); NVIC_EnableIRQ(TWIHS0_IRQn); /* Asynchronous operation */ printf("-I- Read/write on page #0 (IRQ mode)\n\r"); /* Write checkerboard pattern in first page */ _fillBuffer(pData); memset(&async, 0, sizeof(async)); async.callback = (void *) TestCallback; for(i=0; i< EEPROM_PAGES; i++) { printf("-I- Filling page #%d with checkerboard pattern ...\r", i); TWID_Write(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, &async); while (!ASYNC_IsFinished(&async)); /* Wait at least 10 ms */ Wait(10); } printf("\r\n"); /* Read back data */ memset(pData, 0, PAGE_SIZE); memset(&async, 0, sizeof(async)); async.callback = (void *) TestCallback; for(i=0; i< EEPROM_PAGES; i++) { printf("-I- Reading page # %d...\r", i); TWID_Read(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, &async); while ( !ASYNC_IsFinished( &async ) ) ; /* Wait at least 10 ms */ Wait(10); _checkReadBuffer(pData); } printf("\r\n Callback Fired %d times", CallBackFired); return 0 ; }
int main(void) { uint8_t MemVerify = 0; uint32_t __Start_SP, idx; uint32_t (*__Start_New)(void); uint8_t *pMemory = (uint8_t *)( QSPIMEM_ADDR ); /* Disable watchdog */ WDT_Disable(WDT); SCB_EnableICache(); SCB_EnableDCache(); /* Output example information */ printf("-- QSPI XIP Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME); /* Configure systick */ TimeTick_Configure(); /* Initialize the QSPI and serial flash */ PIO_Configure(pins, PIO_LISTSIZE(pins)); /* Enable the clock of QSPI */ ENABLE_PERIPHERAL(ID_QSPI); S25FL1D_InitFlashInterface(1); printf("QSPI drivers initialized\n\r"); /* enable quad mode */ S25FL1D_QuadMode(ENABLE); /* get the code at the beginning of QSPI, run the code directly if it's valid */ S25FL1D_ReadQuadIO(Buffer, sizeof(Buffer), 0, 1, 0); printf("-I- data at the beginning of QSPI: %08x %08x %08x %08x\n\r", (unsigned int)Buffer[0], (unsigned int)Buffer[1], (unsigned int)Buffer[2], (unsigned int)Buffer[3]); if ((IRAM_ADDR <= Buffer[0]) && (IRAM_ADDR + IRAM_SIZE > Buffer[0]) && (QSPIMEM_ADDR < Buffer[1]) && (1 == (Buffer[1]&0x3))) { __Start_New = (uint32_t(*)(void)) Buffer[1]; __Start_SP = Buffer[0]; printf("-I- a valid application is already in QSPI, run it from QSPI\n\r"); printf("========================================================= \n\r"); __set_MSP(__Start_SP); __Start_New(); } else { printf("-I- there isn't a valid application in QSPI, program first\n\r"); } if (S25FL1D_Unprotect()) { printf("Unprotect QSPI Flash failed!\n\r"); while (1); } /* erase entire chip */ S25FL1D_EraseChip(); /* Flash the code to QSPI flash */ printf("Writing to Memory\n\r"); S25FL1D_Write((uint32_t *)pBuffercode, sizeof(pBuffercode), 0, 0); printf("Example code written 0x%x to Memory\n\r", sizeof(pBuffercode)); printf("Verifying \n\r"); /* Update QSPI Region to Full Access and cacheable*/ MPU_UpdateRegions(MPU_QSPIMEM_REGION, QSPI_START_ADDRESS, \ MPU_AP_FULL_ACCESS | INNER_NORMAL_WB_NWA_TYPE( NON_SHAREABLE ) | MPU_CalMPURegionSize(QSPI_END_ADDRESS - QSPI_START_ADDRESS) | MPU_REGION_ENABLE); /* Start continuous read mode to enter in XIP mode*/ S25FL1D_ReadQuadIO(Buffer, sizeof(Buffer), 0, 1, 0); for (idx = 0; idx < sizeof(pBuffercode); idx++) { if (*pMemory == pBuffercode[idx]) { pMemory++; } else { MemVerify = 1; printf("Data does not match at 0x%x \n\r", (unsigned)pMemory); break; } } if (!MemVerify) { printf("Everything is OK \n\r"); /* set PC and SP */ __Start_New = (uint32_t(*) (void) ) Buffer[1]; __Start_SP = Buffer[0]; printf("\n\r Starting getting started example from QSPI flash \n\r"); printf("========================================================= \n\r"); __set_MSP(__Start_SP); __Start_New(); } while (1); }
/** * \brief usart_spi Application entry point. * * \return Unused (ANSI-C compatibility). */ extern int main(void) { uint8_t ucKey, i; /* Disable watchdog */ WDT_Disable(WDT); SCB_EnableICache(); SCB_EnableDCache(); /* Configure systick for 1 ms. */ TimeTick_Configure(); /* Output example information */ printf("-- USART SPI Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME); /* Display menu */ _DisplayMainmenu(); while (1) { ucKey = DBG_GetChar(); switch (ucKey) { /*usart as spi master*/ case 'm': case 'M': /* Configure pins*/ PIO_Configure(pins1, PIO_LISTSIZE(pins1)); /* Configure USART as SPI master */ _ConfigureUsartAsSpiMaster(); /* Configure SPi slave */ _ConfigureSpiSlave(); printf("-I- Configure USART as spi master ...\n\r"); SPI_EnableIt(SPI, SPI_IER_RDRF); SPI_Enable(SPI); USART_EnableIt(USART, UART_IER_RXRDY); for (i = 0; (pTxBuffer1[i]!='\0' && pTxBuffer2[i]!='\0'); i++) { while ((SPI->SPI_SR & SPI_SR_TXEMPTY) == 0); SPI->SPI_TDR = ((uint16_t)pTxBuffer2[i]) | SPI_PCS( 0 ); USART_Write( USART, pTxBuffer1[i], 0); } break; /*usart as spi slave*/ case 's': case 'S': printf("-I- Configure USART as spi slave...\n\r"); /* Configure pins*/ PIO_Configure(pins2, PIO_LISTSIZE(pins2)); /* Configure USART as SPI slave */ _ConfigureUsartAsSpiSlave(); /* Configure SPI master */ _ConfigureSpiMaster(); USART_EnableIt(USART, UART_IER_RXRDY); SPI_EnableIt(SPI, SPI_IER_RDRF); SPI_Enable(SPI); for (i = 0; (pTxBuffer1[i]!='\0' && pTxBuffer2[i]!='\0'); i++) { USART_Write(USART, (uint16_t)pTxBuffer2[i], 0); SPI_Write( SPI, 1, (uint16_t)pTxBuffer1[i]); } break; case 'h': case 'H': _DisplayMainmenu(); break; } } }
/** * \brief usb_iad_hid_aud Application entry point. * * Starts the driver and waits for an audio input stream to forward to the DAC. */ int main(void) { volatile uint8_t usbConn = 0; volatile uint8_t audioOn = 0; int32_t numDiff = 0, prevDiff = 0; int8_t clockAdjust = 0; /* Disable watchdog */ WDT_Disable(WDT); SCB_EnableICache(); SCB_EnableDCache(); printf("-- USB HID + Audio Device Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME); TimeTick_Configure(); /* Interrupt priority */ NVIC_SetPriority(USBHS_IRQn, 2); /* If they are present, configure Vbus & Wake-up pins */ PIO_InitializeInterrupts(0); /* Initialize all USB power (off) */ _ConfigureUsbhs(); /* ----- HID Function Initialize */ #ifdef NO_PUSHBUTTON printf("-- : DBG key 1 2 used as buttons\n\r"); printf("-- : 1st press to push, 2nd press to release\n\r"); #else /* Initialize key statuses and configure push buttons */ PIO_Configure(pinsPushButtons, PIO_LISTSIZE(pinsPushButtons)); #endif memset(keyStatus, 1, NUM_KEYS); //LED_Configure(LED_NUMLOCK); /* Audio STREAM LED */ LED_Configure(USBD_LEDOTHER); /* Configure Audio */ _ConfigureAudioPlay(AUDDevice_SAMPLERATE, BOARD_MCK); /* Configure DMA */ _ConfigureDma(); /* USB audio driver initialization */ HIDAUDDDriver_Initialize(&hidauddDriverDescriptors); /* connect if needed */ USBD_Connect(); /* Infinite loop */ while (1) { if (USBD_GetState() < USBD_STATE_CONFIGURED) { usbConn = 0; continue; } if (audioOn) { if (isDacActive == 0) { AudioPlayEnable(0); printf("audE "); isFirstFrame = 1; audioOn = 0; } else { numDiff = numBuffersToSend - DAC_DELAY; if (prevDiff != numDiff) { prevDiff = numDiff; if (numDiff > 1 && clockAdjust != 1) { printf("+"); /* USB too fast or SSC too slow: faster clock */ clockAdjust = 1; _SyncAdjust(1); } if (numDiff < -1 && clockAdjust != -1) { printf("-"); /* USB too slow or SSC too fast: slower clock */ clockAdjust = -1; _SyncAdjust(-1); } if (numDiff == 0 && clockAdjust != 0) { clockAdjust = 0; _SyncAdjust(0); } } } } else if (isDacActive) { printf("audS "); audioOn = 1; } if (usbConn == 0) { usbConn = 1; /* Start Reading the incoming audio stream */ AUDDFunction_Read(buffers[inBufferIndex], AUDDevice_BYTESPERFRAME, (TransferCallback) FrameReceived, 0); // No optional argument } HIDDKeyboardProcessKeys(); } }
int main(void) { uint32_t i; uint32_t deviceId; uint8_t ucKey; uint8_t TestPassed = 0; /* Disable watchdog */ WDT_Disable(WDT); /* Output example information */ printf("-- QSPI Serialflash Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME); SCB_EnableICache(); SCB_EnableDCache(); TimeTick_Configure(); PIO_Configure(Qspi_pins, PIO_LISTSIZE(Qspi_pins)); ENABLE_PERIPHERAL(ID_QSPI); QSPI_UserMenu(); while (1) { ucKey = DBG_GetChar(); switch (ucKey) { case '1' : S25FL1D_InitFlashInterface(1); TRACE_INFO("QSPI drivers initialized "); /* enable quad mode */ S25FL1D_QuadMode(ENABLE); PeripheralInit = 1; break; case '2' : S25FL1D_InitFlashInterface(0); TRACE_INFO("QSPI Initialized in SPI mode"); S25FL1D_QuadMode(DISABLE); PeripheralInit = 2; break; case '3' : QSPI_UserMenu(); PeripheralInit = 0; break; default: break; } if (PeripheralInit) { while (1) { deviceId = S25FL1D_ReadJedecId(); printf("ID read: Manufacture ID = 0x%x, Device Type = 0x%x, \ Capacity = 0x%x\n\r", (uint8_t)(deviceId), (uint8_t)(deviceId >> 8), (uint8_t)(deviceId >> 16)); break; } /* erase entire chip */ S25FL1D_EraseChip(); /* fill up the buffer*/ _fillupbuffer(TestBuffer, BUFFER_SIZE); printf("Writing buffer to Flash memory...... \n\r"); /* write the buffer to flash memory */ for (i = 0; i < 0x200000; ) { S25FL1D_Write(TestBuffer, BUFFER_SIZE, i, 0); i += BUFFER_SIZE; } TestPassed = _VerifyData(0, 0x200000, TestBuffer, 0); printf("Erasing a block(64 KB) @ Add 0x10000 \n\r"); S25FL1D_Erase64KBlock(0x10000); memset(TestBuffer, 0xFFFFFF, BUFFER_SIZE); SCB_CleanDCache_by_Addr((uint32_t *)TestBuffer, sizeof(TestBuffer)); TestPassed = _VerifyData(0x10000, (0x10000 + 64 * 1024), TestBuffer, 0); if (TestPassed) printf(" \n\r**** Test Failed ***** \n\r"); else printf(" \n\r### Test Passed ###\n\r"); } PeripheralInit = 0; QSPI_UserMenu(); } }
/** * \brief hsmci_multimedia_card Application entry point. * * \return Unused (ANSI-C compatibility). */ int main(void) { uint8_t connected = 0; /* Disable watchdog */ WDT_Disable( WDT ) ; SCB_EnableICache(); SCB_EnableDCache(); TimeTick_Configure(); /* Output example information*/ printf("-- MultiMedia Card Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); bMciID = 0; /* Initialize PIO pins */ _ConfigurePIOs(); /* Initialize drivers */ _ConfigureDrivers(); /* Card insert detection loop */ for(;;) { if (CardIsConnected(bMciID)) { if (connected == 0) { connected = 1; /* Delay before card initialize */ Wait(300); /* Do card test */ CardInit(bMciID); DumpMenu(); } } else if (connected) { connected = 0; printf("** Card Disconnected\n\r"); } if (DBG_IsRxReady()) { uint8_t key = DBG_GetChar(); switch(key) { /* Change performance test block size */ case 'c': case 'C': { if (performanceMultiBlock >= NB_MULTI_BLOCKS) performanceMultiBlock = 1; else performanceMultiBlock <<= 1; printf("-!- Performance Multi set to %d\n\r", (int)performanceMultiBlock); } break; /* Show help information */ default: if (!connected) { DumpMenu(); } else { switch(key){ /* Dump block contents */ case 'd': case 'D': BlockDump(bMciID); break; /* Initialize the card again */ case 'I': case 'i': CardInit(bMciID); break; /* Run test on whole disk */ case 't': case 'T': if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDIO) SdioTest(bMciID); if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDMMC) DiskTest(bMciID, 1, 1, 1); printf("\n\r"); break; /* Run performance test */ case 'P': case 'p': if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDIO) SdioPerformanceTest(bMciID); if (SD_GetCardType(&sdDrv[bMciID]) & CARD_TYPE_bmSDMMC) DiskPerformanceTest(bMciID, 1, 1, 0); printf("\n\r"); break; /* Read/Verify ONLY test */ case 'r': case 'R': DiskTest(bMciID, 0, 0, 1); printf("\n\r"); break; /* Read/Verify ONLY performance test */ case 'V': case 'v': DiskPerformanceTest(bMciID, 0, 1, 1); printf("\n\r"); break; /* Show help information */ default: DumpMenu(); } } break; } } } }