示例#1
0
/**
  * @brief  Configures the USART1 to talk to the RN42, and sets it up. Note that this should only be used to configure new modules!
  * @param  None
  * @retval None
  */
void RN42_conf(void) {
	USART_InitTypeDef   USART_InitStructure;
	//Wait for buffer to empty
	while(anything_in_buff(&Usart1_tx_buff))
		__WFI();
	USART_Cmd(USART1_USART, DISABLE);
	USART_DeInit(USART1_USART);
	//Set the config for default RN42 settings
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;
	USART_InitStructure.USART_StopBits = USART_StopBits_1;
	USART_InitStructure.USART_Parity = USART_Parity_No;
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
	USART_InitStructure.USART_BaudRate  = USART1_BAUD;//use the default
	USART_Init(USART1_USART, &USART_InitStructure );
	USART_Cmd(USART1_USART, ENABLE);
	Usart_Send_Str((char*)"$$$");Delay(150000);
	Usart_Send_Str((char*)"$$$");Delay(150000);
	Usart_Send_Str((char*)"\nD\n");Delay(150000);
	Usart_Send_Str((char*)"SH,0000\n");Delay(100000);
	Usart_Send_Str((char*)"S~,0\n");Delay(100000);
	Usart_Send_Str((char*)"SL,E\n");Delay(100000);
	Usart_Send_Str((char*)"R,1\n");	//causes the setting to take effect
	//Wait for buffer to empty
	while(anything_in_buff(&Usart1_tx_buff))
		__WFI();
	USART_InitStructure.USART_WordLength = USART_WordLength_9b;
	USART_InitStructure.USART_Parity = USART_Parity_Even;
	USART_Cmd(USART1_USART, DISABLE);
	USART_DeInit(USART1_USART);
	USART_Init(USART1_USART, &USART_InitStructure );//now the module should be configured
	USART_Cmd(USART1_USART, ENABLE);
}
示例#2
0
void UartMcuInit( Uart_t *obj, uint8_t uartId, PinNames tx, PinNames rx )
{
    obj->UartId = uartId;

    switch ( obj->UartId )
    {
    case UART_1:
        RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1, ENABLE );

        USART_DeInit( USART1 );

        GpioInit( &obj->Tx, tx, PIN_ALTERNATE_FCT, PIN_PUSH_PULL, PIN_PULL_UP, 1 );
        GpioInit( &obj->Rx, rx, PIN_ALTERNATE_FCT, PIN_PUSH_PULL, PIN_PULL_UP, 1 );

        GPIO_PinAFConfig( obj->Tx.port, ( obj->Tx.pin & 0x0F ), GPIO_AF_USART1 );
        GPIO_PinAFConfig( obj->Rx.port, ( obj->Rx.pin & 0x0F ), GPIO_AF_USART1 );
        break;
    case UART_2:
        RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2, ENABLE );

        USART_DeInit( USART2 );

        GpioInit( &obj->Tx, tx, PIN_ALTERNATE_FCT, PIN_PUSH_PULL, PIN_PULL_UP, 1 );
        GpioInit( &obj->Rx, rx, PIN_ALTERNATE_FCT, PIN_PUSH_PULL, PIN_PULL_UP, 1 );

        GPIO_PinAFConfig( obj->Tx.port, ( obj->Tx.pin & 0x0F ), GPIO_AF_USART2 );
        GPIO_PinAFConfig( obj->Rx.port, ( obj->Rx.pin & 0x0F ), GPIO_AF_USART2 );
        break;
    }
}
示例#3
0
/*******************************************************************************
 * 名    称: IAP_DevDeInit()
 * 功    能: 设备恢复默认值
 * 入口参数:
 * 出口参数: 无
 * 作   者: 无名沈
 * 创建日期: 2014-04-23
 * 修    改: 
 * 修改日期: 
 *******************************************************************************/
