aboutsummaryrefslogtreecommitdiff
path: root/stm32f091
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-10-26 16:20:39 +0200
committerlonkaars <loek@pipeframe.xyz>2022-10-26 16:20:39 +0200
commitd945680142d5b16d8809ea200833edd97caec2f8 (patch)
treeba1e23bf440181e8a2c61587b5274877563fe880 /stm32f091
parente2ae9e96ba05baa389ebc49a65a941bada87e3aa (diff)
esp send with dma in seperate function
Diffstat (limited to 'stm32f091')
-rw-r--r--stm32f091/consts.h1
-rw-r--r--stm32f091/esp8266.c57
-rw-r--r--stm32f091/esp8266.h19
-rw-r--r--stm32f091/test.c8
4 files changed, 33 insertions, 52 deletions
diff --git a/stm32f091/consts.h b/stm32f091/consts.h
index 1d8648d..cf7d34f 100644
--- a/stm32f091/consts.h
+++ b/stm32f091/consts.h
@@ -5,6 +5,7 @@
#define WS_SERVER_PORT "80"
#define WS_DMA_RX_BUFFER_SIZE 50
+#define WS_DMA_TX_BUFFER_SIZE 50
#define WS_PINOUT_I2C_SDA_PIN GPIO_PIN_9
#define WS_PINOUT_I2C_SDA_PORT GPIOB
diff --git a/stm32f091/esp8266.c b/stm32f091/esp8266.c
index 98c4e10..24860a1 100644
--- a/stm32f091/esp8266.c
+++ b/stm32f091/esp8266.c
@@ -7,57 +7,26 @@
#include "esp8266.h"
#include "setup.h"
#include "consts.h"
+#include "util.h"
-char g_ws_esp8266_dma_rx_buffer[WS_DMA_RX_BUFFER_SIZE];
-char MainBuf[WS_DMA_RX_BUFFER_SIZE]; // TODO: remove
-int isOK = 0; // TODO: remove
-uint16_t g_ws_esp8266_dma_old_pos = 0;
-uint16_t g_ws_esp8266_dma_new_pos = 0;
-
-/*
-// when rx receives data handle the message. this function is in stm32. this name needs to stay the same or else it wont work.
-void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){
- if(huart->Instance == USART1) {
- g_ws_esp8266_dma_old_pos = g_ws_esp8266_dma_new_pos; // Update the last position before copying new data
-
- if(g_ws_esp8266_dma_old_pos+Size > WS_DMA_RX_BUFFER_SIZE) { // if the current position + new data is greater than the main buffer
- uint16_t dataToCopy = WS_DMA_RX_BUFFER_SIZE-g_ws_esp8266_dma_old_pos; // find remaining space left
- memcpy ((uint8_t*)MainBuf+g_ws_esp8266_dma_old_pos,g_ws_esp8266_dma_rx_buffer,dataToCopy); // copy data in the remaining space
-
- g_ws_esp8266_dma_old_pos = 0; // point to the start of the buffer
- memcpy ((uint8_t*)MainBuf,(uint8_t*)g_ws_esp8266_dma_rx_buffer+dataToCopy,(Size-dataToCopy)); // copy the remaing data
- g_ws_esp8266_dma_new_pos = (Size-dataToCopy); // update position
- }
- // if data is less than new data
- else {
- memcpy ((uint8_t*)MainBuf+g_ws_esp8266_dma_old_pos,g_ws_esp8266_dma_rx_buffer,Size);
- g_ws_esp8266_dma_new_pos = Size+g_ws_esp8266_dma_old_pos;
- }
- // start DMA again
- // memset(g_ws_esp8266_dma_rx_buffer,'\0',g_ws_esp8266_dma_rx_buffer_Size); // clear rx_buff
- HAL_UART_Receive_DMA(&huart1, (uint8_t*) g_ws_esp8266_dma_rx_buffer, WS_DMA_RX_BUFFER_SIZE);
- __HAL_DMA_DISABLE_IT(&hdma_usart1_rx,DMA_IT_HT);
- }
+uint8_t g_ws_esp8266_dma_rx_buffer[WS_DMA_RX_BUFFER_SIZE];
+uint8_t g_ws_esp8266_dma_tx_buffer[WS_DMA_TX_BUFFER_SIZE];
- // check for OK messagge
- for(int i=0;i<Size;i++){
- if(g_ws_esp8266_dma_rx_buffer[i]=='O' && g_ws_esp8266_dma_rx_buffer[i+1]=='K'){
- isOK=1;
- //memset(MainBuf,'\0',MainBuf_Size); // clear main buffer if OK is in the main buffer.
- //memset(g_ws_esp8266_dma_rx_buffer,'\0',g_ws_esp8266_dma_rx_buffer_Size); // clear rx_buff
+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); }
- }
- else if(strncmp(g_ws_esp8266_dma_rx_buffer, "+IPD", 4) == 0){
+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);
+ g_ws_esp8266_dma_tx_buffer[limited_size] = 0x00;
- }
- }
+ HAL_UART_Transmit_DMA(&huart1, g_ws_esp8266_dma_tx_buffer, strlen((char*) g_ws_esp8266_dma_tx_buffer));
+ __HAL_UART_ENABLE_IT(&huart1, UART_IT_TXE);
}
-*/
-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); }
+// TODO: refactor code from here to EOF
void ws_esp8266_ATsendCommand(uint8_t* data){
char dataChar[20];
uint8_t Tx_send[]="AT+CIPSEND=0,";
diff --git a/stm32f091/esp8266.h b/stm32f091/esp8266.h
index d18c214..8038679 100644
--- a/stm32f091/esp8266.h
+++ b/stm32f091/esp8266.h
@@ -2,17 +2,28 @@
#include "consts.h"
+#include <stdlib.h>
#include <stdint.h>
-extern char g_ws_esp8266_dma_rx_buffer[WS_DMA_RX_BUFFER_SIZE];
+/** @brief null-terminated rx buffer string */
+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];
-// void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *, uint16_t);
-/** @brief This function handles DMA1 channel 2 to 3 and DMA2 channel 1 to 2 interrupts. */
+/** @brief DMA1 channel 2-3 & DMA2 channel 1-2 interrupt handler */
void DMA1_Ch2_3_DMA2_Ch1_2_IRQHandler(void);
-/** @brief This function handles DMA1 channel 1 interrupt. */
+/** @brief DMA1 channel 1 interrupt handler */
void DMA1_Ch1_IRQHandler(void);
+/** @brief USART1 interrupt handler */
void USART1_IRQHandler(void);
+/** @brief send response to incoming request on specific channel */
+void ws_esp8266_res_send(unsigned int channel, uint8_t* data, size_t size);
+
+/** @brief send data to esp over uart with dma */
+void ws_esp8266_send(uint8_t* data, size_t size);
+
+// TODO: remove/update/document/refactor these functions
void ws_esp8266_ATsendCommand(uint8_t* data);
int ws_esp8266_checkOK(uint8_t *receiveData,int length);
int ws_esp8266_receivingMsg(uint8_t *receiveData,int length);
diff --git a/stm32f091/test.c b/stm32f091/test.c
index 4d1b936..0960d0f 100644
--- a/stm32f091/test.c
+++ b/stm32f091/test.c
@@ -2,9 +2,9 @@
#include <FreeRTOS.h>
#include <task.h>
+#include "esp8266.h"
#include "setup.h"
-
-uint8_t tx_buffer[] = "AT\r\n";
+#include "util.h"
void ws_test_read_task() {
uint8_t* buf; // TODO: not working
@@ -15,9 +15,9 @@ void ws_test_read_task() {
}
void ws_test_write_task() {
+ uint8_t data[] = "AT\r\n";
while (1) {
- HAL_UART_Transmit_DMA(&huart1, tx_buffer, sizeof(tx_buffer));
- __HAL_UART_ENABLE_IT(&huart1, UART_IT_TXE);
+ ws_esp8266_send(data, sizeof(data));
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
vTaskDelay(portTICK_PERIOD_MS * 1000 * 1);