lib: port ESP8266 to STM32F4

This commit is contained in:
King Kévin 2022-07-14 18:54:06 +02:00
parent 68def6b234
commit 09ed3c91ea
2 changed files with 19 additions and 14 deletions

View File

@ -2,7 +2,7 @@
* @file * @file
* @author King Kévin <kingkevin@cuvoodoo.info> * @author King Kévin <kingkevin@cuvoodoo.info>
* @copyright SPDX-License-Identifier: GPL-3.0-or-later * @copyright SPDX-License-Identifier: GPL-3.0-or-later
* @date 2016 * @date 2016-2022
* @note peripherals used: USART @ref radio_esp8266_usart * @note peripherals used: USART @ref radio_esp8266_usart
*/ */
@ -25,7 +25,10 @@
/** @defgroup radio_esp8266_usart USART peripheral used for communication with radio /** @defgroup radio_esp8266_usart USART peripheral used for communication with radio
* @{ * @{
*/ */
#define RADIO_ESP8266_USART 2 /**< USART peripheral */ #define RADIO_ESP8266_USART 1 /**< USART peripheral */
#define RADIO_ESP8266_TX PA9 /**< pin used for USART TX */
#define RADIO_ESP8266_RX PA10 /**< pin used for USART RX */
#define RADIO_ESP8266_AF GPIO_AF7 /**< alternate function for UART pins */
/** @} */ /** @} */
/* input and output buffers and used memory */ /* input and output buffers and used memory */
@ -58,15 +61,18 @@ static void radio_esp8266_transmit(uint8_t* data, uint8_t length) {
void radio_esp8266_setup(void) void radio_esp8266_setup(void)
{ {
/* enable USART I/O peripheral */ // configure pins
rcc_periph_clock_enable(RCC_AFIO); // enable pin alternate function (USART) rcc_periph_clock_enable(GPIO_RCC(RADIO_ESP8266_TX)); // enable clock for USART TX pin port peripheral
rcc_periph_clock_enable(USART_PORT_RCC(RADIO_ESP8266_USART)); // enable clock for USART port peripheral gpio_mode_setup(GPIO_PORT(RADIO_ESP8266_TX), GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN(RADIO_ESP8266_TX)); // set TX pin to alternate function
rcc_periph_clock_enable(USART_RCC(RADIO_ESP8266_USART)); // enable clock for USART peripheral gpio_set_output_options(GPIO_PORT(RADIO_ESP8266_TX), GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, GPIO_PIN(RADIO_ESP8266_TX)); // set TX pin output as push-pull
gpio_set_mode(USART_PORT(RADIO_ESP8266_USART), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USART_PIN_TX(RADIO_ESP8266_USART)); // setup GPIO pin USART transmit gpio_set_af(GPIO_PORT(RADIO_ESP8266_TX), RADIO_ESP8266_AF, GPIO_PIN(RADIO_ESP8266_TX)); // set alternate function to USART
gpio_set_mode(USART_PORT(RADIO_ESP8266_USART), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, USART_PIN_RX(RADIO_ESP8266_USART)); // setup GPIO pin USART receive rcc_periph_clock_enable(GPIO_RCC(RADIO_ESP8266_RX)); // enable clock for USART RX pin port peripheral
gpio_set(USART_PORT(RADIO_ESP8266_USART), USART_PIN_RX(RADIO_ESP8266_USART)); // pull up to avoid noise when not connected gpio_mode_setup(GPIO_PORT(RADIO_ESP8266_RX), GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN(RADIO_ESP8266_RX)); // set GPIO to alternate function, with pull up to avoid noise in case it is not connected
gpio_set_af(GPIO_PORT(RADIO_ESP8266_RX), RADIO_ESP8266_AF, GPIO_PIN(RADIO_ESP8266_RX)); // set alternate function to USART
/* setup USART parameters for ESP8266 AT firmware */ // configure USART for ESP8266 AT firmware
rcc_periph_clock_enable(RCC_USART(RADIO_ESP8266_USART)); // enable clock for USART peripheral
rcc_periph_reset_pulse(RST_USART(RADIO_ESP8266_USART)); // reset peripheral
usart_set_baudrate(USART(RADIO_ESP8266_USART), 115200); // AT firmware 0.51 (SDK 1.5.0) uses 115200 bps usart_set_baudrate(USART(RADIO_ESP8266_USART), 115200); // AT firmware 0.51 (SDK 1.5.0) uses 115200 bps
usart_set_databits(USART(RADIO_ESP8266_USART), 8); usart_set_databits(USART(RADIO_ESP8266_USART), 8);
usart_set_stopbits(USART(RADIO_ESP8266_USART), USART_STOPBITS_1); usart_set_stopbits(USART(RADIO_ESP8266_USART), USART_STOPBITS_1);
@ -74,9 +80,9 @@ void radio_esp8266_setup(void)
usart_set_parity(USART(RADIO_ESP8266_USART), USART_PARITY_NONE); usart_set_parity(USART(RADIO_ESP8266_USART), USART_PARITY_NONE);
usart_set_flow_control(USART(RADIO_ESP8266_USART), USART_FLOWCONTROL_NONE); usart_set_flow_control(USART(RADIO_ESP8266_USART), USART_FLOWCONTROL_NONE);
nvic_enable_irq(USART_IRQ(RADIO_ESP8266_USART)); // enable the USART interrupt nvic_enable_irq(USART_IRQ(RADIO_ESP8266_USART)); // enable the UART interrupt
usart_enable_rx_interrupt(USART(RADIO_ESP8266_USART)); // enable receive interrupt usart_enable_rx_interrupt(USART(RADIO_ESP8266_USART)); // enable receive interrupt
usart_enable(USART(RADIO_ESP8266_USART)); // enable USART usart_enable(USART(RADIO_ESP8266_USART)); // enable UART
/* reset buffer states */ /* reset buffer states */
rx_used = 0; rx_used = 0;

View File

@ -2,11 +2,10 @@
* @file * @file
* @author King Kévin <kingkevin@cuvoodoo.info> * @author King Kévin <kingkevin@cuvoodoo.info>
* @copyright SPDX-License-Identifier: GPL-3.0-or-later * @copyright SPDX-License-Identifier: GPL-3.0-or-later
* @date 2016 * @date 2016-2022
* @note peripherals used: USART @ref radio_esp8266_usart * @note peripherals used: USART @ref radio_esp8266_usart
*/ */
#pragma once #pragma once
#error not converted for STM32F4
/** a response has been returned by the radio */ /** a response has been returned by the radio */
extern volatile bool radio_esp8266_activity; extern volatile bool radio_esp8266_activity;