void IAP_DevDeInit(void)
{    
    /***********************************************
    * 描述: 端口恢复默认
    */
    GPIO_DeInit(GPIOA);
    GPIO_DeInit(GPIOB);
    GPIO_DeInit(GPIOC);
    GPIO_DeInit(GPIOD);
    GPIO_DeInit(GPIOE);
    
    /***********************************************
    * 描述: 串口恢复默认
    */
    USART_DeInit(USART1);
    USART_DeInit(USART2);
    USART_DeInit(USART3);
        
    /***********************************************
    * 描述: 定时器恢复默认
    */
    TIM_DeInit(TIM1);
    TIM_DeInit(TIM2);
    TIM_DeInit(TIM2);
    TIM_DeInit(TIM3);
    TIM_DeInit(TIM4);
    TIM_DeInit(TIM5);
    TIM_DeInit(TIM6);
    TIM_DeInit(TIM7);
    TIM_DeInit(TIM8);
}
示例#4
0
void Usart_Configuration(void)
{
	USART_InitTypeDef USART_InitStruct;

	UsartRcc_Configuration();
	UsartGPIO_Configuration();
	NVIC_Configuration();
	USART_DeInit(USART1);
	USART_DeInit(USART2);

	USART_InitStruct.USART_BaudRate = 9600;
	USART_InitStruct.USART_StopBits = USART_StopBits_1;
	USART_InitStruct.USART_WordLength = USART_WordLength_9b;
	USART_InitStruct.USART_Parity = USART_Parity_Odd;
	USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
	
	USART_Init(USART1, &USART_InitStruct); 		 
	USART_ClearFlag(USART1,USART_FLAG_TC);
	USART_Cmd(USART1, ENABLE);	
		

	USART_Init(USART2, &USART_InitStruct);	
	USART_ClearFlag(USART2,USART_FLAG_TC);
	USART_Cmd(USART2, ENABLE);
}
示例#5
0
文件: usart_1.c 项目: jfazli/PE208
//-----------------------------------------------------------------
//   USART 1 initialization
//   USART 1 on ev board Corresponds to USART 1(1 of 1~3) of MCU
//-----------------------------------------------------------------
void USARTA_Test_Init(u8 i)
{
  USART_InitTypeDef USART_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

  // USART1 IO configuration ------------------------------------//
  // Enable GPIOA clock
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

  // Set PA9/PA10 as PP AF - USART_TXD,RXD
  GPIO_InitStructure.GPIO_Pin = USARTATX_PIN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_Init(USARTATX_PORT, &GPIO_InitStructure);
  
  GPIO_InitStructure.GPIO_Pin = USARTARX_PIN;  
  GPIO_Init(USARTARX_PORT, &GPIO_InitStructure);
  // SET PA9/PA10 for USART
  GPIO_PinAFConfig(USARTATX_PORT, GPIO_PinSource9, GPIO_AF_USART1);
  GPIO_PinAFConfig(USARTARX_PORT, GPIO_PinSource10,GPIO_AF_USART1);

  // DeInit USART
  USART_DeInit(USART_A);
  // USART configuration --------------------------------------//
  // USART configured as follow:
  //      - BaudRate = 115200 or other baud  
  //      - Word Length = 8 Bits
  //      - 1 Stop Bit
  //      - No parity
  //      - Hardware flow control disabled (RTS and CTS signals)
  //      - Receive and transmit enabled
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
  // de-init USART1 to avoid the impact of USART3_IrDA
  USART_DeInit(USART1);
  
  Usart_Baud = USART_BAUD[i % (sizeof(USART_BAUD)/sizeof(u32))];
  USART_InitStructure.USART_BaudRate = Usart_Baud;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;// DANA change
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  USART_Init(USART_A, &USART_InitStructure);

  // Enable USART_A
  USART_Cmd(USART_A, ENABLE);
  // short delay seems mandatory before sending 1st byte
//  delay_10us(10);
}
示例#6
0
void goSleep(void) {
  TM_RTC_Interrupts(TM_RTC_Int_Disable);
  TM_USART_Puts(MENU_USART,"Going to sleep state now!\n\r");
  USART_DeInit(MENU_USART);
  USART_DeInit(GSM_USART);
  USART_DeInit(GPS_USART);
  I2C_DeInit(I2C3);
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE, DISABLE);
  TM_RTC_Interrupts(TM_RTC_Int_1s); // 500ms;1,2,5,10,15,30,60 seconds to choose from
  TM_LOWPOWER_Standby();
  //TM_LOWPOWER_StopUntilInterrupt();
  //TM_LOWPOWER_SleepUntilInterrupt(1);
  //TM_LOWPOWER_EnableWakeUpPin();
}
示例#7
0
文件: uart.c 项目: azermert/pto38team
bool init_UART(UART_DESC * _urt, u8 _usartNumber){

	USART_InitTypeDef USART_InitStruct;
	_urt->usart_No = _usartNumber;
	
	USART_StructInit(&USART_InitStruct);	 	//8bit, parity_none, stopbit_1 ..

	switch(_urt->usart_No){
		case 2:
			USART_InitStruct.USART_BaudRate = 115200;
			RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
			_urt->usartBase = (USART_TypeDef*)USART2_BASE;
			uartRegister[2] = _urt;
			break;
		default:
			return FALSE;	
	}

	USART_DeInit(_urt->usartBase);
	USART_Init(_urt->usartBase, &USART_InitStruct);

	init_Comm(&_urt->parent);

	_urt->Tick = _urt->parent.Tick;
	_urt->parent.Tick = &UART_Tick;

	USART_ITConfig(_urt->usartBase, USART_IT_RXNE, ENABLE);
	NVIC_IntEnable(USART2_IRQn,0x02);

	initHW_UART(_urt);
	USART_Cmd(_urt->usartBase, ENABLE);

	return TRUE;
}
示例#8
0
void UartInit(uint32 BaudRate)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
    /* Enable GPIO clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

    /* Configure USART Tx as alternate function push-pull */
    GPIO_InitStructure.GPIO_Pin =GPIO_Pin_9;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    //  /* Configure USART Rx as input floating */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    USART_DeInit(USART1);//复位USART1
    USART_InitStructure.USART_BaudRate = BaudRate;
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_Parity = USART_Parity_No;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructure.USART_Mode =   USART_Mode_Tx|USART_Mode_Rx;

    /* USART configuration */
    USART_Init(USART1, &USART_InitStructure);
    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //接收中断使能

    /* Enable USART */
    USART_Cmd(USART1, ENABLE);
}
示例#9
0
//
// Put any initialization code here
//
void consoleInit() {
	USART_InitTypeDef usartStruct;
	galvoInit();

	// Init Laser (as GPIO OUTPUT)
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
	GPIO_Init(GPIOD, &(GPIO_InitTypeDef){GPIO_Pin_8, GPIO_Mode_OUT, GPIO_OType_PP, GPIO_Speed_50MHz, GPIO_PuPd_NOPULL});
	GPIO_ResetBits(GPIOD, GPIO_Pin_8);

	// Init Serial
	// But don't set AF for pin until we turn the laser 'on'
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
	RCC_APB1PeriphClockLPModeCmd(RCC_APB1Periph_USART3, ENABLE);

	GPIO_PinAFConfig(GPIOD, GPIO_PinSource8 ,GPIO_AF_USART3);

	USART_DeInit(USART3);
	USART_StructInit(&usartStruct);

	usartStruct.USART_BaudRate = 4800;
	usartStruct.USART_Mode = USART_Mode_Tx;

	USART_Init(USART3, &usartStruct);

	USART_Cmd(USART3, ENABLE);
}
ElectronSerialPipe::~ElectronSerialPipe(void)
{
    // wait for transmission of outgoing data
    while (_pipeTx.readable())
    {
        char c = _pipeTx.getc();
        USART_SendData(USART3, c);
    }

    // Disable the USART
    USART_Cmd(USART3, DISABLE);

    // Deinitialise USART
    USART_DeInit(USART3);

    // Disable USART Receive and Transmit interrupts
    USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
    USART_ITConfig(USART3, USART_IT_TXE, DISABLE);

    NVIC_InitTypeDef NVIC_InitStructure;

    // Disable the USART Interrupt
    NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;

    NVIC_Init(&NVIC_InitStructure);

    // Disable USART Clock
    RCC->APB1ENR &= ~RCC_APB1Periph_USART3;

    // clear any received data
    // ... should be handled with ~Pipe deconstructor
}
示例#11
0
void BspUsart1Init(void)
{
    GPIO_InitTypeDef GpioInitdef;
    USART_InitTypeDef UsartInitdef;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE);  

    GpioInitdef.GPIO_Pin = GPIO_Pin_9; //
    GpioInitdef.GPIO_Speed = GPIO_Speed_10MHz;
    GpioInitdef.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOA, &GpioInitdef);

    GpioInitdef.GPIO_Pin = GPIO_Pin_10; //
    GpioInitdef.GPIO_Speed = GPIO_Speed_10MHz;
    GpioInitdef.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &GpioInitdef);    

    USART_DeInit(USART1);

    USART_StructInit(&UsartInitdef);
    UsartInitdef.USART_BaudRate = 115200;
    UsartInitdef.USART_StopBits = USART_StopBits_1;
    UsartInitdef.USART_WordLength = USART_WordLength_8b;
    UsartInitdef.USART_Parity = USART_Parity_No;

    UsartInitdef.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    USART_Init(USART1, &UsartInitdef);

    USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

    USART_Cmd(USART1, ENABLE);
}
示例#12
0
文件: spi.c 项目: jinshuhuai/nRF24L01
void usart1_init()
{
	//GPIO端口设置
	GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);	//使能USART1,GPIOA时钟
	USART_DeInit(USART1);  //复位串口1
	//USART1_TX   PA.9
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;	//复用推挽输出
	GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化PA9

	//USART1_RX	  PA.10
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
	GPIO_Init(GPIOA, &GPIO_InitStructure);  //初始化PA10

	//USART 初始化设置
	USART_InitStructure.USART_BaudRate = 9600;//一般设置为9600;
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
	USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
	USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;	//收发模式

	USART_Init(USART1, &USART_InitStructure); //初始化串口
	USART_Cmd(USART1, ENABLE);                    //使能串口 
}
示例#13
0
文件: uart.c 项目: 2thetop/anypixel
/**
 * Initialize a USART based on the passed configuration structure
 */
