Ejemplo n.º 1
0
void UART_Configuration(void)
{
     UART_InitTypeDef UART_InitStructure;

     /* UART Configuration for UART1*/
     UART_StructInit(&UART_InitStructure);
     UART_Init(UART1,&UART_InitStructure);
}
Ejemplo n.º 2
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main()
{
    int i;

    /*System clock configuration*/
    SystemInit();
    /* UART0 and UART1 configuration*/
    UART_StructInit(&UART_InitStructure);
    /* Configure UART0 */
    UART_Init(UART1,&UART_InitStructure);
    printf("########  I2C EEPROM TEST  #########\r\n");

    /* I2C Init */

    /*  I2C confiugred as follow:
     *  - I2C master mode
     *  - I2C slave address : 0xA0
     *  - I2C Prescale : 0x61
     *     /If MCU clock is 20MHz and Prescale value is 0x61, SCL occurs 100KHz as clock.
     *  - I2C Timeout : 0xFFFF
     */
    conf.mode = I2C_Master;
    conf.slave_address = 0xA0;
    conf.master.prescale = 0x61;
    conf.master.timeout = 0xFFFF;
    /* Cofigure I2C0 */
    I2C_Init(I2C0, conf);

    /* EEPROM Write Test*/
    /* It can transmit up to 9data bytes to the EEPROM(24AA02) ( mem_address 1byte, data 8bytes )   */
    if( I2C_Burst_Write(I2C0,conf.slave_address,&Transmit_Data[0],9,1) == -1 )
        return -1; 
    /*It must be use the delay function between Write operation and Read operation */
    I2C_Delay(0x000F0000);
    /*I2C Core reset */
    I2C_Reset(I2C0);

    // EEPROM Read Test
    /* I2C Start */
    I2C_Start(I2C0,conf.slave_address,I2C_WRITE_SA7);
    /* The memory address of EEPROM send to EEPROM and it wait the ack signal */
    I2C_SendDataAck(I2C0,0x00);         
    /*Once the Slave address and memotu address are clocked in and 
     *acknowledged by the EEPROM, the W7500 must generate another start condition.*/
    I2C_Restart_Structure(I2C0,conf.slave_address,I2C_READ_SA7);
    /* EEPROM Read Test*/
    for(i=0;i<MAX_SIZE;i++)
    {
        if(i != MAX_SIZE-1)     Recv_Data[i] = I2C_ReceiveData(I2C0,0);
        else                    Recv_Data[i] = I2C_ReceiveData(I2C0,1);
    }

    for(i=0;i<MAX_SIZE-2;i+=2)
        printf("[%02d]:%02x,  [%02d]:%02x\r\n",i,Recv_Data[i],i+1,Recv_Data[i+1]);

    return 0;
}
Ejemplo n.º 3
0
int main()
{
    /*System clock configuration*/
	SystemInit();    
    /* UART0 and UART1 configuration*/
    UART_StructInit(&UART_InitStructure);
    /* Configure UART0 */
    UART_Init(UART1,&UART_InitStructure);
  	S_UART_Init(115200);
    /* Retarget functions for GNU Tools for ARM Embedded Processors*/
    UartPuts(UART1,"UART 1 Test(#1)\r\n");
    printf("UART 2 Test(#2)\r\n"); 
}
Ejemplo n.º 4
0
int main()
{
    uint32_t i;
  

    /*System clock configuration*/
	SystemInit();
//    *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz
    
    /* CLK OUT Set */
//    PAD_AFConfig(PAD_PA,GPIO_Pin_2, PAD_AF2); // PAD Config - CLKOUT used 3nd Function

    /*using debugging*/
    S_UART_Init(115200);
    /* UART0 and UART1 configuration*/
    UART_StructInit(&UART_InitStructure);
    /* Configure UART0 */
    UART_Init(UART0,&UART_InitStructure);
    /* Configure UART1 */
    UART_Init(UART1,&UART_InitStructure);
    /* Configure Uart0 Interrupt Enable*/
    UART_ITConfig(UART0, (UART_IT_FLAG_TXI|UART_IT_FLAG_RXI),ENABLE);
    /* NVIC configuration */
    NVIC_ClearPendingIRQ(UART0_IRQn);
    NVIC_EnableIRQ(UART0_IRQn);
    /* Configure Uart1 Interrupt Enable*/
    UART_ITConfig(UART1,(UART_IT_FLAG_TXI|UART_IT_FLAG_RXI),ENABLE);
     /* NVIC configuration */
    NVIC_ClearPendingIRQ(UART1_IRQn);
    NVIC_EnableIRQ(UART1_IRQn);
    /*send the data from UART0 to UART1*/    
    printf("Send UART0\r\n");
    for(i=0;i<409600;i++)
    {
        UartPutc(UART0,(uint8_t)i);
    }
    /*send the data from UART1 to UART0*/    
    printf("Send UART1\r\n");
    for(i=0;i<409600;i++)
    {
        UartPutc(UART1,(uint8_t)i);
    }
    /*confirm the rx/tx data counter of Uart0,1 using Uart2*/    
    printf("Press Any Key\r\n");
    while( S_UartGetc() != 0 )
    {
        printf("uart0_rx_cnt = %d, uart0_tx_cnt = %d\r\n",uart0_rx_cnt, uart0_tx_cnt);
        printf("uart1_rx_cnt = %d, uart1_tx_cnt = %d\r\n",uart1_rx_cnt, uart1_tx_cnt);
    }
  
}
Ejemplo n.º 5
0
int main()
{
    uint32_t i;
  

    /*System clock configuration*/
	SystemInit();
    /*using debugging*/
    S_UART_Init(115200);
    /* UART0 and UART1 configuration*/
    UART_StructInit(&UART_InitStructure);
    /* Configure UART0 */
    UART_Init(UART0,&UART_InitStructure);
    /* Configure UART1 */
    UART_Init(UART1,&UART_InitStructure);
    /* Configure Uart0 Interrupt Enable*/
    UART_ITConfig(UART0, (UART_IT_FLAG_TXI|UART_IT_FLAG_RXI),ENABLE);
    /* NVIC configuration */
    NVIC_ClearPendingIRQ(UART0_IRQn);
    NVIC_EnableIRQ(UART0_IRQn);
    /* Configure Uart1 Interrupt Enable*/
    UART_ITConfig(UART1,(UART_IT_FLAG_TXI|UART_IT_FLAG_RXI),ENABLE);
     /* NVIC configuration */
    NVIC_ClearPendingIRQ(UART1_IRQn);
    NVIC_EnableIRQ(UART1_IRQn);
    /*send the data from UART0 to UART1*/    
    printf("Send UART0\r\n");
    for(i=0;i<409600;i++)
    {
        UartPutc(UART0,(uint8_t)i);
    }
    /*send the data from UART1 to UART0*/    
    printf("Send UART1\r\n");
    for(i=0;i<409600;i++)
    {
        UartPutc(UART1,(uint8_t)i);
    }
    /*confirm the rx/tx data counter of Uart0,1 using Uart2*/    
    printf("Press Any Key\r\n");
    while( S_UartGetc() != 0 )
    {
        printf("uart0_rx_cnt = %d, uart0_tx_cnt = %d\r\n",uart0_rx_cnt, uart0_tx_cnt);
        printf("uart1_rx_cnt = %d, uart1_tx_cnt = %d\r\n",uart1_rx_cnt, uart1_tx_cnt);
    }
  
}
Ejemplo n.º 6
0
Archivo: main.c Proyecto: Wiznet/W7500
int main()
{
	 /*System clock configuration*/
	SystemInit();
//    *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz
    
    /* CLK OUT Set */
//    PAD_AFConfig(PAD_PA,GPIO_Pin_2, PAD_AF2); // PAD Config - CLKOUT used 3nd Function
    /* UART0 and UART1 configuration*/
    UART_StructInit(&UART_InitStructure);
    /* Configure UART0 */
    UART_Init(UART0,&UART_InitStructure);
    /* Configure UART1 */
    UART_Init(UART1,&UART_InitStructure);

    while(TxCounter < TxBufferSize)
    {
        /* Send one byte from UART0 to UART1 */
        UART_SendData(UART0,TxBuffer[TxCounter++]);

        /* Loop until UART0 TX FIFO Register is empty */
        while(UART_GetFlagStatus(UART0,UART_FLAG_TXFE) == RESET)
        {
        } 

        /* Loop until the UART1 Receive FIFO Register is not empty */
        while(UART_GetFlagStatus(UART1,UART_FLAG_RXFE) == SET)
        {
        }
        
        /* Store the received byte in RxBuffer */
        RxBuffer[RxCounter++] = (UART_ReceiveData(UART1) & 0xFF);
    }

    /* Check the received data with the send ones */
    TransferStatus  = Buffercmp(TxBuffer, RxBuffer, TxBufferSize);
    /* TransferStatus = PASSED, if the data transmitted from USARTy and  
       received by USARTz are the same */
    /* TransferStatus = FAILED, if the data transmitted from USARTy and 
       received by USARTz are different */

    while(1)
    {
    } 
}
Ejemplo n.º 7
0
int main()
{
    float result = 0;
    uint8_t recv_data[2] ={0,};
    uint8_t register_address = LM75_REG_TEMP;
    
    

    /*System clock configuration*/
    SystemInit();
//    *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz
    
    /* CLK OUT Set */
//    PAD_AFConfig(PAD_PA,GPIO_Pin_2, PAD_AF2); // PAD Config - CLKOUT used 3nd Function

    /* UART0 and UART1 configuration*/
    UART_StructInit(&UART_InitStructure);
    /* Configure UART0 */
    UART_Init(UART1,&UART_InitStructure);
    printf("########  I2C LM75 Temperature TEST  #########\r\n");
    
    /* Cofigure I2C0 */
    conf.scl = I2C_PA_9;
    conf.sda = I2C_PA_10;
    I2C_Init(&conf);
    while(1)
    {
        /* Temperature Read Test*/
        /*Send LM75 slave address */
        I2C_Write(&conf, LM75_7bitSlaveAddress, &register_address, 0);
        delay_us(10);
        
        /*Read data*/
        I2C_Read(&conf, LM75_7bitSlaveAddress, &recv_data[0], 2);
        
        result = ((recv_data[0] << 8) | recv_data[1]) >> 5;
        result = result * 0.125;
        
        printf("Temperature : %.2f \r\n", result);
        
        delay_ms(2000);
    }
 } 
