From aab4ed17b94f54813368201d3a0cba3f3d432589 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 19 Oct 2022 20:04:06 +0200 Subject: integrate protocol code into stm32 code --- stm32f091/makefile | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'stm32f091/makefile') diff --git a/stm32f091/makefile b/stm32f091/makefile index 5a185de..20424c3 100644 --- a/stm32f091/makefile +++ b/stm32f091/makefile @@ -5,6 +5,8 @@ RM = rm -f TARGET = main +include ../shared/shared.mk + SHARED_FLAGS += -g SHARED_FLAGS += -DSTM32F091xC SHARED_FLAGS += -Wall @@ -74,9 +76,15 @@ $(TARGET).bin: $(TARGET).elf %.o: %.s $(CC) -c $(AFLAGS) $< -o $@ +lib/%.o: lib/%.c + $(CC) -c $(CFLAGS) -w $< -o $@ + %.o: %.c $(CC) -c $(CFLAGS) $< -o $@ +%-stm.o: %.c + $(CC) -c $(CFLAGS) $< -o $@ + $(TARGET).elf: $(OBJS) $(LD) $(LFLAGS) $^ -o $@ -- cgit v1.2.3 From e2ae9e96ba05baa389ebc49a65a941bada87e3aa Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 26 Oct 2022 15:51:18 +0200 Subject: dma write working --- stm32f091/esp8266.c | 12 +++++------- stm32f091/esp8266.h | 3 ++- stm32f091/main.c | 6 +++++- stm32f091/makefile | 1 + stm32f091/setup.c | 1 - stm32f091/test.c | 25 +++++++++++++++++++++++++ stm32f091/test.h | 4 ++++ 7 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 stm32f091/test.c create mode 100644 stm32f091/test.h (limited to 'stm32f091/makefile') diff --git a/stm32f091/esp8266.c b/stm32f091/esp8266.c index 341f052..98c4e10 100644 --- a/stm32f091/esp8266.c +++ b/stm32f091/esp8266.c @@ -14,6 +14,7 @@ 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) { @@ -51,14 +52,11 @@ void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){ } } } +*/ -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 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 ws_esp8266_ATsendCommand(uint8_t* data){ char dataChar[20]; diff --git a/stm32f091/esp8266.h b/stm32f091/esp8266.h index 9df02cb..d18c214 100644 --- a/stm32f091/esp8266.h +++ b/stm32f091/esp8266.h @@ -6,11 +6,12 @@ extern char g_ws_esp8266_dma_rx_buffer[WS_DMA_RX_BUFFER_SIZE]; -void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *, uint16_t); +// 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 USART1_IRQHandler(void); void ws_esp8266_ATsendCommand(uint8_t* data); int ws_esp8266_checkOK(uint8_t *receiveData,int length); diff --git a/stm32f091/main.c b/stm32f091/main.c index ed0dacd..f5fe563 100644 --- a/stm32f091/main.c +++ b/stm32f091/main.c @@ -6,8 +6,12 @@ #include "setup.h" #include "sensor.h" +#include "test.h" + int main() { ws_io_setup(); - xTaskCreate(ws_sensor_read_task, "sensor", 128, NULL, 1, NULL); + // 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); vTaskStartScheduler(); } diff --git a/stm32f091/makefile b/stm32f091/makefile index 20424c3..bf20f00 100644 --- a/stm32f091/makefile +++ b/stm32f091/makefile @@ -90,6 +90,7 @@ $(TARGET).elf: $(OBJS) flash: $(TARGET).bin st-flash write $(TARGET).bin 0x08000000 + st-flash reset compile_commands: clean compiledb make -n diff --git a/stm32f091/setup.c b/stm32f091/setup.c index 63efd37..39cff07 100644 --- a/stm32f091/setup.c +++ b/stm32f091/setup.c @@ -132,7 +132,6 @@ static void ws_io_usart1_setup() { if (HAL_UART_Init(&huart1) != HAL_OK) return ws_setup_error_handler(); - 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); } diff --git a/stm32f091/test.c b/stm32f091/test.c new file mode 100644 index 0000000..4d1b936 --- /dev/null +++ b/stm32f091/test.c @@ -0,0 +1,25 @@ +#include +#include +#include + +#include "setup.h" + +uint8_t tx_buffer[] = "AT\r\n"; + +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() { + while (1) { + HAL_UART_Transmit_DMA(&huart1, tx_buffer, sizeof(tx_buffer)); + __HAL_UART_ENABLE_IT(&huart1, UART_IT_TXE); + + HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); + vTaskDelay(portTICK_PERIOD_MS * 1000 * 1); + } +} diff --git a/stm32f091/test.h b/stm32f091/test.h new file mode 100644 index 0000000..6c312d9 --- /dev/null +++ b/stm32f091/test.h @@ -0,0 +1,4 @@ +#pragma once + +void ws_test_read_task(); +void ws_test_write_task(); -- cgit v1.2.3 From a74368cb7eebb99b14060c9198dfa277a18c2234 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 26 Oct 2022 19:17:51 +0200 Subject: optimize makefile --- stm32f091/makefile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'stm32f091/makefile') diff --git a/stm32f091/makefile b/stm32f091/makefile index bf20f00..dd03761 100644 --- a/stm32f091/makefile +++ b/stm32f091/makefile @@ -4,6 +4,7 @@ OC = arm-none-eabi-objcopy RM = rm -f TARGET = main +HOST=$(strip $(shell uname -o)) include ../shared/shared.mk @@ -13,7 +14,6 @@ SHARED_FLAGS += -Wall SHARED_FLAGS += -Wextra # SHARED_FLAGS += -Wno-register SHARED_FLAGS += -Wa,--defsym,CALL_ARM_SYSTEM_INIT=1 -# SHARED_FLAGS += -I/usr/arm-none-eabi/include/ SHARED_FLAGS += -I./lib/STM32-base-STM32Cube/HAL/STM32F0xx/inc SHARED_FLAGS += -I./lib/STM32-base-STM32Cube/HAL/STM32F0xx/inc/Legacy SHARED_FLAGS += -I./lib/STM32-base-STM32Cube/CMSIS/ARM/inc @@ -22,7 +22,10 @@ SHARED_FLAGS += -I./lib/STM32-base/startup SHARED_FLAGS += -I./lib/FreeRTOS-Kernel/include SHARED_FLAGS += -I./lib/FreeRTOS-Kernel/portable/GCC/ARM_CM0/ SHARED_FLAGS += -I. -SHARED_FLAGS += -O1 +ifeq ($(HOST),GNU/Linux) +SHARED_FLAGS += -I/usr/arm-none-eabi/include/ +endif +# SHARED_FLAGS += -O1 SHARED_FLAGS += -ffunction-sections SHARED_FLAGS += -fdata-sections SHARED_FLAGS += -Wl,--gc-sections @@ -89,8 +92,7 @@ $(TARGET).elf: $(OBJS) $(LD) $(LFLAGS) $^ -o $@ flash: $(TARGET).bin - st-flash write $(TARGET).bin 0x08000000 - st-flash reset + st-flash --reset write $(TARGET).bin 0x08000000 compile_commands: clean compiledb make -n -- cgit v1.2.3