diff options
Diffstat (limited to 'stm32f091')
-rw-r--r-- | stm32f091/consts.h | 2 | ||||
-rw-r--r-- | stm32f091/esp8266.c | 8 | ||||
-rw-r--r-- | stm32f091/esp8266.h | 10 | ||||
-rw-r--r-- | stm32f091/main.c | 3 | ||||
-rw-r--r-- | stm32f091/setup.c | 11 | ||||
-rw-r--r-- | stm32f091/stm32f0xx_hal_conf.h | 2 | ||||
-rw-r--r-- | stm32f091/test.c | 13 | ||||
-rw-r--r-- | stm32f091/test.h | 1 |
8 files changed, 28 insertions, 22 deletions
diff --git a/stm32f091/consts.h b/stm32f091/consts.h index cf7d34f..5f9d7a1 100644 --- a/stm32f091/consts.h +++ b/stm32f091/consts.h @@ -4,7 +4,7 @@ #define WS_SERVER_PORT "80" -#define WS_DMA_RX_BUFFER_SIZE 50 +#define WS_DMA_RX_BUFFER_SIZE 10 #define WS_DMA_TX_BUFFER_SIZE 50 #define WS_PINOUT_I2C_SDA_PIN GPIO_PIN_9 diff --git a/stm32f091/esp8266.c b/stm32f091/esp8266.c index 24860a1..5d1847b 100644 --- a/stm32f091/esp8266.c +++ b/stm32f091/esp8266.c @@ -16,6 +16,14 @@ void DMA1_Ch1_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_usart1_rx); } void DMA1_Ch2_3_DMA2_Ch1_2_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_usart1_tx); } void USART1_IRQHandler(void) { HAL_UART_IRQHandler(&huart1); } +void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) { + HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); + + HAL_UART_Transmit(&huart2, g_ws_esp8266_dma_rx_buffer, WS_DMA_RX_BUFFER_SIZE, 100); + HAL_UART_Receive_DMA(&huart1, g_ws_esp8266_dma_rx_buffer, WS_DMA_RX_BUFFER_SIZE); + __HAL_DMA_DISABLE_IT(&hdma_usart1_rx, DMA_IT_HT); +} + void ws_esp8266_send(uint8_t* data, size_t size) { size_t limited_size = WS_MIN(size, WS_DMA_TX_BUFFER_SIZE - 1); memcpy(g_ws_esp8266_dma_tx_buffer, data, limited_size); diff --git a/stm32f091/esp8266.h b/stm32f091/esp8266.h index 8038679..0832e95 100644 --- a/stm32f091/esp8266.h +++ b/stm32f091/esp8266.h @@ -1,11 +1,12 @@ #pragma once -#include "consts.h" - +#include <stm32f0xx_hal.h> #include <stdlib.h> #include <stdint.h> -/** @brief null-terminated rx buffer string */ +#include "consts.h" + +/** @brief DMA rx buffer */ extern uint8_t g_ws_esp8266_dma_rx_buffer[WS_DMA_RX_BUFFER_SIZE]; /** @brief null-terminated tx buffer string */ extern uint8_t g_ws_esp8266_dma_tx_buffer[WS_DMA_TX_BUFFER_SIZE]; @@ -17,6 +18,9 @@ void DMA1_Ch1_IRQHandler(void); /** @brief USART1 interrupt handler */ void USART1_IRQHandler(void); +/** @brief receive chunk complete */ +void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart); + /** @brief send response to incoming request on specific channel */ void ws_esp8266_res_send(unsigned int channel, uint8_t* data, size_t size); diff --git a/stm32f091/main.c b/stm32f091/main.c index f5fe563..80eb5a7 100644 --- a/stm32f091/main.c +++ b/stm32f091/main.c @@ -11,7 +11,6 @@ int main() { ws_io_setup(); // xTaskCreate(ws_sensor_read_task, "sensor", 64, NULL, 1, NULL); - xTaskCreate(ws_test_write_task, "testw", 16, NULL, 2, NULL); - xTaskCreate(ws_test_read_task, "testr", 16, NULL, 2, NULL); + xTaskCreate(ws_test_write_task, "test", 16, NULL, 2, NULL); vTaskStartScheduler(); } diff --git a/stm32f091/setup.c b/stm32f091/setup.c index 39cff07..98ef8cd 100644 --- a/stm32f091/setup.c +++ b/stm32f091/setup.c @@ -30,8 +30,8 @@ UART_HandleTypeDef huart1 = { .Init.Mode = UART_MODE_TX_RX, .Init.HwFlowCtl = UART_HWCONTROL_NONE, .Init.OverSampling = UART_OVERSAMPLING_16, - .Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE, - .AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT, +// .Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE, +// .AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT, }; UART_HandleTypeDef huart2 = { @@ -81,6 +81,7 @@ void ws_io_setup() { ws_io_clock_setup(); ws_io_i2c_setup(); + ws_io_dma_setup(); ws_io_usart1_setup(); ws_io_usart2_setup(); ws_io_dma_setup(); @@ -132,7 +133,11 @@ static void ws_io_usart1_setup() { if (HAL_UART_Init(&huart1) != HAL_OK) return ws_setup_error_handler(); + // HAL_UARTEx_ReceiveToIdle_DMA(&huart2, RX_DMA_buffer, RX_DMA_BUFFER_SIZE); + HAL_UART_Receive_DMA(&huart1, g_ws_esp8266_dma_rx_buffer, WS_DMA_RX_BUFFER_SIZE); __HAL_DMA_DISABLE_IT(&hdma_usart1_rx, DMA_IT_HT); + // __HAL_DMA_ENABLE_IT(&hdma_usart1_rx, DMA_IT_TC); + // __HAL_UART_ENABLE_IT(&huart1, UART_IT_TC); } static void ws_io_usart2_setup() { @@ -191,7 +196,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef *huart) { __HAL_LINKDMA(huart, hdmatx, hdma_usart1_tx); // USART1 interrupt Init - HAL_NVIC_SetPriority(USART1_IRQn, 0, 0); + HAL_NVIC_SetPriority(USART1_IRQn, 5, 0); HAL_NVIC_EnableIRQ(USART1_IRQn); } else if (huart->Instance == USART2) { __HAL_RCC_USART2_CLK_ENABLE(); diff --git a/stm32f091/stm32f0xx_hal_conf.h b/stm32f091/stm32f0xx_hal_conf.h index fc27221..45f9fab 100644 --- a/stm32f091/stm32f0xx_hal_conf.h +++ b/stm32f091/stm32f0xx_hal_conf.h @@ -19,6 +19,8 @@ #define DATA_CACHE_ENABLE 0U #define USE_SPI_CRC 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 1 + #define HAL_RCC_MODULE_ENABLED #define HAL_MODULE_ENABLED #define HAL_I2C_MODULE_ENABLED diff --git a/stm32f091/test.c b/stm32f091/test.c index 0960d0f..e25b071 100644 --- a/stm32f091/test.c +++ b/stm32f091/test.c @@ -3,23 +3,12 @@ #include <task.h> #include "esp8266.h" -#include "setup.h" -#include "util.h" - -void ws_test_read_task() { - uint8_t* buf; // TODO: not working - while (1) { - HAL_UART_Receive_DMA(&huart1, buf, 1); - HAL_UART_Transmit(&huart2, buf, 1, 100); - } -} void ws_test_write_task() { uint8_t data[] = "AT\r\n"; while (1) { ws_esp8266_send(data, sizeof(data)); - HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); - vTaskDelay(portTICK_PERIOD_MS * 1000 * 1); + vTaskDelay(portTICK_PERIOD_MS * 100 * 1); } } diff --git a/stm32f091/test.h b/stm32f091/test.h index 6c312d9..dffa516 100644 --- a/stm32f091/test.h +++ b/stm32f091/test.h @@ -1,4 +1,3 @@ #pragma once -void ws_test_read_task(); void ws_test_write_task(); |