void HardwareSerial::begin(uint32 baud) {
    ASSERT(baud <= usart_device->max_baud);

    if (baud > usart_device->max_baud) {
        return;
    }

    const stm32_pin_info *txi = &PIN_MAP[tx_pin];
    const stm32_pin_info *rxi = &PIN_MAP[rx_pin];
#ifdef STM32F2
	// int af = 7<<8;
    gpio_set_af_mode(txi->gpio_device, txi->gpio_bit, 7);
    gpio_set_af_mode(rxi->gpio_device, rxi->gpio_bit, 7);
    gpio_set_mode(txi->gpio_device, txi->gpio_bit, (gpio_pin_mode)(GPIO_AF_OUTPUT_PP | GPIO_PUPD_INPUT_PU | 0x700));
    gpio_set_mode(rxi->gpio_device, rxi->gpio_bit, (gpio_pin_mode)(GPIO_MODE_AF      | GPIO_PUPD_INPUT_PU | 0x700));
    //gpio_set_mode(txi->gpio_device, txi->gpio_bit, (gpio_pin_mode)(GPIO_PUPD_INPUT_PU));
    //gpio_set_mode(rxi->gpio_device, rxi->gpio_bit, (gpio_pin_mode)(GPIO_PUPD_INPUT_PU));
#else
	gpio_set_mode(txi->gpio_device, txi->gpio_bit, GPIO_AF_OUTPUT_PP);
    gpio_set_mode(rxi->gpio_device, rxi->gpio_bit, GPIO_INPUT_FLOATING);
#endif
#if 0
    if (txi->timer_device != NULL) {
        /* Turn off any PWM if there's a conflict on this GPIO bit. */
        timer_set_mode(txi->timer_device, txi->timer_channel, TIMER_DISABLED);
    }
#endif

    usart_init(usart_device);
    usart_set_baud_rate(usart_device, baud);
    usart_enable(usart_device);
}
Exemple #2
0
void USB_OTG_BSP_DeInit(USB_OTG_CORE_HANDLE *pdev)
{
	// ala42
#define GPIO_AF0         ((uint8_t)0)  /* OTG_FS Alternate Function mapping */
	gpio_set_mode(GPIOA,11, GPIO_MODE_INPUT);
	gpio_set_mode(GPIOA,12, GPIO_MODE_INPUT);
	gpio_set_af_mode(GPIOA,11,GPIO_AF0) ;	// OTG_FS_DM
	gpio_set_af_mode(GPIOA,12,GPIO_AF0) ;	// OTG_FS_DP
#ifdef USB_OTG_FS_SOF_OUTPUT_ENABLED
	gpio_set_mode(GPIOA, 8,GPIO_MODE_INPUT);
	gpio_set_af_mode(GPIOA, 8,GPIO_AF0) ;		// OTG_FS_SOF
#endif
#ifdef VBUS_SENSING_ENABLED
	gpio_set_mode(GPIOA, 9,GPIO_MODE_INPUT);
	gpio_set_af_mode(GPIOA, 9,GPIO_AF0) ;		// OTG_FS_VBUS
#endif

#ifdef ID_SENSING_ENABLED
	gpio_set_mode(GPIOA,10,GPIO_MODE_INPUT);
	gpio_set_af_mode(GPIOA,10,GPIO_AF0) ;	// OTG_FS_ID
#endif

	rcc_clk_enable(RCC_SYSCFG);
	rcc_clk_disable(RCC_USBFS);
}
Exemple #3
0
void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
{
	// ala42
#define GPIO_AF_OTG1_FS         ((uint8_t)0xA)  /* OTG_FS Alternate Function mapping */
	gpio_set_mode(GPIOA,11,GPIO_MODE_AF | GPIO_OTYPE_PP | GPIO_OSPEED_100MHZ);
	gpio_set_mode(GPIOA,12,GPIO_MODE_AF | GPIO_OTYPE_PP | GPIO_OSPEED_100MHZ);
	gpio_set_af_mode(GPIOA,11,GPIO_AF_OTG1_FS) ;	// OTG_FS_DM
	gpio_set_af_mode(GPIOA,12,GPIO_AF_OTG1_FS) ;	// OTG_FS_DP
#ifdef USB_OTG_FS_SOF_OUTPUT_ENABLED
	gpio_set_mode(GPIOA, 8,GPIO_MODE_AF | GPIO_OTYPE_PP | GPIO_OSPEED_100MHZ);
	gpio_set_af_mode(GPIOA, 8,GPIO_AF_OTG1_FS) ;		// OTG_FS_SOF
#endif
#ifdef VBUS_SENSING_ENABLED
	gpio_set_mode(GPIOA, 9,GPIO_MODE_AF | GPIO_OTYPE_PP | GPIO_OSPEED_100MHZ);
	gpio_set_af_mode(GPIOA, 9,GPIO_AF_OTG1_FS) ;		// OTG_FS_VBUS
#endif

#ifdef ID_SENSING_ENABLED
	gpio_set_mode(GPIOA,10,GPIO_MODE_OUTPUT | GPIO_OTYPE_OD | GPIO_PUPD_INPUT_PU | GPIO_OSPEED_100MHZ);
	gpio_set_af_mode(GPIOA,10,GPIO_AF_OTG1_FS) ;	// OTG_FS_ID
#endif
	rcc_clk_enable(RCC_SYSCFG);
	rcc_clk_enable(RCC_USBFS);
}
//static void initSRAMChip(void);
void boardInit(void) {
	// remap TIMER8 to PC6-9
	gpio_set_af_mode(GPIOC, 6, 3);
	gpio_set_af_mode(GPIOC, 7, 3);
	gpio_set_af_mode(GPIOC, 8, 3);
	gpio_set_af_mode(GPIOC, 9, 3);

	// remap TIMER1 to PE9,11,13,14
	gpio_set_af_mode(GPIOE,  9, 1);
	gpio_set_af_mode(GPIOE, 11, 1);
	gpio_set_af_mode(GPIOE, 13, 1);
	gpio_set_af_mode(GPIOE, 14, 1);

	// remap TIMER3 to PB4,5,0,1
	gpio_set_af_mode(GPIOB,  4, 2);
	gpio_set_af_mode(GPIOB,  5, 2);
	gpio_set_af_mode(GPIOB,  0, 2);
	gpio_set_af_mode(GPIOB,  1, 2);

	//gpio_set_af_mode(GPIOA, 2, 7);
	//gpio_set_af_mode(GPIOA, 3, 7);

#ifdef ARDUINO_STM32F4_NETDUINO2PLUS
    // PA8 Output the Master Clock MCO1
    gpio_set_af_mode(GPIOA, 8, 0);
    // PB4 as alternate MISO Input
    gpio_set_af_mode(GPIOB, 4, 5);
    // PA5 as alternate SCK Output
    gpio_set_af_mode(GPIOA, 5, 5);
    // PA7 as alternate MOSI Output
    gpio_set_af_mode(GPIOA, 7, 5);
#endif
	return;
}