void UART_Config(CONFIG_USART_ConfigState *cfg) {
	USART_InitTypeDef USART_InitStructure;

	FIFO_InitStruct(cfg->rx_fifo, cfg->rx_buf, cfg->rx_buf_size);

	// turn on peripheral clocks
	RCC_AHBPeriphClockCmd(cfg->ahb1, ENABLE);
	RCC_APB1PeriphClockCmd(cfg->apb1, ENABLE);
	RCC_APB2PeriphClockCmd(cfg->apb2, ENABLE);

	// configure pins
	CONFIG_pins(cfg->pins, cfg->num_pins);

	// configure USART
	USART_DeInit(cfg->USARTx);
	USART_InitStructure.USART_BaudRate = cfg->baud;
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_Parity = USART_Parity_No;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
	USART_Init(cfg->USARTx, &USART_InitStructure);

	// enable RX interrupt
	//USART_ITConfig(cfg->USARTx, USART_IT_RXNE, ENABLE);

	// enable the USART
	USART_Cmd(cfg->USARTx, ENABLE);
	cfg->configured = true;
	cfg->configured = true;
	cfg->configured = true;
	cfg->configured = true;
}
示例#14
0
文件: uart1.c 项目: GaoMjun/balancer
void uart1_init(void)
{
    USART_DeInit(USART1);

		//Tx
  	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  	GPIO_Init(GPIOA, &GPIO_InitStructure);
	
		//Rx
  	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  	GPIO_Init(GPIOA, &GPIO_InitStructure);


    USART_InitStructure.USART_BaudRate = 115200;
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_Parity = USART_Parity_No;
		USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
		USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    
		USART_Init(USART1,&USART_InitStructure);
		USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
		//USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
		USART_Cmd(USART1, ENABLE);
}
示例#15
0
void USART_Configuration(USART_TypeDef* USART,u32 bps,u16 databit,u16 paritybit)
{
	USART_InitTypeDef USART_InitStructure;
	USART_ClockInitTypeDef USART_ClockInitStructure;
	
	USART_DeInit(USART);
 	if(USART==USART1)RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
	if(USART==USART2)RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
	if(USART==USART3)RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

	USART_InitStructure.USART_BaudRate            = bps;
	USART_InitStructure.USART_WordLength          = databit;
	USART_InitStructure.USART_StopBits            = USART_StopBits_1;
	USART_InitStructure.USART_Parity              = paritybit ;
	
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	USART_InitStructure.USART_Mode                = USART_Mode_Rx | USART_Mode_Tx;
	
	USART_ClockInitStructure.USART_Clock          = USART_Clock_Disable;
	USART_ClockInitStructure.USART_CPOL           = USART_CPOL_High;
	USART_ClockInitStructure.USART_CPHA           = USART_CPHA_2Edge;
	USART_ClockInitStructure.USART_LastBit        = USART_LastBit_Disable;
	
	USART_Init(USART, &USART_InitStructure);
	USART_ClockInit(USART, &USART_ClockInitStructure);
	if(USART==USART1){
		USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
		NVIC_Configuration(USART1_IRQChannel,0);
	}
	USART_Cmd(USART, ENABLE);
}
示例#16
0
/*
 * UART Config
 *
 * USART1_TX -> PB6
 * USART1_RX -> PB7
 */