Ejemplo n.º 8
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main()
{
    int i;

    /*System clock configuration*/
    SystemInit();
//    *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz
    
    /* CLK OUT Set */
//    PAD_AFConfig(PAD_PA,GPIO_Pin_2, PAD_AF2); // PAD Config - CLKOUT used 3nd Function
    /* UART0 and UART1 configuration*/
    UART_StructInit(&UART_InitStructure);
    /* Configure UART1 */
    UART_Init(UART1,&UART_InitStructure);
   
    conf.scl = I2C_PA_9;
    conf.sda = I2C_PA_10;
    
    I2C_Init(&conf);
    
    //============ Write ==============
    I2C_Write(&conf, 0xa0, &Transmit_Data[0], MAX_SIZE);
    
    delay_function(4000);
    
    //========= Read =============
    //Write memory address
    I2C_Write(&conf, 0xA0, &Transmit_Data[0], 1);
    
    delay_function(4000);
    //Read data
    I2C_Read(&conf, 0xA0, &Recv_Data[0], MAX_SIZE - 1);
    
    printf("Recv data : ");
    for(i=0; i<MAX_SIZE - 1; i++)
    {
        printf("0x%x ", Recv_Data[i]);
    }
    printf("\r\n");
    
    
}
Ejemplo n.º 9
0
Archivo: main.c Proyecto: Wiznet/W7500
int main()
{
    int32_t ch;

    /*System clock configuration*/
	SystemInit();
    
    /* CLK OUT Set */
//    PAD_AFConfig(PAD_PA,GPIO_Pin_2, PAD_AF2); // PAD Config - CLKOUT used 3nd Function

    /*using debugging*/
    S_UART_Init(115200);
    UART_StructInit(&UART_InitStructure);

    //UART_Init(UART0,&UART_InitStructure);
    UART_Init(UART1,&UART_InitStructure);

    UART_ITConfig(UART0,(UART_IT_FLAG_RXI),ENABLE);
    UART_ITConfig(UART1,(UART_IT_FLAG_RXI),ENABLE);

        //UART_FIFO_Enable(UART0,0,4);
    UART_FIFO_Enable(UART1,0,0);

    
    //S_UART_ITConfig(S_UART_CTRL_RXI,ENABLE);

    /* NVIC configuration */
    NVIC_ClearPendingIRQ(UART0_IRQn);
    NVIC_EnableIRQ(UART0_IRQn);

    NVIC_ClearPendingIRQ(UART1_IRQn);
    NVIC_EnableIRQ(UART1_IRQn);
    
    while(1)
    {
        ch = uart_getc(1);
        uart_putc(1,(uint8_t)ch);
        //printf("u1rx_cnt %d\r\n",u1rx_cnt);
    }
  
}
Ejemplo n.º 10
0
Archivo: main.c Proyecto: Wiznet/W7500P
int main()
{
	 /*System clock configuration*/
	SystemInit();
    /* UART0 and UART1 configuration*/
    UART_StructInit(&UART_InitStructure);
    /* Configure UART0 */
    UART_Init(UART0,&UART_InitStructure);
    /* Configure UART1 */
    UART_Init(UART1,&UART_InitStructure);

    while(TxCounter < TxBufferSize)
    {
        /* Send one byte from UART0 to UART1 */
        UART_SendData(UART0,TxBuffer[TxCounter++]);

        /* Loop until UART0 TX FIFO Register is empty */
        while(UART_GetFlagStatus(UART0,UART_FLAG_TXFE) == RESET)
        {
        } 

        /* Loop until the UART1 Receive FIFO Register is not empty */
        while(UART_GetFlagStatus(UART1,UART_FLAG_RXFE) == SET)
        {
        }
        
        /* Store the received byte in RxBuffer */
        RxBuffer[RxCounter++] = (UART_ReceiveData(UART1) & 0xFF);
    }

    /* Check the received data with the send ones */
    TransferStatus  = Buffercmp(TxBuffer, RxBuffer, TxBufferSize);
    /* TransferStatus = PASSED, if the data transmitted from USARTy and  
       received by USARTz are the same */
    /* TransferStatus = FAILED, if the data transmitted from USARTy and 
       received by USARTz are different */

    while(1)
    {
    } 
}
Ejemplo n.º 11
0
void UART0_Configure(u16 Baudrate)
{
	UART_InitTypeDef UART_InitStructure;

	SCU_APBPeriphClockConfig(__UART0, ENABLE);  // Enable the UART0 Clock

  	/* UART0 configured as follow:
          - Word Length = 8 Bits
          - One Stop Bit
          - No parity
          - BaudRate taken from function argument
          - Hardware flow control Disabled
          - Receive and transmit enabled
          - Receive and transmit FIFOs are Disabled
    */
	UART_StructInit(&UART_InitStructure);
    UART_InitStructure.UART_WordLength = 			UART_WordLength_8D;
    UART_InitStructure.UART_StopBits = 				UART_StopBits_1;
    UART_InitStructure.UART_Parity = 				UART_Parity_No ;
    UART_InitStructure.UART_BaudRate = 				Baudrate;
    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;
    UART_InitStructure.UART_RxFIFOLevel = 			UART_FIFOLevel_1_2;

	UART_DeInit(UART0);	// reset uart 0	to default
    UART_Init(UART0, &UART_InitStructure);  // initialize uart 0

	// enable uart 0 interrupts selective
    UART_ITConfig(UART0, UART_IT_Receive | UART_IT_ReceiveTimeOut  /*| UART_IT_FrameError*/, ENABLE);
	UART_Cmd(UART0, ENABLE); // enable uart 0
	// configure the uart 0 interupt line
 	VIC_Config(UART0_ITLine, VIC_IRQ, PRIORITY_UART0);
	// enable the uart 0 IRQ
	VIC_ITCmd(UART0_ITLine, ENABLE);
}
Ejemplo n.º 12
0
Archivo: main.c Proyecto: Wiznet/W7500P
int main()
{
    uint32_t i;
    uint8_t idx;


    /*System clock configuration*/
    SystemInit();
    /* UART0 and UART1 configuration*/
    UART_StructInit(&UART_InitStructure);
    /*Hardware Flow Control use(RTS/CTS).*/
    UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_RTS_CTS;
    /*Transmit and receive FIFO buffers are enable(FIFO mode)*/
    UART0->LCR_H |=UART_LCR_H_FEN;
    UART1->LCR_H |=UART_LCR_H_FEN;
    /*UART FIFO Level Select  - TX/RX  level select 1/4 full. */
    SetUartIFLS(UART0,UART_IFLS_RXIFLSEL1_4,UART_IFLS_TXIFLSEL1_4);
    SetUartIFLS(UART1,UART_IFLS_RXIFLSEL1_4,UART_IFLS_TXIFLSEL1_4);
    /* Configure UART0 */
    UART_Init(UART0,&UART_InitStructure);
    /* Configure UART1 */
    UART_Init(UART1,&UART_InitStructure);

#ifdef UART2_DEBUG
    S_UART_Init(115200);
#endif


#ifdef UART2_DEBUG
    printf("TxBufferSize= %x\r\n",TxBufferSize);
#endif
    /* The data of TXbuffer send from UART0 to UART1.*/
    for(idx=0; idx<= TxBufferSize-1; idx++)
    {
        /*Check the RTS of UART1 bit*/
        if((UART0->FR &UART_FR_CTS )!=0)
        {
            UART0->DR = TxBuffer[idx];
            /*If this bit is set to 1, the UART is busy transmitting data.
             * This bitt remains set until the complete byte, including all the stop bits, has been sent from the shift register,*/
            while(UART0->FR & UART_FR_BUSY);
#ifdef UART2_DEBUG
            printf("idx = %x\r\n",idx);
#endif
        }
    }
#ifdef UART2_DEBUG
    printf("\r\n");
    printf("Read DATA : \r\n");
#endif

    /*Check the  data of RXbuffer(from UART0 to UART1)*/
    for(i=0; i<=idx-2 ; i++)
    {
        /*Confirm the RX FIFO Empty flag*/
        if((UART1->FR & UART_FR_RXFE)==0)
        {
            RxBuffer[i] = (UART1->DR & 0xFF);
#ifdef UART2_DEBUG
            printf("%x = %c\r\n",i,RxBuffer[i]);
#endif
        }
    }
}
Ejemplo n.º 13
0
/**
  * @brief  Main Function
  */
