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 UARTClass::begin(const uint32_t baud) { const stm32_pin_info *txi = &PIN_MAP[this->_txPin]; const stm32_pin_info *rxi = &PIN_MAP[this->_rxPin]; usart_config_gpios_async(this->_dev, rxi->gpio_device, rxi->gpio_bit, txi->gpio_device, txi->gpio_bit, 0); usart_init(this->_dev, _pBuff, _buffSize); usart_set_baud_rate(this->_dev, 0, baud); usart_enable(this->_dev); }
//To consider: Implement Cold/Hot start functions? //Idea for cold start, start and wait for coords or 30 seconds, whichever comes first. //Might be better to separate wait to avoid blocking and allow startup for other components simultaneously. void gps_start(void){ usart_config_gpios_async(GPS_USART, GPS_PORT_RX, GPS_PIN_RX, GPS_PORT_TX, GPS_PIN_TX, 0); usart_init(GPS_USART); usart_set_baud_rate(GPS_USART, USART_USE_PCLK, GPS_BAUD); //Enable BJT to turn on GPS //TODO: Confirm this isn't affected by being on UART CLK Pin (Currently unused) gpio_set_mode(GPIOA, 1, GPIO_OUTPUT_PP); gpio_write_bit(GPIOA, 8, 1); //Enable GPS USART Port usart_enable(GPS_USART); }
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); }