void systemInit(void) { //Default configuration SCU_MCLKSourceConfig(SCU_MCLK_OSC); //Configure the FMI FMI_Config(FMI_READ_WAIT_STATE_2, FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE, FMI_LVD_ENABLE, FMI_FREQ_HIGH); //Configure PLL factors SCU_PLLFactorsConfig(192, 25, 2); //Enable PLL and wait for the the PLL to lock SCU_PLLCmd(ENABLE); //Set clock dividers SCU_RCLKDivisorConfig(SCU_RCLK_Div1); SCU_HCLKDivisorConfig(SCU_HCLK_Div1); SCU_FMICLKDivisorConfig(SCU_FMICLK_Div1); SCU_PCLKDivisorConfig(SCU_PCLK_Div2); //Switch to PLL clock SCU_MCLKSourceConfig(SCU_MCLK_PLL); //Enable VIC clock SCU_AHBPeriphClockConfig(__VIC, ENABLE); //Reset VIC peripheral VIC_DeInit(); //Assign default vectors VIC_InitDefaultVectors(); }
static void platform_config_scu() { volatile u16 i = 0xFFFF; while (i-- > 0); // SCU initialization SCU_MCLKSourceConfig(SCU_MCLK_OSC); SCU_PLLFactorsConfig(192,25,2); /* PLL = 96 MHz */ SCU_PLLCmd(ENABLE); /* PLL Enabled */ SCU_MCLKSourceConfig(SCU_MCLK_PLL); /* MCLK = PLL */ SCU_PFQBCCmd( ENABLE ); /* Set the RCLK Clock divider to max speed*/ SCU_RCLKDivisorConfig(SCU_RCLK_Div1); /* Set the PCLK Clock to MCLK/2 */ SCU_PCLKDivisorConfig(SCU_PCLK_Div2); /* Set the HCLK Clock to MCLK */ SCU_HCLKDivisorConfig(SCU_HCLK_Div1); /* Set the BRCLK Clock to MCLK */ SCU_BRCLKDivisorConfig(SCU_BRCLK_Div1); // Enable VIC clock SCU_AHBPeriphClockConfig(__VIC, ENABLE); SCU_AHBPeriphReset(__VIC, DISABLE); // Enable the UART clocks SCU_APBPeriphClockConfig(__UART_ALL, ENABLE); // Enable the timer clocks SCU_APBPeriphClockConfig(__TIM01, ENABLE); SCU_APBPeriphReset(__TIM01, DISABLE); SCU_APBPeriphClockConfig(__TIM23, ENABLE); SCU_APBPeriphReset(__TIM23, DISABLE); // Enable the GPIO clocks SCU_APBPeriphClockConfig(__GPIO_ALL, ENABLE); // Enable the WIU clock SCU_APBPeriphClockConfig(__WIU, ENABLE); SCU_APBPeriphReset(__WIU, DISABLE); // Enable the I2C clocks SCU_APBPeriphClockConfig(__I2C0, ENABLE); SCU_APBPeriphReset(__I2C0, DISABLE); SCU_APBPeriphClockConfig(__I2C1, ENABLE); SCU_APBPeriphReset(__I2C1, DISABLE); // Enable the ADC clocks SCU_APBPeriphClockConfig(__ADC, ENABLE); // Enable the SSP clocks SCU_APBPeriphClockConfig(__SSP0,ENABLE); SCU_APBPeriphReset(__SSP0,DISABLE); SCU_APBPeriphClockConfig(__SSP1,ENABLE); SCU_APBPeriphReset(__SSP1,DISABLE); }
static void prvSetupHardware( void ) { /* Configuration taken from the ST code. Set Flash banks size & address */ FMI_BankRemapConfig( 4, 2, 0, 0x80000 ); /* FMI Waite States */ FMI_Config( FMI_READ_WAIT_STATE_2, FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE, FMI_LVD_ENABLE, FMI_FREQ_HIGH ); /* Configure the FPLL = 96MHz, and APB to 48MHz. */ SCU_PCLKDivisorConfig( SCU_PCLK_Div2 ); SCU_PLLFactorsConfig( 192, 25, 2 ); SCU_PLLCmd( ENABLE ); SCU_MCLKSourceConfig( SCU_MCLK_PLL ); WDG_Cmd( DISABLE ); VIC_DeInit(); /* GPIO8 clock source enable, used by the LCD. */ SCU_APBPeriphClockConfig(__GPIO8, ENABLE); GPIO_DeInit(GPIO8); /* GPIO 9 clock source enable, used by the LCD. */ SCU_APBPeriphClockConfig(__GPIO9, ENABLE); GPIO_DeInit(GPIO9); /* Enable VIC clock */ SCU_AHBPeriphClockConfig(__VIC, ENABLE); SCU_AHBPeriphReset(__VIC, DISABLE); /* Peripheral initialisation. */ vParTestInitialise(); }
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { #ifdef DEBUG debug(); #endif SCU_MCLKSourceConfig(SCU_MCLK_OSC); /*Use OSC as the default clock source*/ SCU_PCLKDivisorConfig(SCU_PCLK_Div1); /* ARM Peripheral bus clokdivisor = 1*/ System_Setup();/*PCLK=8MHz*/ IO_Init(); LED_OFF(LD1); LED_OFF(LD2); LED_OFF(LD3); LED_OFF(LD4); /* CAN tests */ CAN_Com_LoopBack();/* send and receive some frame */ CAN_Com_LoopBack_IRQ();/* send and receive some frame, received in 91x_it.c */ /* LD2, LD3 should be lit */ /* If LD4 lit so something's wrong */ return 0; }
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { #ifdef DEBUG debug(); #endif SCU_MCLKSourceConfig(SCU_MCLK_OSC); /*Use OSC as the default clock source*/ SCU_PCLKDivisorConfig(SCU_PCLK_Div1); /* ARM Peripheral bus clokdivisor = 1*/ /* source addresses and destination addresses for the Second LLI structure */ Link[0]=(u32)(&Buffer0[12]); Link[1]=(u32)(&Buffer2[0]); /* source addresses and destination addresses for the Third LLI structure */ Link[4]=(u32)(&Buffer0[24]); Link[5]=(u32)(&Buffer3[0]); /*Set the addresses of next linked list for the second LLI structure*/ Link[2]=(u32)(&Link[4]); SCU_AHBPeriphClockConfig(__DMA,ENABLE); /* Enable the clock for DMA*/ DMA_DeInit(); /* DMA default configuration : Reset configuration*/ DMA_Cmd(ENABLE);/*Enable the DMA*/ DMA_StructInit(&DMA_InitStruct); /* Write the first LLI*/ DMA_InitStruct.DMA_Channel_LLstItm=(u32)(&Link[0]); /*Set the addresses of next linked list for the first LLI structure*/ DMA_InitStruct.DMA_Channel_SrcAdd=(u32)(&Buffer0[0]); /* source address for the first LLI structure */ DMA_InitStruct.DMA_Channel_DesAdd=(u32)(&Buffer1[0]); /*Destination address for the first LLI structure */ DMA_InitStruct.DMA_Channel_SrcWidth= DMA_SrcWidth_Word;/* The source bus width is a word" 32 bits"*/ DMA_InitStruct.DMA_Channel_DesWidth= DMA_DesWidth_Word; /* The Destination bus width is a word word*/ DMA_InitStruct.DMA_Channel_FlowCntrl=DMA_FlowCntrlt0_DMA;/* DMA is The flow controller*/ DMA_InitStruct.DMA_Channel_TrsfSize =12; /*transfer size*/ /* Configure the DMA channel1 "the chosen channel to perform the transfer" */ DMA_ChannelSRCIncConfig (DMA_Channel1, ENABLE); DMA_ChannelDESIncConfig (DMA_Channel1, ENABLE); DMA_Init(DMA_Channel1,&DMA_InitStruct);/* update the DMA channel1 registers with the cfirst LLI structure*/ DMA_ChannelCmd (DMA_Channel1,ENABLE);/*Enable the DMA channel*/ /*wait for the fifo to be empty*/ while(DMA_GetChannelActiveStatus(DMA_Channel1)); while(1); }
/* Private functions ---------------------------------------------------------*/ void System_Setup(void) { SCU_MCLKSourceConfig(SCU_MCLK_OSC); SCU_PCLKDivisorConfig(SCU_PCLK_Div2); SCU_PLLFactorsConfig(128,25,4); SCU_PLLCmd(ENABLE); SCU_MCLKSourceConfig(SCU_MCLK_PLL); SCU_APBPeriphClockConfig(__CAN, ENABLE); SCU_APBPeriphClockConfig(__GPIO0, ENABLE); SCU_APBPeriphClockConfig(__GPIO1, ENABLE); SCU_APBPeriphClockConfig(__GPIO3, ENABLE); SCU_APBPeriphClockConfig(__GPIO5, ENABLE); SCU_AHBPeriphClockConfig(__VIC, ENABLE); SCU_APBPeriphReset(__CAN, DISABLE); SCU_APBPeriphReset(__GPIO0, DISABLE); SCU_APBPeriphReset(__GPIO1, DISABLE); SCU_APBPeriphReset(__GPIO3, DISABLE); SCU_APBPeriphReset(__GPIO5, DISABLE); SCU_AHBPeriphReset(__VIC, DISABLE); }
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None *******************************************************************************/ int main() { #ifdef DEBUG debug(); #endif SCU_MCLKSourceConfig(SCU_MCLK_OSC); /*Use OSC as the default clock source*/ SCU_PCLKDivisorConfig(SCU_PCLK_Div1); /* ARM Peripheral bus clokdivisor = 1*/ WDG_InitTypeDef WDG_InitStructure; GPIO_InitTypeDef GPIO3_InitStruct; SCU_APBPeriphClockConfig(__GPIO3, ENABLE);/* Enable the clock for GPIO3*/ GPIO_DeInit(GPIO3);/* GPIO3 default configuration : Reset configuration*/ /* Configure the GPIO3 */ GPIO3_InitStruct.GPIO_Pin= GPIO_Pin_2; /* Choose the pin "P3.2 port"*/ GPIO3_InitStruct.GPIO_Direction=GPIO_PinOutput; /* Choose the P3.2 port Direction "output".*/ GPIO3_InitStruct.GPIO_Type = GPIO_Type_PushPull ; GPIO3_InitStruct.GPIO_Alternate=GPIO_OutputAlt1; GPIO_Init(GPIO3,&GPIO3_InitStruct); /*GPIO3 initialization with the previous chosen parameters.*/ GPIO_WriteBit(GPIO3, GPIO_Pin_2, Bit_RESET); /* Reset the P3.2 port " on STR912-SK-IAR Board, LED3 is on "*/ SCU_APBPeriphClockConfig(__WDG, ENABLE); /* Enable the clock for the WDG peripheral*/ WDG_DeInit();/* WDG default configuration : Reset configuration*/ /* Configure the WDG to generate a system reset signal each 1s */ WDG_InitStructure.WDG_Mode = WDG_Mode_Wdg; WDG_InitStructure.WDG_Preload = 0x7d; WDG_InitStructure.WDG_Prescaler = 0xFF; WDG_InitStructure.WDG_ClockSource=WDG_ClockSource_Rtc; /* using the 32khz RTC clock as clock source*/ WDG_Init(&WDG_InitStructure); /* WDG initialization with the previous chosen parameters.*/ while(1) { GPIO_WriteBit(GPIO3, GPIO_Pin_2, Bit_SET); } }
//was main() - JWG int uartInit() { SCU_MCLKSourceConfig(SCU_MCLK_OSC); /*Use OSC as the default clock source*/ SCU_PCLKDivisorConfig(SCU_PCLK_Div1); /* ARM Peripheral bus clokdivisor = 1*/ /* Configure the system clocks */ SCU_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); /* UART0 configuration -------------------------------------------------------*/ /* UART0 configured as follow: - Word Length = 7 Bits - Two Stop Bit - No parity - BaudRate = 115200 baud - Hardware flow control disabled - Receive and transmit enabled - Receive and transmit FIFOs are enabled - Transmit and Receive FIFOs levels have 8 bytes depth */ UART_InitStructure.UART_WordLength = UART_WordLength_7D; UART_InitStructure.UART_StopBits = UART_StopBits_2; UART_InitStructure.UART_Parity = UART_Parity_No ; UART_InitStructure.UART_BaudRate = 115200; UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; UART_InitStructure.UART_FIFO = UART_FIFO_Enable; UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */ UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */ UART_DeInit(UART0); UART_Init(UART0, &UART_InitStructure); /* Enable the UART0 */ UART_Cmd(UART0, ENABLE); /* Communication hyperterminal-UART0 using the hardware flow control */ /* Send a buffer from UART to hyperterminal */ return 0; }
int main(void) { u16 Conversion_Value = 0; #ifdef DEBUG debug(); #endif SCU_MCLKSourceConfig(SCU_MCLK_OSC); /*Use OSC as the default clock source*/ SCU_PCLKDivisorConfig(SCU_PCLK_Div1); /* ARM Peripheral bus clokdivisor = 1*/ SCU_APBPeriphClockConfig(__ADC, ENABLE); /* Enable the clock for the ADC */ ADC_DeInit(); /* ADC Deinitialization */ SCU_APBPeriphClockConfig(__TIM01, ENABLE); /* Enable the clock for TIM0 and TIM1 */ TIM_DeInit(TIM0); /* TIM0 Deinitialization */ SCU_APBPeriphClockConfig(__GPIO4, ENABLE); /* Enable the clock for the GPIO4 */ GPIO_DeInit(GPIO4); /* GPIO4 Deinitialization */ SCU_APBPeriphClockConfig(__GPIO3, ENABLE); /* Enable the clock for the GPIO3 */ GPIO_DeInit(GPIO3); /* GPIO3 Deinitialization */ /* Configure the GPIO4 pin 5 as analog input */ GPIO_ANAPinConfig(GPIO_ANAChannel5, ENABLE); /* GPIO6 configuration (PWM on P3.0, pin 55) */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3; GPIO_Init(GPIO3,&GPIO_InitStructure); /* TIM0 Structure Initialization */ TIM_StructInit(&TIM_InitStructure); /* TIM0 Configuration in PWM Mode */ TIM_InitStructure.TIM_Mode = TIM_PWM; TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB; TIM_InitStructure.TIM_Prescaler = 0x0; TIM_InitStructure.TIM_Pulse_Level_1 = TIM_HIGH; TIM_InitStructure.TIM_Period_Level = TIM_LOW; TIM_InitStructure.TIM_Pulse_Length_1 = 0x200; TIM_InitStructure.TIM_Full_Period = 0x404; TIM_Init (TIM0, &TIM_InitStructure); /* Start the counter of TIM0 */ TIM_CounterCmd(TIM0, TIM_START); /* ADC Structure Initialization */ ADC_StructInit(&ADC_InitStructure); /* Configure the ADC in continuous mode conversion */ ADC_InitStructure.ADC_Channel_5_Mode = ADC_NoThreshold_Conversion; ADC_InitStructure.ADC_Select_Channel = ADC_Channel_5; ADC_InitStructure.ADC_Scan_Mode = DISABLE; ADC_InitStructure.ADC_Conversion_Mode = ADC_Continuous_Mode; /* Enable the ADC */ ADC_Cmd(ENABLE); /* Prescaler config */ ADC_PrescalerConfig(0x0); /* Configure the ADC */ ADC_Init(&ADC_InitStructure); /* Start the conversion */ ADC_ConversionCmd(ADC_Conversion_Start); while(1) { /* Wait until conversion completion */ while(ADC_GetFlagStatus(ADC_FLAG_ECV) == RESET); /* Get the conversion value */ Conversion_Value = ADC_GetConversionValue(ADC_Channel_5); /* Clear the end of conversion flag */ ADC_ClearFlag(ADC_FLAG_ECV); /* Set the new pulse of the TIM0 */ TIM_SetPulse(TIM0, TIM_PWM_OC1_Channel, Conversion_Value); } }
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { #ifdef DEBUG debug(); #endif SCU_MCLKSourceConfig(SCU_MCLK_OSC); /*Use OSC as the default clock source*/ SCU_PCLKDivisorConfig(SCU_PCLK_Div1); /* ARM Peripheral bus clokdivisor = 1*/ /* SCU configuration */ SCU_Configuration(); /* GPIO pins configuration */ GPIO_Configuration(); /* VIC configuration */ VIC_Configuration(); /*I2C0 & I2C1 reset */ I2C_DeInit(I2C0); I2C_DeInit(I2C1); /* Enable I2C0, I2C1 */ I2C_Cmd(I2C0, ENABLE); I2C_Cmd(I2C1, ENABLE); /* Configure GPIO2, I2C0 and I2C1 */ /* I2C0 Configuration */ I2C_Struct.I2C_GeneralCall = I2C_GeneralCall_Disable; I2C_Struct.I2C_Ack = I2C_Ack_Enable; I2C_Struct.I2C_CLKSpeed = 400000; I2C_Struct.I2C_OwnAddress = I2C0OwnAddr; I2C_Init(I2C0, &I2C_Struct); /* I2C1 Configuration */ /* we keep the same config as I2C0 for the other I2C_Struct members */ /* We change just the address*/ I2C_Struct.I2C_OwnAddress = I2C1OwnAddr; I2C_Init(I2C1, &I2C_Struct); Direction = I2C_MODE_TRANSMITTER; Fill_Buffer(I2C1_Buffer_Tx, 0x1); I2C_ITConfig(I2C1, ENABLE); I2C_ITConfig(I2C0, ENABLE); I2C_GenerateStart(I2C1, ENABLE); while (Tx_Idx < BUFFER_SIZE+1); /* Check if the transmitted data is read correctly */ TransferStatus1 = Buffercmp(I2C0_Buffer_Rx, I2C1_Buffer_Tx, BUFFER_SIZE); /* TransferStatus = PASSED, if the transmitted from I2C1 and received data by the I2C0 are the same */ /* TransferStatus = FAILED, if the transmitted from I2C1 and received data by the I2C0 are different */ /*--------------------------------------------------*/ /* Delay between transmission and reception --------*/ /*--------------------------------------------------*/ Delay(100000); /*--------------------------------------------------*/ /* Reception Phase----------------------------------*/ /*--------------------------------------------------*/ /*reset counters*/ Tx_Idx = Rx_Idx = 0; Direction = I2C_MODE_RECEIVER; Fill_Buffer(I2C0_Buffer_Tx, 0x5); I2C_GenerateStart(I2C1, ENABLE); while (Tx_Idx < BUFFER_SIZE+1); /* Check if the transmitted data is read correctly */ TransferStatus2 = Buffercmp(I2C1_Buffer_Rx, I2C0_Buffer_Tx, BUFFER_SIZE); /* TransferStatus = PASSED, if the transmitted from I2C0 and received data by the I2C1 are the same */ /* TransferStatus = FAILED, if the transmitted from I2C0 and received data by the I2C1 are different */ while(1); }
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None *******************************************************************************/ int main() { #ifdef DEBUG debug(); #endif SCU_MCLKSourceConfig(SCU_MCLK_OSC); /*Use OSC as the default clock source*/ SCU_PCLKDivisorConfig(SCU_PCLK_Div1); /* ARM Peripheral bus clokdivisor = 1*/ /* SCU configuration */ SCU_Configuration(); /* GPIO pins configuration */ GPIO_Configuration(); /* SSP0 configuration */ SSP_DeInit(SSP0); SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola; SSP_InitStructure.SSP_Mode = SSP_Mode_Master; SSP_InitStructure.SSP_CPOL = SSP_CPOL_High; SSP_InitStructure.SSP_CPHA = SSP_CPHA_2Edge; SSP_InitStructure.SSP_DataSize = SSP_DataSize_8b; SSP_InitStructure.SSP_ClockRate = 5; SSP_InitStructure.SSP_ClockPrescaler = 2; SSP_Init(SSP0, &SSP_InitStructure); /* SSP1 configuration */ SSP_DeInit(SSP1); SSP_InitStructure.SSP_Mode = SSP_Mode_Slave; SSP_InitStructure.SSP_SlaveOutput = SSP_SlaveOutput_Enable; SSP_Init(SSP1, &SSP_InitStructure); /* SSP0 enable */ SSP_Cmd(SSP0, ENABLE); /* SSP1 enable */ SSP_Cmd(SSP1, ENABLE); /* Master to slave transfer procedure */ while(Tx_Idx<32) { SSP_SendData(SSP0, SSP0_Buffer_Tx[Tx_Idx++]); while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RxFifoNotEmpty)==RESET); SSP1_Buffer_Rx[Rx_Idx++] = SSP_ReceiveData(SSP1); } /* Check the received data with the send ones */ TransferStatus1 = Buffercmp(SSP0_Buffer_Tx, SSP1_Buffer_Rx, 32); /* TransferStatus = PASSED, if the data transmitted from SSP0 and received by SSP1 are the same */ /* TransferStatus = FAILED, if the data transmitted from SSP0 and received by SSP1 are different */ /* Clear SSP0 receive Fifo */ for(k=0; k<8; k++) SSP0_Buffer_Rx[k] = SSP_ReceiveData(SSP0); /* Reset counters */ Tx_Idx=Rx_Idx=0; /* Slave to master transfer procedure */ while(Tx_Idx<32) { SSP_SendData(SSP1, SSP1_Buffer_Tx[Tx_Idx]); /* send a dummy bit to generate the clock */ SSP_SendData(SSP0, SSP0_Buffer_Tx[Tx_Idx++]); while(SSP_GetFlagStatus(SSP0, SSP_FLAG_RxFifoNotEmpty)==RESET); SSP0_Buffer_Rx[Rx_Idx++] = SSP_ReceiveData(SSP0); } /* Check the received data with the send ones */ TransferStatus2 = Buffercmp(SSP1_Buffer_Tx, SSP0_Buffer_Rx, 32); /* TransferStatus = PASSED, if the data transmitted from SSP1 and received by SSP0 are the same */ /* TransferStatus = FAILED, if the data transmitted from SSP1 and received by SSP0 are different */ while(1); }