void UART_init(){
    GPIO_InitTypeDef GPIO_InitStructure;

    /* GPIOD Periph clock enable */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

    /* Configure pins in output pushpull mode */
    GPIO_StructInit(&GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    // remap
    GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE);

    // configure UART
    USART_DeInit(USART1);
    USART_StructInit(&USART_InitStruct);
    USART_InitStruct.USART_BaudRate = 115200;
    USART_InitStruct.USART_Mode = (USART_Mode_Tx);
    //USART_InitStruct.USART_Mode = (USART_Mode_Tx | USART_Mode_Rx);
    USART_Init(USART1, &USART_InitStruct);

    // enable USART
    USART_Cmd(USART1, ENABLE);
}
示例#17
0
void init_SCI(USART_TypeDef* USARTx,
              uint32_t USART_BaudRate,
              uint16_t USART_WordLength,
              uint16_t USART_StopBits,
              uint16_t USART_Parity,
              uint16_t USART_Mode,
              uint16_t USART_HardwareFlowControl)
{
   static uint16_t usartDeInitFlag=0;

   USART_InitTypeDef USART_InitStructure; //setup UART_InitStructure
   USART_ClockInitTypeDef USART_ClockInitStructure; //setup UART_ClockInitStructure
   USART_ClockStructInit(&USART_ClockInitStructure);

   if (usartDeInitFlag==0)
   {
      USART_DeInit(USARTx); //Deinit USARTx
      usartDeInitFlag=1;
   }

   USART_InitStructure.USART_BaudRate = USART_BaudRate;
   USART_InitStructure.USART_WordLength = USART_WordLength;
   USART_InitStructure.USART_StopBits = USART_StopBits;
   USART_InitStructure.USART_Parity = USART_Parity;
   USART_InitStructure.USART_Mode = USART_Mode;
   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl;

   USART_Init(USARTx, &USART_InitStructure);

   USART_ClockInit(USARTx, &USART_ClockInitStructure);

   USART_Cmd(USARTx, ENABLE);
}
void UartMcuDeInit( Uart_t *obj )
{
    USART_DeInit( USART1 );

    GpioInit( &obj->Tx, obj->Tx.pin, PIN_ANALOGIC, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
    GpioInit( &obj->Rx, obj->Rx.pin, PIN_ANALOGIC, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
}
示例#19
0
文件: usart.c 项目: hsjia/DIY
void usart1_init(void){
	GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);	//ENABLE RCC_GPIOA AND RCC_AFIO
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;			//PA10 RX
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;			//PA9 TX
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);	//ENABLE RCC_USART1
	USART_DeInit(USART1);			//DEINIT USART1
	USART_InitStructure.USART_BaudRate = 38400;
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;
	USART_InitStructure.USART_StopBits = USART_StopBits_1;
	USART_InitStructure.USART_Parity = USART_Parity_No;
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	USART_Init(USART1, &USART_InitStructure);			//INIT USART1
	
	USART_SendData(USART1, (uint8_t) 0x00);				//FOR CLEAR TXE
	while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
	
	USART_Cmd(USART1, ENABLE);							//ENABLE USART1
	USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);
	USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);
	
	printf("USART1 INIT OK\r\n");
}
示例#20
0
文件: system.c 项目: art103/ar-t6
/**
  * @brief  calls Stm32F1xx on-chip bootloader for flashing
  * @param  None
  * @retval None - shall not ever return
  */
