From 137f62eb368101dd0371f0c54e1a4a2a7be48890 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 14 Oct 2022 15:57:47 +0200 Subject: remove executable from git --- .gitignore | 1 + 1 file changed, 1 insertion(+) (limited to '.gitignore') diff --git a/.gitignore b/.gitignore index 1c68c8a..aba4463 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ stm32f091/main.bin client/makefile client/client client/moc_* +shared/main .qmake.stash .vscode/.cortex-debug.registers.state.json -- cgit v1.2.3 From ed1c1efa7aee67d36a37212c13998318f02c4350 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 19 Oct 2022 22:12:31 +0200 Subject: moved constants around --- .gitignore | 15 ++++++++++++--- stm32f091/consts.h | 19 +++++++++++++++++++ stm32f091/esp8266.c | 3 ++- stm32f091/readme.md | 7 +++++++ stm32f091/setup.h | 15 +-------------- stm32f091/wifi.def.h | 5 +++++ 6 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 stm32f091/consts.h create mode 100644 stm32f091/readme.md create mode 100644 stm32f091/wifi.def.h (limited to '.gitignore') diff --git a/.gitignore b/.gitignore index aba4463..18c2616 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,21 @@ -copyright +# blob **/*.o -stm32f091/main.elf -stm32f091/main.bin **/.cache **/compile_commands.json + +# stm32-specific files +stm32f091/main.elf +stm32f091/main.bin +stm32f091/wifi.h + +# client-specific files client/makefile client/client client/moc_* + +# others shared/main .qmake.stash .vscode/.cortex-debug.registers.state.json +copyright + diff --git a/stm32f091/consts.h b/stm32f091/consts.h new file mode 100644 index 0000000..e0d92bb --- /dev/null +++ b/stm32f091/consts.h @@ -0,0 +1,19 @@ +#pragma once + +#include "wifi.h" + +#define WS_PINOUT_I2C_SDA_PIN GPIO_PIN_9 +#define WS_PINOUT_I2C_SDA_PORT GPIOB +#define WS_PINOUT_I2C_SCL_PIN GPIO_PIN_8 +#define WS_PINOUT_I2C_SCL_PORT GPIOB + +#define WS_PINOUT_USART1_RX_PIN GPIO_PIN_10 +#define WS_PINOUT_USART1_RX_PORT GPIOA +#define WS_PINOUT_USART1_TX_PIN GPIO_PIN_9 +#define WS_PINOUT_USART1_TX_PORT GPIOA + +#define WS_PINOUT_USART2_RX_PIN GPIO_PIN_3 +#define WS_PINOUT_USART2_RX_PORT GPIOA +#define WS_PINOUT_USART2_TX_PIN GPIO_PIN_2 +#define WS_PINOUT_USART2_TX_PORT GPIOA + diff --git a/stm32f091/esp8266.c b/stm32f091/esp8266.c index 4c5d0d2..9fccf70 100644 --- a/stm32f091/esp8266.c +++ b/stm32f091/esp8266.c @@ -5,6 +5,7 @@ #include "esp8266.h" #include "setup.h" +#include "consts.h" void ws_esp8266_ATsendCommand(uint8_t* data){ char dataChar[20]; @@ -126,7 +127,7 @@ void ws_esp8266_mode(){ HAL_Delay(1000); } void ws_esp8266_connect(){ - uint8_t Tx_network[]="AT+CWJAP=\"Test\",\"12345678\"\r\n"; + uint8_t Tx_network[]="AT+CWJAP=\"" WS_ESP8266_WLAN_SSID "\",\"" WS_ESP8266_WLAN_PASSWD "\"\r\n"; HAL_UART_Transmit(&huart1, Tx_network,strlen((char*)Tx_network),1000); diff --git a/stm32f091/readme.md b/stm32f091/readme.md new file mode 100644 index 0000000..97492d5 --- /dev/null +++ b/stm32f091/readme.md @@ -0,0 +1,7 @@ +# stm32 firmware subdirectory + +- uses make +- make sure to initialize the git submodules +- all warnings from source files in the lib/ subfolder are hidden +- copy wifi.def.h to wifi.h and edit the network credentials + diff --git a/stm32f091/setup.h b/stm32f091/setup.h index 8ca3720..04fa177 100644 --- a/stm32f091/setup.h +++ b/stm32f091/setup.h @@ -4,20 +4,7 @@ #include #include -#define WS_PINOUT_I2C_SDA_PIN GPIO_PIN_9 -#define WS_PINOUT_I2C_SDA_PORT GPIOB -#define WS_PINOUT_I2C_SCL_PIN GPIO_PIN_8 -#define WS_PINOUT_I2C_SCL_PORT GPIOB - -#define WS_PINOUT_USART1_RX_PIN GPIO_PIN_10 -#define WS_PINOUT_USART1_RX_PORT GPIOA -#define WS_PINOUT_USART1_TX_PIN GPIO_PIN_9 -#define WS_PINOUT_USART1_TX_PORT GPIOA - -#define WS_PINOUT_USART2_RX_PIN GPIO_PIN_3 -#define WS_PINOUT_USART2_RX_PORT GPIOA -#define WS_PINOUT_USART2_TX_PIN GPIO_PIN_2 -#define WS_PINOUT_USART2_TX_PORT GPIOA +#include "consts.h" extern I2C_HandleTypeDef hi2c1; extern UART_HandleTypeDef huart1; diff --git a/stm32f091/wifi.def.h b/stm32f091/wifi.def.h new file mode 100644 index 0000000..f0748d2 --- /dev/null +++ b/stm32f091/wifi.def.h @@ -0,0 +1,5 @@ +#pragma once + +#define WS_ESP8266_WLAN_SSID "Test" +#define WS_ESP8266_WLAN_PASSWD "12345678" + -- cgit v1.2.3 From 931b357fee219f7d69e3b2e1c5c275413de6010b Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-LF2PDOO\\niels" Date: Tue, 25 Oct 2022 17:42:12 +0200 Subject: initial merge of CubeIDE code for dma idle read --- .gitignore | 1 + stm32f091/consts.h | 2 ++ stm32f091/esp8266.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ stm32f091/esp8266.h | 10 ++++++++++ stm32f091/setup.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ stm32f091/setup.h | 2 ++ 6 files changed, 114 insertions(+) (limited to '.gitignore') diff --git a/.gitignore b/.gitignore index 18c2616..90d7960 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ shared/main .qmake.stash .vscode/.cortex-debug.registers.state.json copyright +temp/ diff --git a/stm32f091/consts.h b/stm32f091/consts.h index 349ff21..1d8648d 100644 --- a/stm32f091/consts.h +++ b/stm32f091/consts.h @@ -4,6 +4,8 @@ #define WS_SERVER_PORT "80" +#define WS_DMA_RX_BUFFER_SIZE 50 + #define WS_PINOUT_I2C_SDA_PIN GPIO_PIN_9 #define WS_PINOUT_I2C_SDA_PORT GPIOB #define WS_PINOUT_I2C_SCL_PIN GPIO_PIN_8 diff --git a/stm32f091/esp8266.c b/stm32f091/esp8266.c index 4fdf7e6..6a9f254 100644 --- a/stm32f091/esp8266.c +++ b/stm32f091/esp8266.c @@ -2,11 +2,64 @@ #include #include #include +#include #include "esp8266.h" #include "setup.h" #include "consts.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_UARTEx_ReceiveToIdle_DMA(&huart1, g_ws_esp8266_dma_rx_buffer, WS_DMA_RX_BUFFER_SIZE); + __HAL_DMA_DISABLE_IT(&hdma_usart1_rx,DMA_IT_HT); + } + + // check for OK messagge + for(int i=0;i +extern char g_ws_esp8266_dma_rx_buffer[WS_DMA_RX_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. */ +void DMA1_Ch2_3_DMA2_Ch1_2_IRQHandler(void); +/** @brief This function handles DMA1 channel 1 interrupt. */ +void DMA1_Ch1_IRQHandler(void); + 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/setup.c b/stm32f091/setup.c index fec2b7c..318de5a 100644 --- a/stm32f091/setup.c +++ b/stm32f091/setup.c @@ -5,6 +5,7 @@ #include #include +#include "esp8266.h" #include "setup.h" I2C_HandleTypeDef hi2c1 = { @@ -45,10 +46,33 @@ UART_HandleTypeDef huart2 = { .AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT, }; +DMA_HandleTypeDef hdma_usart1_rx = { + .Instance = DMA1_Channel1, + .Init.Direction = DMA_PERIPH_TO_MEMORY, + .Init.PeriphInc = DMA_PINC_DISABLE, + .Init.MemInc = DMA_MINC_ENABLE, + .Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE, + .Init.MemDataAlignment = DMA_MDATAALIGN_BYTE, + .Init.Mode = DMA_NORMAL, + .Init.Priority = DMA_PRIORITY_LOW, +}; + +DMA_HandleTypeDef hdma_usart1_tx { + .Instance = DMA1_Channel2, + .Init.Direction = DMA_MEMORY_TO_PERIPH, + .Init.PeriphInc = DMA_PINC_DISABLE, + .Init.MemInc = DMA_MINC_ENABLE, + .Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE, + .Init.MemDataAlignment = DMA_MDATAALIGN_BYTE, + .Init.Mode = DMA_NORMAL, + .Init.Priority = DMA_PRIORITY_LOW, +}; + static void ws_io_clock_setup(); static void ws_io_i2c_setup(); static void ws_io_usart1_setup(); static void ws_io_usart2_setup(); +static void ws_io_dma_setup(); static void ws_setup_error_handler(); void ws_io_setup() { @@ -58,6 +82,7 @@ void ws_io_setup() { ws_io_i2c_setup(); ws_io_usart1_setup(); ws_io_usart2_setup(); + ws_io_dma_setup(); } static void ws_io_clock_setup() { @@ -97,6 +122,9 @@ static void ws_io_i2c_setup() { static void ws_io_usart1_setup() { if (HAL_UART_Init(&huart1) != HAL_OK) return ws_setup_error_handler(); + + HAL_UARTEx_ReceiveToIdle_DMA(&huart1, g_ws_esp8266_dma_rx_buffer, WS_DMA_RX_BUFFER_SIZE); + __HAL_DMA_DISABLE_IT(&hdma_usart1_rx, DMA_IT_HT); } static void ws_io_usart2_setup() { @@ -104,6 +132,16 @@ static void ws_io_usart2_setup() { return ws_setup_error_handler(); } +static void ws_io_dma_setup() { + __HAL_RCC_DMA1_CLK_ENABLE(); + + // interrupt priorities + HAL_NVIC_SetPriority(DMA1_Ch1_IRQn, 3, 0); + HAL_NVIC_EnableIRQ(DMA1_Ch1_IRQn); + HAL_NVIC_SetPriority(DMA1_Ch2_3_DMA2_Ch1_2_IRQn, 3, 0); + HAL_NVIC_EnableIRQ(DMA1_Ch2_3_DMA2_Ch1_2_IRQn); +} + void HAL_MspInit() { __HAL_RCC_SYSCFG_CLK_ENABLE(); __HAL_RCC_PWR_CLK_ENABLE(); @@ -136,6 +174,14 @@ void HAL_UART_MspInit(UART_HandleTypeDef *huart) { .Alternate = GPIO_AF1_USART1, }); + // DMA setup + if (HAL_DMA_Init(&hdma_usart1_rx) != HAL_OK) return ws_setup_error_handler(); + __HAL_DMA1_REMAP(HAL_DMA1_CH1_USART1_RX); + __HAL_LINKDMA(huart, hdmarx, hdma_usart1_rx); + if (HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK) return ws_setup_error_handler(); + __HAL_DMA1_REMAP(HAL_DMA1_CH2_USART1_TX); + __HAL_LINKDMA(huart, hdmatx, hdma_usart1_tx); + // USART1 interrupt Init HAL_NVIC_SetPriority(USART1_IRQn, 0, 0); HAL_NVIC_EnableIRQ(USART1_IRQn); diff --git a/stm32f091/setup.h b/stm32f091/setup.h index 04fa177..d459635 100644 --- a/stm32f091/setup.h +++ b/stm32f091/setup.h @@ -9,6 +9,8 @@ extern I2C_HandleTypeDef hi2c1; extern UART_HandleTypeDef huart1; extern UART_HandleTypeDef huart2; +extern DMA_HandleTypeDef hdma_usart1_rx; +extern DMA_HandleTypeDef hdma_usart1_tx; void ws_io_setup(); -- cgit v1.2.3