void HardwareSerialFlowControl::begin(uint32 baud) { ASSERT(baud <= this->usart_device->max_baud); if (baud > this->usart_device->max_baud) { return; } const stm32_pin_info *txi = &PIN_MAP[this->tx_pin]; const stm32_pin_info *rxi = &PIN_MAP[this->rx_pin]; //TODO figureout how to extract correct pin from &PIN_MAP[this->rts_pin] const stm32_pin_info *ctsi = &PIN_MAP[this->cts_pin]; const stm32_pin_info *rtsi = &PIN_MAP[this->rts_pin]; disable_timer_if_necessary(txi->timer_device, txi->timer_channel); /* Configure USART2 RTS and USART2 Tx as alternate function push-pull */ /* Configure USART2 CTS and USART2 Rx as input floating */ usart_config_gpios_async(this->usart_device, rxi->gpio_device, rxi->gpio_bit, txi->gpio_device, txi->gpio_bit, 0); // need to configure the rts and cts pins here as // gpio_set_mode(ctsi->gpio_device, ctsi->gpio_bit, GPIO_INPUT_FLOATING); // gpio_set_mode(rtsi->gpio_device, rtsi->gpio_bit, GPIO_AF_OUTPUT_PP); // note this would do the same thing but is less explicit usart_config_gpios_async(this->usart_device, ctsi->gpio_device, ctsi->gpio_bit, rtsi->gpio_device, rtsi->gpio_bit, 0); usart_init(this->usart_device); usart_enable(this->usart_device); // enable rts/cts flow control in registers // should this be in usart.c for libmaple? does this apply to USART1,2.. // The stm peripheral example uses a temporary register (tmpreg) with a clear // mask and the following defines: // from stm peripheral library examples: // #define CR3_CLEAR_Mask ((uint16)0xFCFF) /*!< USART CR3 Mask */ // #define USART_HardwareFlowControl_RTS_CTS ((uint16)0x0300) // uint16 tmpreg = 0x00; // tmpreg = this->usart_device->regs->CR3; // tmpreg &= CR3_CLEAR_Mask; // tmpreg |= USART_HardwareFlowControl_RTS_CTS; // USART_HardwareFlowControl_RTS_CTS should be equivalent to // tmpreg |= (USART_CR3_RTSE |USART_CR3_CTSE ); // this->usart_device->regs->CR3 = tmpreg; this->usart_device->regs->CR3 = (USART_CR3_RTSE |USART_CR3_CTSE ); usart_set_baud_rate(this->usart_device, USART_USE_PCLK, baud); }
void HardwareSerial::begin(uint32 baud) { ASSERT(baud <= this->usart_device->max_baud); if (baud > this->usart_device->max_baud) { return; } const stm32_pin_info *txi = &PIN_MAP[this->tx_pin]; const stm32_pin_info *rxi = &PIN_MAP[this->rx_pin]; disable_timer_if_necessary(txi->timer_device, txi->timer_channel); usart_config_gpios_async(this->usart_device, rxi->gpio_device, rxi->gpio_bit, txi->gpio_device, txi->gpio_bit, 0); usart_init(this->usart_device); usart_set_baud_rate(this->usart_device, USART_USE_PCLK, baud); usart_enable(this->usart_device); }
void HardwareSerial::begin(uint32 baud, uint8_t config) { // ASSERT(baud <= this->usart_device->max_baud);// Roger Clark. Assert doesn't do anything useful, we may as well save the space in flash and ram etc if (baud > this->usart_device->max_baud) { return; } const stm32_pin_info *txi = &PIN_MAP[this->tx_pin]; const stm32_pin_info *rxi = &PIN_MAP[this->rx_pin]; disable_timer_if_necessary(txi->timer_device, txi->timer_channel); usart_init(this->usart_device); usart_config_gpios_async(this->usart_device, rxi->gpio_device, rxi->gpio_bit, txi->gpio_device, txi->gpio_bit, config); usart_set_baud_rate(this->usart_device, USART_USE_PCLK, baud); usart_enable(this->usart_device); }