void enter_bootloader(void) {
	USART_DeInit(USART1);
	RCC_DeInit();
	SysTick->CTRL = 0;
	SysTick->LOAD = 0;
	SysTick->VAL = 0;

	__ASM volatile (
			"MOVS r4,#1\n"
			"MSR primask, r4\n"
			"LDR r4,=#0x1FFFF000\n"
			"LDR r3,[r4]\n"
			"MSR msp,r3\n"
			"LDR r3,[r4, #4]\n"
			"blx r3\n"
	);
	 // the above ASM does the same but is much shorter
	// and does not need core_cm3.c (for the __set_XXXX())
	#if 0
	__set_PRIMASK(1);
	// changing stack point would invalidate all local var on stack!
	#define SYSMEM ((uint32_t*)0x1FFFF000) /*specific to STM32F1xx*/
	register const uint32_t SP = SYSMEM[0];
	__set_MSP(SYSMEM[0]/*sp addr*/);
	register const uint32_t BL = SYSMEM[1];
	typedef void (*BLFUNC)();
	((BLFUNC)SYSMEM[1]/*bootloader addr*/)();
	#endif
}
示例#21
0
static void usart_init(u32 id, USART_InitTypeDef * initVals)
{
  /* Configure USART IO */
  GPIO_InitTypeDef GPIO_InitStructure;

  //Connect pin to USARTx_Tx
  GPIO_PinAFConfig(usart_gpio_tx_port[id], usart_gpio_tx_pin_source[id], stm32_usart_AF[id]);
  //Connect pin to USARTx_Rx
  GPIO_PinAFConfig(usart_gpio_rx_port[id], usart_gpio_rx_pin_source[id], stm32_usart_AF[id]);

  /* Configure USART Tx Pin as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = usart_gpio_tx_pin[id];
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //push pull or open drain
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //pull-up or pull-down
  GPIO_Init(usart_gpio_tx_port[id], &GPIO_InitStructure);

  /* Configure USART Rx Pin as input floating */
  GPIO_InitStructure.GPIO_Pin = usart_gpio_rx_pin[id];
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //pull-up or pull-down
  GPIO_Init(usart_gpio_rx_port[id], &GPIO_InitStructure);

  USART_DeInit(stm32_usart[id]);

  /* Configure USART */
  USART_Init(stm32_usart[id], initVals);

  /* Enable USART */
  USART_Cmd(stm32_usart[id], ENABLE);
  USART_ITConfig( stm32_usart[id], USART_IT_RXNE, ENABLE); // enable the USART1 receive int
}
示例#22
0
文件: uart.c 项目: edgardo87/lepton
/*******************************************************************************
* Function Name  : uart_close
* Description    : Close the USART port communication
* Input          : - Uart: Select the USART or the UART peripheral.
* Output         : None
* Return         : 0
*******************************************************************************/
int uart_close(const _Uart_Descriptor *Uart)
{
  /* Disable IT */
  NVIC_DisableIRQ(Uart->IRQn);

  /* Free control variables and buffers */
  if (*Uart->Ctrl)
  {
    if ((*Uart->Ctrl)->DmaBufSize)
    {
      USART_DMACmd(Uart->UARTx, USART_DMAReq_Rx, DISABLE);
      NVIC_DisableIRQ(Uart->DMAx_IRQn);
      DMA_DeInit(Uart->DMAy_Streamx);
    }
    if (((*Uart->Ctrl)->HwCtrl & UART_HW_FLOW_CTRL_RX) || ((*Uart->Ctrl)->HwCtrl & UART_HALF_DUPLEX)) gpio_init((*Uart->Ctrl)->Gpio);
    _sys_free(*Uart->Ctrl);
    *Uart->Ctrl = 0;
  }

  /* Deactivate UART peripheral */
  USART_DeInit(Uart->UARTx);

  /* Disable peripheral clock */
  (*Uart->RCC_APBxPeriphClockCmd)(Uart->RCC_APBxPeriph, DISABLE);

  /* Configure GPIO to default state */
  gpio_init(Uart->TxGpio);
  gpio_init(Uart->RxGpio);

  return(0);
}
/**
* @brief  This routine will reconfigure the USART interface.
* @param  None.
* @retval None.
*/
void USART_ReConfig(void)
{
  USART_InitTypeDef USART_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
  
  USART_DeInit(USART2);
  
  USART_InitStructure.USART_BaudRate = SerialBaudRate;
  USART_InitStructure.USART_WordLength = SerialWordLength;
  USART_InitStructure.USART_StopBits = SerialStopBits;
  USART_InitStructure.USART_Parity = SerialParity;
  USART_InitStructure.USART_HardwareFlowControl = SerialHardwareFlowControl;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  
  USART_Init(USART2, &USART_InitStructure);
  
  /* NVIC configuration */
  /* Configure the Priority Group to 2 bits */
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  
  /* Enable the USARTx Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  USART_ITConfig(USART2, USART_IT_RXNE  , ENABLE);
  USART_ITConfig(USART2, USART_IT_TXE  , DISABLE);
  
  /* Enable USART */
  USART_Cmd(USART2, ENABLE);
}
示例#24
0
文件: usart.cpp 项目: 2cats/STM32
Usart<Configure>::Usart(int baud)
{
	//GPIO端口设置
	GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;
	RCC_APB1PeriphClockCmd(ConfigLoader<Configure>::RCC_USART, ENABLE);	
	RCC_APB2PeriphClockCmd(ConfigLoader<Configure>::RCC_GPIO, ENABLE);
	
	USART_DeInit((USART_TypeDef *)ConfigLoader<Configure>::GPIOx);
	//USART1_TX  
	GPIO_InitStructure.GPIO_Pin = ConfigLoader<Configure>::PIN_TX; 
	GPIO_InitStructure.GPIO_Speed =(GPIOSpeed_TypeDef) ConfigLoader<Configure>::SPEED;
	GPIO_InitStructure.GPIO_Mode =(GPIOMode_TypeDef) GPIO_Mode_AF_PP;	//复用推挽输出
	GPIO_Init((GPIO_TypeDef *)ConfigLoader<Configure>::GPIOx, &GPIO_InitStructure);
	//USART1_RX	  
	GPIO_InitStructure.GPIO_Pin = ConfigLoader<Configure>::PIN_RX;
	GPIO_InitStructure.GPIO_Mode = (GPIOMode_TypeDef)GPIO_Mode_IN_FLOATING;//浮空输入
	GPIO_Init((GPIO_TypeDef *)ConfigLoader<Configure>::GPIOx, &GPIO_InitStructure);  


	//USART 初始化设置

	USART_InitStructure.USART_BaudRate = baud;//一般设置为9600;
	USART_InitStructure.USART_WordLength = ConfigLoader<Configure>::USART_WordLength;//字长为8位数据格式
	USART_InitStructure.USART_StopBits = ConfigLoader<Configure>::USART_StopBits;//一个停止位
	USART_InitStructure.USART_Parity = ConfigLoader<Configure>::USART_Parity;//无奇偶校验位
	USART_InitStructure.USART_HardwareFlowControl = ConfigLoader<Configure>::USART_HardwareFlowControl;//无硬件数据流控制
	USART_InitStructure.USART_Mode = ConfigLoader<Configure>::USART_Mode;	//收发模式

	USART_Init((USART_TypeDef *)ConfigLoader<Configure>::GPIOx, &USART_InitStructure); //初始化串口

	USART_Cmd((USART_TypeDef *)ConfigLoader<Configure>::GPIOx, ENABLE);                    //使能串口 
};
示例#25
0
void UartMcuDeInit( Uart_t *obj )
{
    switch ( obj->UartId )
    {
    case UART_1:
        USART_DeInit( USART1 );
        break;
    case UART_2:
        USART_DeInit( USART2 );
        break;
    }
    //USART_DeInit( USART1 );

    GpioInit( &obj->Tx, obj->Tx.pin, PIN_ANALOGIC, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
    GpioInit( &obj->Rx, obj->Rx.pin, PIN_ANALOGIC, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
}
示例#26
0
void usartInit(void) {
    GPIO_InitTypeDef  GPIO_InitStruct;
    USART_InitTypeDef USART_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

    GPIO_InitStruct.GPIO_Pin   = GPIO_Pin_10;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStruct.GPIO_Mode  = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOB, &GPIO_InitStruct);

    GPIO_InitStruct.GPIO_Pin  = GPIO_Pin_11;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOB, &GPIO_InitStruct);

    USART_DeInit(USART3);
    USART_InitStructure.USART_BaudRate            = 9600;
    USART_InitStructure.USART_WordLength          = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits            = USART_StopBits_1;
    USART_InitStructure.USART_Parity              = USART_Parity_No;
    USART_InitStructure.USART_Mode                = USART_Mode_Rx | USART_Mode_Tx;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_Init(USART3, &USART_InitStructure);

    USART_Cmd(USART3, ENABLE);
}
OSStatus MicoUartFinalize( mico_uart_t uart )
{
  NVIC_InitTypeDef nvic_init_structure;
  
  MicoMcuPowerSaveConfig(false);
  
  /* Disable USART */
  USART_Cmd( uart_mapping[uart].usart, DISABLE );
  
  /* Deinitialise USART */
  USART_DeInit( uart_mapping[uart].usart );
  
  /**************************************************************************
  * De-initialise STM32 DMA and interrupt
  **************************************************************************/
  
  /* Deinitialise DMA streams */
  DMA_DeInit( uart_mapping[uart].tx_dma_stream );
  DMA_DeInit( uart_mapping[uart].rx_dma_stream );
  
  /* Disable TC (transfer complete) interrupt at the source */
  DMA_ITConfig( uart_mapping[uart].tx_dma_stream, DMA_IT_TC | DMA_IT_TE, DISABLE );
  
  /* Disable transmit DMA interrupt at Cortex-M3 */
  nvic_init_structure.NVIC_IRQChannel                   = uart_mapping[uart].tx_dma_irq;
  nvic_init_structure.NVIC_IRQChannelPreemptionPriority = (uint8_t) 0x5;
  nvic_init_structure.NVIC_IRQChannelSubPriority        = 0x8;
  nvic_init_structure.NVIC_IRQChannelCmd                = DISABLE;
  NVIC_Init( &nvic_init_structure );
  
  /* Disable DMA peripheral clocks */
  uart_mapping[uart].tx_dma_peripheral_clock_func( uart_mapping[uart].tx_dma_peripheral_clock, DISABLE );
  uart_mapping[uart].rx_dma_peripheral_clock_func( uart_mapping[uart].rx_dma_peripheral_clock, DISABLE );
  
  /**************************************************************************
  * De-initialise STM32 USART interrupt
  **************************************************************************/
  
  USART_ITConfig( uart_mapping[uart].usart, USART_IT_RXNE, DISABLE );
  
  /* Disable UART interrupt vector on Cortex-M3 */
  nvic_init_structure.NVIC_IRQChannel                   = uart_mapping[uart].usart_irq;
  nvic_init_structure.NVIC_IRQChannelPreemptionPriority = (uint8_t) 0xf;
  nvic_init_structure.NVIC_IRQChannelSubPriority        = 0xf;
  nvic_init_structure.NVIC_IRQChannelCmd                = DISABLE;
  NVIC_Init( &nvic_init_structure );
  
  /* Disable registers clocks */
  uart_mapping[uart].usart_peripheral_clock_func( uart_mapping[uart].usart_peripheral_clock, DISABLE );
  
#ifndef NO_MICO_RTOS
  mico_rtos_deinit_semaphore(&uart_interfaces[uart].rx_complete);
  mico_rtos_deinit_semaphore(&uart_interfaces[uart].tx_complete);
#endif
  
  MicoMcuPowerSaveConfig(true);
  
  return kNoErr;
}
示例#28
0
文件: main.c 项目: guillep19/frob
void USART_Configuration(u8 PORT, u32 baudrate)
{

	USART_InitTypeDef USART_InitStructure;

	USART_StructInit(&USART_InitStructure);


	USART_InitStructure.USART_BaudRate = baudrate;
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;
	USART_InitStructure.USART_StopBits = USART_StopBits_1;
	USART_InitStructure.USART_Parity = USART_Parity_No ;
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;


	if( PORT == USART_DXL )
	{
		USART_DeInit(USART1);
		mDelay(10);
		/* Configure the USART1 */
		USART_Init(USART1, &USART_InitStructure);

		/* Enable USART1 Receive and Transmit interrupts */
		USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
		//USART_ITConfig(USART1, USART_IT_TC, ENABLE);

		/* Enable the USART1 */
		USART_Cmd(USART1, ENABLE);
	}

	else if( PORT == USART_PC )
	{
		USART_DeInit(USART3);
		mDelay(10);
		/* Configure the USART3 */
		USART_Init(USART3, &USART_InitStructure);

		/* Enable USART3 Receive and Transmit interrupts */
		//USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
		//USART_ITConfig(USART3, USART_IT_TC, ENABLE);

		/* Enable the USART3 */
		USART_Cmd(USART3, ENABLE);
	}
}
示例#29
0
/* Disable the UART */
void UARTdisable()
{
    /* Float pins */
    initPins(0);

    /* DeInit */
    USART_DeInit(H1UART);
}
示例#30
0
//USART2	DMA初始化配置函数
void DST_DBUS_USART2::USART2_DMA_Init(void)
{
	USART_InitTypeDef usart2;
	GPIO_InitTypeDef  gpio;
	NVIC_InitTypeDef  nvic;
	DMA_InitTypeDef   dma;
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_DMA1,ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
	
	GPIO_PinAFConfig(GPIOD,GPIO_PinSource6 ,GPIO_AF_USART2);	//PD6 USART2_RX
	
	gpio.GPIO_Pin = GPIO_Pin_6;
	gpio.GPIO_Mode = GPIO_Mode_AF;
	gpio.GPIO_OType = GPIO_OType_PP;
	gpio.GPIO_Speed = GPIO_Speed_100MHz;
	gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_Init(GPIOD,&gpio);
	
	USART_DeInit(USART2);
	usart2.USART_BaudRate = 100000;   //SBUS 100K baudrate
	usart2.USART_WordLength = USART_WordLength_8b;
	usart2.USART_StopBits = USART_StopBits_1;
	usart2.USART_Parity = USART_Parity_Even;
	usart2.USART_Mode = USART_Mode_Rx;
	usart2.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	USART_Init(USART2,&usart2);
	
	USART_Cmd(USART2,ENABLE);
	USART_DMACmd(USART2,USART_DMAReq_Rx,ENABLE);

	nvic.NVIC_IRQChannel = DMA1_Stream5_IRQn;
	nvic.NVIC_IRQChannelPreemptionPriority = 1;	// 主优先级为1
	nvic.NVIC_IRQChannelSubPriority = 2;				// 从优先级为2
	nvic.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&nvic);
	
	DMA_DeInit(DMA1_Stream5);
	dma.DMA_Channel= DMA_Channel_4;
	dma.DMA_PeripheralBaseAddr = (uint32_t)&(USART2->DR);
	dma.DMA_Memory0BaseAddr = (uint32_t)dbus_rx_buffer;
	dma.DMA_DIR = DMA_DIR_PeripheralToMemory;
	dma.DMA_BufferSize = 18;
	dma.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
	dma.DMA_MemoryInc = DMA_MemoryInc_Enable;
	dma.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
	dma.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
	dma.DMA_Mode = DMA_Mode_Circular;
	dma.DMA_Priority = DMA_Priority_VeryHigh;
	dma.DMA_FIFOMode = DMA_FIFOMode_Disable;
	dma.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
	dma.DMA_MemoryBurst = DMA_Mode_Normal;
	dma.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
	DMA_Init(DMA1_Stream5,&dma);
	
	DMA_ITConfig(DMA1_Stream5,DMA_IT_TC,ENABLE);
	DMA_Cmd(DMA1_Stream5,ENABLE);
}