int main()
{
    uint32_t i,result;

	SystemInit();
//    *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz
    
    /* CLK OUT Set */
//    PAD_AFConfig(PAD_PA,GPIO_Pin_2, PAD_AF2); // PAD Config - CLKOUT used 3nd Function
#ifdef __DEBUG
    UART_StructInit(&UART_InitStructure);
    UART_Init(USING_UART,&UART_InitStructure);
    UartPuts(USING_UART,"Test Start\r\n");
#endif


    // Make Dummy Data for Flash Write Test
    for(i=0;i<SECT_SIZE;i++)
    {
        save_buff[i] = i;
    }

    // Step 1 DATA0 Erase, Read, Write Test
    DO_IAP(IAP_ERAS_DAT0,0,0,0);
    DO_IAP(IAP_PROG,DAT0_START_ADDR,save_buff,SECT_SIZE);
    result = Buffercmp((uint8_t*)save_buff,((uint8_t *)(DAT0_START_ADDR)),SECT_SIZE);
#ifdef __DEBUG
    if(result == PASSED)
        UartPuts(USING_UART,"Step1 Test Passed\r\n");
    else
        UartPuts(USING_UART,"Step1 Test Falied\r\n");
#endif


    // Step 2 DATA1 Erase, Read, Write Test
    DO_IAP(IAP_ERAS_DAT1,0,0,0);
    DO_IAP(IAP_PROG,DAT1_START_ADDR,save_buff,SECT_SIZE);
    result = Buffercmp((uint8_t*)save_buff,((uint8_t *)(DAT1_START_ADDR)),SECT_SIZE);
#ifdef __DEBUG
    if(result == PASSED)
        UartPuts(USING_UART,"Step2 Test Passed\r\n");
    else
        UartPuts(USING_UART,"Step2 Test Falied\r\n");
#endif

    // Step 3 Code Flash Block Erase, Read, Write Test
    for(i=0;i<BLOCK_SIZE;i++)
    {
        save_buff[i] = i;
    }

    DO_IAP(IAP_ERAS_BLCK,CODE_TEST_ADDR,0,0);
    DO_IAP(IAP_PROG, CODE_TEST_ADDR,save_buff,BLOCK_SIZE);
    result = Buffercmp((uint8_t*)save_buff,((uint8_t *)(CODE_TEST_ADDR)),BLOCK_SIZE);
#ifdef __DEBUG
    if(result == PASSED)
        UartPuts(USING_UART,"Step3 Test Passed\r\n");
    else
        UartPuts(USING_UART,"Step3 Test Falied\r\n");
#endif
}
Ejemplo n.º 14
0
void main(void)
#endif
{
	RST_CLK_DeInit();
	RST_CLK_CPU_PLLconfig(RST_CLK_CPU_PLLsrcHSIdiv2, 0);
	/* Enable peripheral clocks --------------------------------------------------*/
	RST_CLK_PCLKcmd(
				(RST_CLK_PCLK_RST_CLK |
				 RST_CLK_PCLK_UART1   |
				 RST_CLK_PCLK_UART2   |
				 RST_CLK_PCLK_DMA),
				 ENABLE);
	RST_CLK_PCLKcmd((RST_CLK_PCLK_PORTC | RST_CLK_PCLK_PORTD), ENABLE);

	/* Disable all DMA request */
	MDR_DMA ->CHNL_REQ_MASK_CLR = 0xFFFFFFFF;
	MDR_DMA ->CHNL_USEBURST_CLR = 0xFFFFFFFF;

	/* Reset PORTC settings */
	PORT_DeInit(MDR_PORTC );
	/* Reset PORTC settings */
	PORT_DeInit(MDR_PORTD );

	/* Configure UART1 pins: RXD, TXD */

	/* Configure PORTB pins 3, 4 */
	PORT_InitStructure.PORT_Pin = PORT_Pin_4;
	PORT_InitStructure.PORT_OE = PORT_OE_IN;
	PORT_InitStructure.PORT_FUNC = PORT_FUNC_MAIN;
	PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL;
	PORT_InitStructure.PORT_SPEED = PORT_SPEED_FAST;
	PORT_Init(MDR_PORTC, &PORT_InitStructure);

	PORT_InitStructure.PORT_Pin = PORT_Pin_3;
	PORT_InitStructure.PORT_OE = PORT_OE_OUT;
	PORT_Init(MDR_PORTC, &PORT_InitStructure);

	/* Configure UART2 pins: RXD, TXD */

	/* Configure PORTF pins 13, 14 */
	PORT_InitStructure.PORT_Pin = PORT_Pin_14;
	PORT_InitStructure.PORT_FUNC = PORT_FUNC_MAIN;
	PORT_InitStructure.PORT_OE = PORT_OE_IN;
	PORT_Init(MDR_PORTD, &PORT_InitStructure);

	PORT_InitStructure.PORT_Pin = (PORT_Pin_13);
	PORT_InitStructure.PORT_OE = PORT_OE_OUT;
	PORT_Init(MDR_PORTD, &PORT_InitStructure);

	/* Init RAM */
	Init_RAM(DstBuf1, BufferSize);
	Init_RAM(SrcBuf1, BufferSize);
	Init_RAM(DstBuf2, BufferSize);
	Init_RAM(SrcBuf2, BufferSize);

	/* Reset all UART settings */
	UART_DeInit(MDR_UART1 );
	UART_DeInit(MDR_UART2 );

	UART_BRGInit(MDR_UART1, UART_HCLKdiv1 );
	UART_BRGInit(MDR_UART2, UART_HCLKdiv1 );

	/* UART1 configuration ------------------------------------------------*/
	UART_StructInit(&sUART);

	sUART.UART_BaudRate 			= 1200;
	sUART.UART_WordLength 			= UART_WordLength8b;
	sUART.UART_StopBits 			= UART_StopBits1;
	sUART.UART_Parity 				= UART_Parity_No;
	sUART.UART_FIFOMode 			= UART_FIFO_ON;
	sUART.UART_HardwareFlowControl 	= (UART_HardwareFlowControl_RXE
									| UART_HardwareFlowControl_TXE );
	UART_Init(MDR_UART1, &sUART);
	UART_DMAConfig( MDR_UART1,
					UART_IT_FIFO_LVL_8words,
				    UART_IT_FIFO_LVL_8words );

	/* UART2 configuration ------------------------------------------------*/
	UART_Init(MDR_UART2, &sUART);
	UART_DMAConfig(MDR_UART2,
				   UART_IT_FIFO_LVL_8words,
				   UART_IT_FIFO_LVL_8words );

	/* Enable UART1 DMA Rx and Tx request */
	UART_DMACmd(MDR_UART1, (UART_DMA_RXE | UART_DMA_TXE ), ENABLE);
	/* Enable UART2 DMA Rx and Tx request */
	UART_DMACmd(MDR_UART2, (UART_DMA_RXE | UART_DMA_TXE ), ENABLE);

	/* Reset all DMA settings */
	DMA_DeInit();
	DMA_StructInit(&DMA_InitStr);

	/* DMA_Channel_UART1_RX configuration ---------------------------------*/
	/* Set Primary Control Data */
	DMA_PriCtrlStr.DMA_SourceBaseAddr 	= (uint32_t) (&(MDR_UART1 ->DR));
	DMA_PriCtrlStr.DMA_DestBaseAddr 	= (uint32_t) DstBuf1;
	DMA_PriCtrlStr.DMA_SourceIncSize 	= DMA_SourceIncNo;
	DMA_PriCtrlStr.DMA_DestIncSize 		= DMA_DestIncByte;
	DMA_PriCtrlStr.DMA_MemoryDataSize 	= DMA_MemoryDataSize_Byte;
	DMA_PriCtrlStr.DMA_Mode 			= DMA_Mode_Basic;
	DMA_PriCtrlStr.DMA_CycleSize 		= BufferSize;
	DMA_PriCtrlStr.DMA_NumContinuous 	= DMA_Transfers_8;
	DMA_PriCtrlStr.DMA_SourceProtCtrl 	= DMA_SourcePrivileged;
	DMA_PriCtrlStr.DMA_DestProtCtrl 	= DMA_DestPrivileged;
	/* Set Channel Structure */
	DMA_InitStr.DMA_PriCtrlData 		= &DMA_PriCtrlStr;
	DMA_InitStr.DMA_Priority 			= DMA_Priority_High;
	DMA_InitStr.DMA_UseBurst	 		= DMA_BurstClear;
	DMA_InitStr.DMA_SelectDataStructure = DMA_CTRL_DATA_PRIMARY;
	/* Init DMA channel */
	DMA_Init(DMA_Channel_REQ_UART1_RX, &DMA_InitStr);

	/* DMA_Channel_UART2_RX configuration ---------------------------------*/
	/* Set Primary Control Data */
	DMA_PriCtrlStr.DMA_SourceBaseAddr 	= (uint32_t) (&(MDR_UART2 ->DR));
	DMA_PriCtrlStr.DMA_DestBaseAddr 	= (uint32_t) DstBuf2;
	/* Init DMA channel */
	DMA_Init(DMA_Channel_REQ_UART2_RX, &DMA_InitStr);

	/* DMA_Channel_UART1_TX configuration ---------------------------------*/
	/* Set Primary Control Data */
	DMA_PriCtrlStr.DMA_SourceBaseAddr 	= (uint32_t) SrcBuf1;
	DMA_PriCtrlStr.DMA_DestBaseAddr 	= (uint32_t) (&(MDR_UART1 ->DR));
	DMA_PriCtrlStr.DMA_SourceIncSize 	= DMA_SourceIncByte;
	DMA_PriCtrlStr.DMA_DestIncSize 		= DMA_DestIncNo;
	DMA_InitStr.DMA_Priority 			= DMA_Priority_Default;
	/* Init DMA channel */
	DMA_Init(DMA_Channel_REQ_UART1_TX, &DMA_InitStr);

	/* DMA_Channel_UART2_TX configuration ---------------------------------*/
	/* Set Primary Control Data */
	DMA_PriCtrlStr.DMA_SourceBaseAddr 	= (uint32_t) SrcBuf2;
	DMA_PriCtrlStr.DMA_DestBaseAddr 	= (uint32_t) (&(MDR_UART2 ->DR));
	/* Init DMA channel */
	DMA_Init(DMA_Channel_REQ_UART2_TX, &DMA_InitStr);

	/* Enable UART1 */
	UART_Cmd(MDR_UART1, ENABLE);
	/* Enable UART2 */
	UART_Cmd(MDR_UART2, ENABLE);

	/* Transfer complete */
	while ((DMA_GetFlagStatus(DMA_Channel_REQ_UART1_TX, DMA_FLAG_CHNL_ENA )));
	while ((DMA_GetFlagStatus(DMA_Channel_REQ_UART1_RX, DMA_FLAG_CHNL_ENA )));
	while ((DMA_GetFlagStatus(DMA_Channel_REQ_UART2_TX, DMA_FLAG_CHNL_ENA )));
	while ((DMA_GetFlagStatus(DMA_Channel_REQ_UART2_RX, DMA_FLAG_CHNL_ENA )));

	/* Check the corectness of written dada */
	TransferStatus1 = Verif_mem((BufferSize / 2), SrcBuf1, DstBuf2);
	TransferStatus2 = Verif_mem((BufferSize / 2), SrcBuf2, DstBuf1);
	/* TransferStatus1, TransferStatus2 = PASSED, if the data transmitted and received
	 are correct */
	/* TransferStatus1, TransferStatus2 = FAILED, if the data transmitted and received
	 are different */

	while (1);
}
Ejemplo n.º 15
0
int serial_open(char *name, unsigned int *subdevice)
{
  unsigned int port;
  unsigned int baudrate;
  GPIO_InitTypeDef config_pin;
  UART_InitTypeDef config_uart;

  errno_r = 0;

// Look up serial port number

  port = serial_name_to_port(name);
  if (port < 0) return port;

// Pass up port number, if requested

  if (subdevice != NULL)
    *subdevice = port;

// Extract baud rate from device name

  baudrate = atoi(name+5);

/* We assume the UART pin configuration of the STR910-EVAL board: */

/*   UART0 RxD is P51 alt in  1 */
/*   UART0 TxD is P34 alt out 3 */
/*   UART1 RxD is P32 alt in  1 */
/*   UART1 TxD is P33 alt out 2 */
/*   UART2 RxD is P31 alt in  1 */
/*   UART2 TxD is P35 alt out 3 */

  switch (port)
  {
    case 0:

// Turn on UART clock

      SCU_APBPeriphClockConfig(__UART0, ENABLE);

// Let UART out of reset

      SCU_APBPeriphReset(__UART0, DISABLE);

// Disable IRDA mode

      SCU_UARTIrDASelect(SCU_UART0, SCU_UARTMode_UART);

// Turn on GPIO clock

      SCU_APBPeriphClockConfig(__GPIO3, ENABLE);
      SCU_APBPeriphClockConfig(__GPIO5, ENABLE);

// Let GPIO out of reset

      SCU_APBPeriphReset(__GPIO3, DISABLE);
      SCU_APBPeriphReset(__GPIO5, DISABLE);

// Configure RxD on P51 alt in 1

      GPIO_StructInit(&config_pin);
      config_pin.GPIO_Pin = GPIO_Pin_1;
      config_pin.GPIO_Direction = GPIO_PinInput;
      config_pin.GPIO_Type = GPIO_Type_PushPull;
      config_pin.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
      config_pin.GPIO_Alternate = GPIO_InputAlt1;
      GPIO_Init(GPIO5, &config_pin);

// Configure TxD on P34 alt out 3

      GPIO_StructInit(&config_pin);
      config_pin.GPIO_Pin = GPIO_Pin_4;
      config_pin.GPIO_Direction = GPIO_PinOutput;
      config_pin.GPIO_Type = GPIO_Type_PushPull;
      config_pin.GPIO_Alternate = GPIO_OutputAlt3;
      GPIO_Init(GPIO3, &config_pin);
      break;

    case 1:

// Turn on UART clock

      SCU_APBPeriphClockConfig(__UART1, ENABLE);

// Let UART out of reset

      SCU_APBPeriphReset(__UART1, DISABLE);

// Disable IRDA mode

      SCU_UARTIrDASelect(SCU_UART1, SCU_UARTMode_UART);

// Turn on GPIO clock

      SCU_APBPeriphClockConfig(__GPIO3, ENABLE);

// Let GPIO out of reset

      SCU_APBPeriphReset(__GPIO3, DISABLE);

// Configure RxD on P32 alt in 1

      GPIO_StructInit(&config_pin);
      config_pin.GPIO_Pin = GPIO_Pin_2;
      config_pin.GPIO_Direction = GPIO_PinInput;
      config_pin.GPIO_Type = GPIO_Type_PushPull;
      config_pin.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
      config_pin.GPIO_Alternate = GPIO_InputAlt1;
      GPIO_Init(GPIO3, &config_pin);

// Configure TxD on P33 alt out 2

      GPIO_StructInit(&config_pin);
      config_pin.GPIO_Pin = GPIO_Pin_3;
      config_pin.GPIO_Direction = GPIO_PinOutput;
      config_pin.GPIO_Type = GPIO_Type_PushPull;
      config_pin.GPIO_Alternate = GPIO_OutputAlt2;
      GPIO_Init(GPIO3, &config_pin);
      break;

    case 2:

// Turn on UART clock

      SCU_APBPeriphClockConfig(__UART2, ENABLE);

// Let UART out of reset

      SCU_APBPeriphReset(__UART2, DISABLE);

// Disable IRDA mode

      SCU_UARTIrDASelect(SCU_UART2, SCU_UARTMode_UART);

// Turn on GPIO clock

      SCU_APBPeriphClockConfig(__GPIO3, ENABLE);

// Let GPIO out of reset

      SCU_APBPeriphReset(__GPIO3, DISABLE);

// Configure RxD on P31 alt in 1

      GPIO_StructInit(&config_pin);
      config_pin.GPIO_Pin = GPIO_Pin_1;
      config_pin.GPIO_Direction = GPIO_PinInput;
      config_pin.GPIO_Type = GPIO_Type_PushPull;
      config_pin.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
      config_pin.GPIO_Alternate = GPIO_InputAlt1;
      GPIO_Init(GPIO3, &config_pin);

// Configure TxD on P35 alt out 3

      GPIO_StructInit(&config_pin);
      config_pin.GPIO_Pin = GPIO_Pin_5;
      config_pin.GPIO_Direction = GPIO_PinOutput;
      config_pin.GPIO_Type = GPIO_Type_PushPull;
      config_pin.GPIO_Alternate = GPIO_OutputAlt3;
      GPIO_Init(GPIO3, &config_pin);
      break;

    default :
      errno_r = ENODEV;
      return -1;
  }

// Reset UART

  UART_DeInit(UARTS[port]);

// Configure UART

  UART_StructInit(&config_uart);
  config_uart.UART_WordLength = UART_WordLength_8D;
  config_uart.UART_StopBits = UART_StopBits_1;
  config_uart.UART_Parity = UART_Parity_No;
  config_uart.UART_BaudRate = baudrate;
  config_uart.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
  config_uart.UART_Mode = UART_Mode_Tx_Rx;
  config_uart.UART_FIFO = UART_FIFO_Enable;
  config_uart.UART_TxFIFOLevel = UART_FIFOLevel_1_2;
  config_uart.UART_RxFIFOLevel = UART_FIFOLevel_1_2;
  UART_Init(UARTS[port], &config_uart);

// Enable UART

  UART_Cmd(UARTS[port], ENABLE);
  return 0;
}
Ejemplo n.º 16
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main()
{
    //uint8_t tx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    //uint8_t rx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    //uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x11, 0x22, 0x33};
    //uint8_t src_addr[4] = {192, 168,  0,  80};
    //uint8_t gw_addr[4]  = {192, 168,  0,  1};
    //uint8_t sub_addr[4] = {255, 255, 255,  0};
    //uint8_t dns_server[4] = {8, 8, 8, 8};           // for Example domain name server
    //uint8_t tmp[8];
	//int ret;

    /* External Clock */
    CRG_PLL_InputFrequencySelect(CRG_OCLK);

    /* Set System init */
    SystemInit();

    /* UART Init */
    UART_StructInit(&UART_InitStructure);
    UART_Init(UART_DEBUG,&UART_InitStructure);

    /* SysTick_Config */
    SysTick_Config((GetSystemClock()/1000));

    /* Set WZ_100US Register */
    setTIC100US((GetSystemClock()/10000));
    //getTIC100US();	
    //printf(" GetSystemClock: %X, getTIC100US: %X, (%X) \r\n", 
    //      GetSystemClock, getTIC100US(), *(uint32_t *)TIC100US);        

	LED_Init(LED1);
	LED_Init(LED2);

	LED_On(LED1);
	LED_Off(LED2);

	BOOT_Pin_Init();

	/* Load Configure Information */
	load_S2E_Packet_from_storage();
	UART_Configuration();

	/* Check MAC Address */
	check_mac_address();

	Timer0_Configuration();

#ifdef _MAIN_DEBUG_
	uint8_t tmpstr[6] = {0,};

	ctlwizchip(CW_GET_ID,(void*)tmpstr);
    printf("\r\n============================================\r\n");
	printf(" WIZnet %s EVB Demo v%d.%.2d\r\n", tmpstr, VER_H, VER_L);
	printf("============================================\r\n");
	printf(" WIZwiki Platform based TFTP App Example\r\n");
	printf("============================================\r\n");
#endif

#ifdef __DEF_USED_IC101AG__ //For using IC+101AG
    *(volatile uint32_t *)(0x41003068) = 0x64; //TXD0 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x4100306C) = 0x64; //TXD1 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003070) = 0x64; //TXD2 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003074) = 0x64; //TXD3 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003050) = 0x64; //TXE  - set PAD strengh and pull-up
#endif

#ifdef __DEF_USED_MDIO__ 
    /* mdio Init */
    mdio_init(GPIOB, MDC, MDIO );
    /* PHY Link Check via gpio mdio */
    while( link() == 0x0 )
    {
        printf(".");  
        delay(500);
    }
    printf("PHY is linked. \r\n");  
#else
    delay(1000);
    delay(1000);
#endif

#if 0
    /* Network Configuration */
    setSHAR(mac_addr);
    setSIPR(src_addr);
    setGAR(gw_addr);
    setSUBR(sub_addr);

    getSHAR(tmp);
    printf("MAC ADDRESS : %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\r\n",tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]);
    getSIPR(tmp);
    printf("IP ADDRESS : %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
    getGAR(tmp);
    printf("GW ADDRESS : %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
    getSUBR(tmp);
    printf("SN MASK: %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 

    /* Set Network Configuration */
    //wizchip_init(tx_size, rx_size);
#else
	Net_Conf();
#endif

	//TFTP_init(SOCK_TFTP, socket_buf);

	while (1) {
		if(g_op_mode == NORMAL_MODE) {
			do_udp_config(SOCK_CONFIG);
		} else {
			if(TFTP_run() != TFTP_PROGRESS)
				g_op_mode = NORMAL_MODE;
		}
	}

    return 0;
}
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main()
{
    //uint8_t tx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    //uint8_t rx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x11, 0x22, 0x34};
    uint8_t src_addr[4] = {192, 168,  0,  80};
    uint8_t gw_addr[4]  = {192, 168,  0,  1};
    uint8_t sub_addr[4] = {255, 255, 255,  0};		
    //uint8_t dns_server[4] = {8, 8, 8, 8};           // for Example domain name server
    uint8_t tmp[8];
#if LOOPBACK_MODE == LOOPBACK_MAIN_NOBLOCK
    int ret;
    uint8_t sn;
#if defined(TEST_TCPC)
    int32_t loopback_ret;
    struct sockaddr_in sa;
    uint32_t s_addr;
#endif
#endif

    // For TCP client loopback examples; destination network info
    //uint8_t destip[4] = {192, 168, 0, 2};
    //uint16_t destport = 5000;
    //int32_t loopback_ret;

    /* External Clock */
    CRG_PLL_InputFrequencySelect(CRG_OCLK);

    /* Set Systme init */
    SystemInit();

    /* UART Init */
    UART_StructInit(&UART_InitStructure);
    UART_Init(UART1,&UART_InitStructure);

    /* SysTick_Config */
    SysTick_Config((GetSystemClock()/1000));

    /* Set WZ_100US Register */
    setTIC100US((GetSystemClock()/10000));
    //getTIC100US();	
    //printf(" GetSystemClock: %X, getTIC100US: %X, (%X) \r\n", 
    //      GetSystemClock, getTIC100US(), *(uint32_t *)TIC100US);        

#ifdef _MAIN_DEBUG_
	uint8_t tmpstr[6] = {0,};

	ctlwizchip(CW_GET_ID,(void*)tmpstr);
    printf("\r\n============================================\r\n");
	printf(" WIZnet %s EVB Demo v%d.%.2d\r\n", tmpstr, VER_H, VER_L);
	printf("============================================\r\n");
	printf(" WIZwiki Platform based Loopback Example\r\n");
	printf("============================================\r\n");
#endif

#ifdef __DEF_USED_IC101AG__ //For using IC+101AG
    *(volatile uint32_t *)(0x41003068) = 0x64; //TXD0 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x4100306C) = 0x64; //TXD1 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003070) = 0x64; //TXD2 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003074) = 0x64; //TXD3 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003050) = 0x64; //TXE  - set PAD strengh and pull-up
#endif

#ifdef __DEF_USED_MDIO__ 
    /* mdio Init */
    mdio_init(GPIOB, MDC, MDIO );
    /* PHY Link Check via gpio mdio */
    while( link() == 0x0 )
    {
        printf(".");  
        delay(500);
    }
    printf("PHY is linked. \r\n");  
#else
    delay(1000);
    delay(1000);
#endif

    /* Network Configuration */
    setSHAR(mac_addr);
    setSIPR(src_addr);
    setGAR(gw_addr);
    setSUBR(sub_addr);

    getSHAR(tmp);
    printf("MAC ADDRESS : %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\r\n",tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]);
    getSIPR(tmp);
    printf("IP ADDRESS : %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
    getGAR(tmp);
    printf("GW ADDRESS : %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
    getSUBR(tmp);
    printf("SN MASK: %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 

    /* Set Network Configuration */
    //wizchip_init(tx_size, rx_size);

#if LOOPBACK_MODE == LOOPBACK_MAIN_NOBLOCK
#if defined(TEST_TCPS) || defined(TEST_TCPC)
	ret = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
#elif defined(TEST_UDPS)
    ret = socket(AF_INET, SOCK_STREAM, IPPROTO_UDP);
#endif
#if defined(TEST_TCPC)
    memset(&sa, 0, sizeof(sa));
    sa.sin_len = (uint16_t)sizeof(sa);
    sa.sin_family = AF_INET;
    sa.sin_port = htons(destport);
    s_addr = (((((destip[0] << 8) | destip[1]) << 8) | destip[2]) << 8) | destip[3];
    sa.sin_addr.s_addr = htonl(s_addr);
#endif

    if(ret == -1)
    {
#ifdef _LOOPBACK_DEBUG_
        printf("%d:Socket Error\r\n", ret);
#endif
        return ret;
    }
    sn = ret;
#endif

    while(1)
    {
		/* Loopback Test: TCP Server and UDP */
#if LOOPBACK_MODE == LOOPBACK_MAIN_NOBLOCK
#if defined(TEST_TCPS)
			loopback_tcps_bsd(sn, gDATABUF, TEST_PORT);
#elif defined(TEST_UDPS)
			loopback_udps_bsd(sn, gDATABUF, TEST_PORT);
#elif defined(TEST_TCPC)
			loopback_ret = loopback_tcpc_bsd(sn, gDATABUF, (struct sockaddr*)&sa);
			if(loopback_ret < 0) printf("loopback ret: %ld\r\n", loopback_ret); // TCP Socket Error code
#endif
#elif LOOPBACK_MODE == LOOPBACK_MAIN_SAMPLE
#if defined(TEST_TCPS)
			loopback_tcps_bsd(test_buf);
#elif defined(TEST_TCPC)
			loopback_tcpc_bsd(test_buf);
#endif
#endif
    }

}
Ejemplo n.º 18
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main()
{
    //uint8_t tx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    //uint8_t rx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    //uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x11, 0x22, 0x33};
    //uint8_t src_addr[4] = {192, 168,  0,  80};
    //uint8_t gw_addr[4]  = {192, 168,  0,  1};
    //uint8_t sub_addr[4] = {255, 255, 255,  0};
    //uint8_t dns_server[4] = {8, 8, 8, 8};           // for Example domain name server
    //uint8_t tmp[8];
	//int ret;
	int i;
#if defined (_MAIN_DEBUG_) && defined (_USE_SDCARD_)
	int ret;
#endif
#if defined(F_APP_FTP)
	wiz_NetInfo gWIZNETINFO;
#endif
#if defined(F_APP_DHCP) || defined(F_APP_DNS)
	S2E_Packet *value = get_S2E_Packet_pointer();
#endif
#if defined(F_APP_DNS)
	uint8_t dns_server_ip[4];
#endif

    /* External Clock */
    CRG_PLL_InputFrequencySelect(CRG_OCLK);

    /* Set System init */
    SystemInit();

    /* UART Init */
    UART_StructInit(&UART_InitStructure);
    UART_Init(UART_DEBUG,&UART_InitStructure);

    /* SysTick_Config */
    SysTick_Config((GetSystemClock()/1000));

    /* Set WZ_100US Register */
    setTIC100US((GetSystemClock()/10000));
    //getTIC100US();	
    //printf(" GetSystemClock: %X, getTIC100US: %X, (%X) \r\n", 
    //      GetSystemClock, getTIC100US(), *(uint32_t *)TIC100US);        

	LED_Init(LED1);
	LED_Init(LED2);
	LED_Init(LED3);

	LED_Off(LED1);
	LED_Off(LED2);
	LED_Off(LED3);

	g_sdcard_done = 0;

	BOOT_Pin_Init();
	Board_factory_Init();
	EXTI_Configuration();

	/* Load Configure Information */
	load_S2E_Packet_from_storage();
	UART_Configuration();

	/* Check MAC Address */
	check_mac_address();

	Timer0_Configuration();

    // ADC initialize
    ADC_Init();

#ifdef _MAIN_DEBUG_
	uint8_t tmpstr[6] = {0,};

	ctlwizchip(CW_GET_ID,(void*)tmpstr);
    printf("\r\n============================================\r\n");
	printf(" WIZnet %s EVB Demo v%d.%.2d\r\n", tmpstr, VER_H, VER_L);
	printf("============================================\r\n");
	printf(" WIZwiki Platform based WEBBoot Example\r\n");
	printf("============================================\r\n");
#endif

#ifdef __DEF_USED_IC101AG__ //For using IC+101AG
    *(volatile uint32_t *)(0x41003068) = 0x64; //TXD0 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x4100306C) = 0x64; //TXD1 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003070) = 0x64; //TXD2 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003074) = 0x64; //TXD3 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003050) = 0x64; //TXE  - set PAD strengh and pull-up
#endif

#ifdef __DEF_USED_MDIO__ 
    /* mdio Init */
    mdio_init(GPIOB, MDC, MDIO );
    /* PHY Link Check via gpio mdio */
    while( link() == 0x0 )
    {
        printf(".");  
        delay(500);
    }
    printf("PHY is linked. \r\n");  
#else
    delay(1000);
    delay(1000);
#endif

	Mac_Conf();
#if defined(F_APP_DHCP)
	if(value->options.dhcp_use)		// DHCP
	{
		uint32_t ret;
		uint8_t dhcp_retry = 0;

#ifdef _MAIN_DEBUG_
		printf(" - DHCP Client running\r\n");
#endif

		DHCP_init(SOCK_DHCP, TX_BUF);
		reg_dhcp_cbfunc(w5500_dhcp_assign, w5500_dhcp_assign, w5500_dhcp_conflict);

		while(1)
		{
			ret = DHCP_run();

			if(ret == DHCP_IP_LEASED)
			{
#ifdef _MAIN_DEBUG_
				printf(" - DHCP Success: DHCP Leased time : %ld Sec.\r\n\r\n", getDHCPLeasetime());
#endif
				break;
			}
			else if(ret == DHCP_FAILED)
			{
				dhcp_retry++;
#ifdef _MAIN_DEBUG_
				if(dhcp_retry <= 3) printf(" - DHCP Timeout occurred and retry [%d]\r\n", dhcp_retry);
#endif
			}

			if(dhcp_retry > 3)
			{
#ifdef _MAIN_DEBUG_
				printf(" - DHCP Failed\r\n\r\n");
#endif
				value->options.dhcp_use = 0;
				Net_Conf();
				break;
			}

			do_udp_config(SOCK_CONFIG);
		}
	}
	else 								// Static
	{
		Net_Conf();
	}
#else
	Net_Conf();
#endif

#ifdef _MAIN_DEBUG_
	display_Net_Info();
#endif

#if defined(F_APP_ATC)
	atc_init(&rxring, &txring);

	op_mode = OP_DATA;
#endif

	TFTP_init(SOCK_TFTP, socket_buf);

	ret = application_update();

    printf("[DEBUG] check trigger:%d ret:%d \r\n", get_bootpin_Status(), ret);
	if((get_bootpin_Status() == 1) && (ret != TFTP_FAIL)) {
		uint32_t tmp;

#if !defined(MULTIFLASH_ENABLE)
		tmp = *(volatile uint32_t *)APP_BASE;
#else
		tmp = *(volatile uint32_t *)flash.flash_app_base;
#endif

		if((tmp & 0xffffffff) != 0xffffffff) {
		    printf("[DEBUG] application_jump\r\n");
			application_jump();
		}
	}

#ifdef _USE_SDCARD_
	// SD card Initialization
	ret = mmc_mount();
	if(ret <= 0)
	{
#ifdef _MAIN_DEBUG_
		printf("\r\n - Can't mount SD card: Please Reboot WIZ750WEB Board or Insert SD card\r\n");
#endif
		//while(!(ret = mmc_mount()));
	}

	if(ret > 0)
	{
#ifdef _MAIN_DEBUG_
		display_SDcard_Info(ret);
#endif
	}
#endif

	httpServer_init(TX_BUF, RX_BUF, MAX_HTTPSOCK, socknumlist);
#ifdef _USE_WATCHDOG_
	reg_httpServer_cbfunc(NVIC_SystemReset, IWDG_ReloadCounter); // Callback: STM32 MCU Reset / WDT Reset (IWDG)
#else
	reg_httpServer_cbfunc(NVIC_SystemReset, NULL); // Callback: STM32 MCU Reset
#endif
	IO_status_init();

#if defined(F_APP_FTP)
	ctlnetwork(CN_GET_NETINFO, (void*) &gWIZNETINFO);
	ftpd_init(gWIZNETINFO.ip);	// Added by James for FTP
#endif

#ifdef _USE_WATCHDOG_
	// IWDG Initialization: STM32 Independent WatchDog
	IWDG_Configureation();
#endif

	while (1) {
#ifdef _USE_WATCHDOG_
		IWDG_ReloadCounter(); // Feed IWDG
#endif

#if defined(F_APP_ATC)
		atc_run();
#endif
		
		if(g_op_mode == NORMAL_MODE) {
			do_udp_config(SOCK_CONFIG);
		} else {
			if(TFTP_run() != TFTP_PROGRESS)
				g_op_mode = NORMAL_MODE;
		}

#if defined(F_APP_DHCP)
		if(value->options.dhcp_use)
			DHCP_run();
#endif

		for(i = 0; i < MAX_HTTPSOCK; i++)	httpServer_run(i);	// HTTP server handler

#if defined(F_APP_FTP)
		ftpd_run(FTP_DBUF);
#endif

#ifdef _USE_WATCHDOG_
		IWDG_ReloadCounter(); // Feed IWDG
#endif

	}

    return 0;
}
Ejemplo n.º 19
0
Archivo: main.c Proyecto: Wiznet/W7500P
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main()
{
    //uint8_t tx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    //uint8_t rx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x01, 0x02, 0x03}; 
    uint8_t src_addr[4] = {192, 168,  0,  9};
    uint8_t gw_addr[4]  = {192, 168,  0,  1};
    uint8_t sub_addr[4] = {255, 255, 255,  0};		
    //uint8_t dns_server[4] = {8, 8, 8, 8};           // for Example domain name server
    uint8_t tmp[8];
		
		int32_t ret;
		uint16_t port=5000, size = 0, sentsize=0;
		uint8_t destip[4];
		uint16_t destport;

		*(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz
		
		/* External Clock */
    //CRG_PLL_InputFrequencySelect(CRG_OCLK);

    /* Set Systme init */
    SystemInit();
		
		SSP0_Initialize();
		SSP1_Initialize();
		GPIO_Initialize();	

		GPIO_SetBits(GPIOC, GPIO_Pin_8); // LED red off
		GPIO_SetBits(GPIOC, GPIO_Pin_9); // LED green off
		GPIO_ResetBits(GPIOC, GPIO_Pin_6); // Test off

    /* UART Init */
    UART_StructInit(&UART_InitStructure);
    UART_Init(UART1,&UART_InitStructure);

    /* SysTick_Config */
    SysTick_Config((GetSystemClock()/1000));

    /* Set WZ_100US Register */
    setTIC100US((GetSystemClock()/10000));
    //getTIC100US();	
    //printf(" GetSystemClock: %X, getTIC100US: %X, (%X) \r\n", 
    //      GetSystemClock, getTIC100US(), *(uint32_t *)TIC100US);        


#ifdef __DEF_USED_IC101AG__ //For using IC+101AG
    *(volatile uint32_t *)(0x41003068) = 0x64; //TXD0 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x4100306C) = 0x64; //TXD1 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003070) = 0x64; //TXD2 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003074) = 0x64; //TXD3 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003050) = 0x64; //TXE  - set PAD strengh and pull-up
#endif	
    printf("PHY is linked. \r\n"); 
#ifdef __DEF_USED_MDIO__ 
    /* mdio Init */
    mdio_init(GPIOB, MDC, MDIO );
    //mdio_error_check(GPIOB, MDC, MDIO); //need verify...
    /* PHY Link Check via gpio mdio */
    while( link() == 0x0 )
    {
        printf(".");  
        delay(500);
    }
    printf("PHY is linked. \r\n");  
#else
    delay(1000);
    delay(1000);
#endif

    /* Network Configuration */
    setSHAR(mac_addr);
    setSIPR(src_addr);
    setGAR(gw_addr);
    setSUBR(sub_addr);

    getSHAR(tmp);
    printf(" MAC ADDRESS : %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\r\n",tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]); 
    getSIPR(tmp);
    printf("IP ADDRESS : %d.%d.%d.%d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
    getGAR(tmp);
    printf("GW ADDRESS : %d.%d.%d.%d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
    getSUBR(tmp);
    printf("SN MASK: %d.%d.%d.%d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
   
    /* Set Network Configuration */
    //wizchip_init(tx_size, rx_size);

    printf(" TEST- START \r\n");  
		
    while(1)
    {
        switch(getSn_SR(SOCK_NUM))
				{
					case SOCK_ESTABLISHED:
					if(getSn_IR(SOCK_NUM) & Sn_IR_CON)
					{
						getSn_DIPR(SOCK_NUM, destip);
						destport = getSn_DPORT(SOCK_NUM);
						printf("%d:Connected - %d.%d.%d.%d : %d\r\n",SOCK_NUM, destip[0], destip[1], destip[2], destip[3], destport);
						setSn_IR(SOCK_NUM,Sn_IR_CON);
					}
					if((size = getSn_RX_RSR(SOCK_NUM)) > 0) // Don't need to check SOCKERR_BUSY because it doesn't not occur.
					{
						if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
						ret = recv(SOCK_NUM, test_buf, size);

						if(ret <= 0) return ret;      // check SOCKERR_BUSY & SOCKERR_XXX. For showing the occurrence of SOCKERR_BUSY.
						
						 /* Send only data to SSP1 */ 
						for (TxIdx=0; TxIdx<size; TxIdx++)
						{
							SSP_SendData(SSP0, test_buf[TxIdx]);
							while( SSP_GetFlagStatus(SSP0, SSP_FLAG_BSY) );
						}
						
						/* Receive only data from SSP0 */
						while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RNE))
						{
							SSP1_Buffer_Rx[RxIdx] = SSP_ReceiveData(SSP1);
							RxIdx++;
						} 
						RxIdx=0;
						
						sentsize = 0;

						while(size != sentsize)
						{
							ret = send(SOCK_NUM, SSP1_Buffer_Rx+sentsize, size-sentsize);
							if(ret < 0)
							{
								close(SOCK_NUM);
								return ret;
							}
							sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
						}
					}
						break;
					case SOCK_CLOSE_WAIT:
						printf("%d:CloseWait\r\n",SOCK_NUM);
						if((ret = disconnect(SOCK_NUM)) != SOCK_OK) return ret;
						printf("%d:Socket Closed\r\n", SOCK_NUM);

						break;
					case SOCK_INIT:
						printf("%d:Listen, TCP server loopback, port [%d]\r\n", SOCK_NUM, port);
						if( (ret = listen(SOCK_NUM)) != SOCK_OK) return ret;
						break;
					
					case SOCK_CLOSED:
						
						printf("%d:TCP server loopback start\r\n",SOCK_NUM);
						if((ret = socket(SOCK_NUM, Sn_MR_TCP, port, 0x00)) != SOCK_NUM) return ret;
						printf("%d:Socket opened\r\n",SOCK_NUM);
					
						break;
					
					default:
						break;
					
				}
    }

}
Ejemplo n.º 20
0
/**
 * @brief   Main program
 * @param  None
 * @retval None
 */
int main()
{
    //uint8_t tx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    //uint8_t rx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x71, 0x72, 0x77}; 
    uint8_t src_addr[4] = {192, 168,  77,  9};
    uint8_t gw_addr[4]  = {192, 168,  77,  1};
    uint8_t sub_addr[4] = {255, 255, 255,  0};	
		uint8_t Domain_name[] = "www.google.com";    // for example domain name
    uint8_t dns_server[4] = {8, 8, 8, 8};           // for Example domain name server
		uint8_t Domain_IP[4] = {0, 0, 0, 0};           // for Example domain name server
    uint8_t tmp[8];
    uint32_t toggle = 1;

    /* External Clock */
    //CRG_PLL_InputFrequencySelect(CRG_OCLK);

    /* Set Systme init */
    SystemInit();

    /* UART Init */
    UART_StructInit(&UART_InitStructure);
    UART_Init(UART1,&UART_InitStructure);

    /* SysTick_Config */
    SysTick_Config((GetSystemClock()/1000));

    /* Set WZ_100US Register */
    setTIC100US((GetSystemClock()/10000));
    //getTIC100US();	
    //printf(" GetSystemClock: %X, getTIC100US: %X, (%X) \r\n", 
    //      GetSystemClock, getTIC100US(), *(uint32_t *)TIC100US);        


#ifdef __DEF_USED_IC101AG__ //For using IC+101AG
    *(volatile uint32_t *)(0x41003068) = 0x64; //TXD0 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x4100306C) = 0x64; //TXD1 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003070) = 0x64; //TXD2 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003074) = 0x64; //TXD3 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003050) = 0x64; //TXE  - set PAD strengh and pull-up
#endif	

#ifdef __DEF_USED_MDIO__ 
    /* mdio Init */
    mdio_init(GPIOB, MDC, MDIO );
    /* PHY Link Check via gpio mdio */
    while( link() == 0x0 )
    {
        printf(".");  
        delay(500);
    }
    printf("PHY is linked. \r\n");  
#else
    delay(1000);
#endif

    /* Network Configuration (Default setting) */
    setSHAR(mac_addr);
    setSIPR(src_addr);
    setGAR(gw_addr);
    setSUBR(sub_addr);

    getSHAR(tmp);	printf("MAC ADDRESS : %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\r\n",tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]); 
    getSIPR(tmp); printf("IP ADDRESS : %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
    getGAR(tmp);  printf("GW ADDRESS : %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
    getSUBR(tmp); printf("SN MASK: %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 

    /* Set Network Configuration */
    //wizchip_init(tx_size, rx_size);
			
    /* DHCP client Initialization */
    DHCP_init(SOCK_DHCP, test_buf);
    /* DHCP IP allocation and check the DHCP lease time (for IP renewal) */
    while(1)
    {
        switch(DHCP_run())
        {
            case DHCP_IP_ASSIGN:
            case DHCP_IP_CHANGED:
                /* If this block empty, act with default_ip_assign & default_ip_update  */
                //
                // This example calls the registered 'my_ip_assign' in the two case.
                //
                // Add to ...
                //
                //
                break;
            case DHCP_IP_LEASED:
                //
                if(toggle)
                {
                    getGAR(tmp);  printf("> DHCP GW : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]);
                    getSUBR(tmp); printf("> DHCP SN : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]);
                    getSIPR(tmp); printf("> DHCP IP : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]);
                    toggle = 0;
                }  
                // TO DO YOUR NETWORK APPs.
								// 
								/* DNS client initialization */
								DNS_init(SOCK_DNS, test_buf);
								if(DNS_run(dns_server, Domain_name, Domain_IP))
								{
									printf("> Translated %s to %d.%d.%d.%d\r\n",Domain_name,Domain_IP[0],Domain_IP[1],Domain_IP[2],Domain_IP[3]);
								}
								else
								{
									printf("> DNS Failed\r\n");
								}
								delay(1000);
								
                break;

            case DHCP_FAILED:
                /* ===== Example pseudo code =====  */
                // The below code can be replaced your code or omitted.
                // if omitted, retry to process DHCP
                my_dhcp_retry++;
                if(my_dhcp_retry > MY_MAX_DHCP_RETRY)
                {
#if DEBUG_MODE != DEBUG_NO
                    printf(">> DHCP %d Failed\r\n",my_dhcp_retry);
#endif
                    my_dhcp_retry = 0;
                    DHCP_stop();      // if restart, recall DHCP_init()
                }
                break;
            default:
                break;
        }	


    }

}