diff options
Diffstat (limited to 'stm32f091')
-rw-r--r-- | stm32f091/FreeRTOSConfig.h | 4 | ||||
-rw-r--r-- | stm32f091/main.c | 5 | ||||
-rw-r--r-- | stm32f091/sensor.c | 5 | ||||
-rw-r--r-- | stm32f091/setup.c | 58 | ||||
-rw-r--r-- | stm32f091/setup.h | 7 |
5 files changed, 48 insertions, 31 deletions
diff --git a/stm32f091/FreeRTOSConfig.h b/stm32f091/FreeRTOSConfig.h index b1a692a..223cf8b 100644 --- a/stm32f091/FreeRTOSConfig.h +++ b/stm32f091/FreeRTOSConfig.h @@ -50,7 +50,7 @@ #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) #include <stdint.h> extern uint32_t SystemCoreClock; - // void xPortSysTickHandler(void); + void xPortSysTickHandler(void); #endif #define configUSE_PREEMPTION 1 #define configSUPPORT_STATIC_ALLOCATION 1 @@ -119,7 +119,7 @@ standard names. */ /* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick, to prevent overwriting SysTick_Handler defined within STM32Cube HAL */ -#define xPortSysTickHandler SysTick_Handler +/* #define xPortSysTickHandler SysTick_Handler */ /* USER CODE BEGIN Defines */ /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */ diff --git a/stm32f091/main.c b/stm32f091/main.c index aec5869..9235f1b 100644 --- a/stm32f091/main.c +++ b/stm32f091/main.c @@ -9,6 +9,11 @@ int main() { ws_io_setup(); + HAL_GPIO_Init(GPIOA, &(GPIO_InitTypeDef) { + .Pin = GPIO_PIN_5, + .Mode = GPIO_MODE_OUTPUT_PP, + .Pull = GPIO_NOPULL + }); ws_backlog_alloc(24 * 60); ws_sensor_read(); diff --git a/stm32f091/sensor.c b/stm32f091/sensor.c index 04181cf..77ade64 100644 --- a/stm32f091/sensor.c +++ b/stm32f091/sensor.c @@ -11,8 +11,7 @@ #define REG_HUM ((uint8_t)(0xF5)) uint8_t ws_sensor_temperature() { - HAL_UART_Transmit(&huart2, (uint8_t * const) "hello world!", 13, 100); - return 0; + HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); uint8_t buf[12]; int16_t val; float temp_c; @@ -45,7 +44,7 @@ void ws_sensor_read() { void ws_sensor_read_task() { while (1) { ws_sensor_read(); - vTaskDelay(portTICK_PERIOD_MS * 1000 * 60); + vTaskDelay(portTICK_PERIOD_MS * 1000 * 1); } } diff --git a/stm32f091/setup.c b/stm32f091/setup.c index 5f2db16..ed4ee0b 100644 --- a/stm32f091/setup.c +++ b/stm32f091/setup.c @@ -2,6 +2,8 @@ #include <stm32f0xx_hal_rcc.h> #include <stm32f0xx_hal_i2c.h> #include <stm32f0xx_hal_uart.h> +#include <FreeRTOS.h> +#include <task.h> #include "setup.h" @@ -11,28 +13,17 @@ UART_HandleTypeDef huart2; static void ws_io_clock_setup(); static void ws_io_i2c_setup(); static void ws_io_usart2_setup(); -static void ws_io_gpio_setup(); static void ws_setup_error_handler(); void ws_io_setup() { HAL_Init(); ws_io_clock_setup(); - ws_io_gpio_setup(); ws_io_i2c_setup(); ws_io_usart2_setup(); } static void ws_io_clock_setup() { - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOF_CLK_ENABLE(); - __HAL_RCC_I2C1_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_USART2_CLK_ENABLE(); - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; @@ -74,13 +65,7 @@ static void ws_io_i2c_setup() { hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; if (HAL_I2C_Init(&hi2c1) != HAL_OK) return ws_setup_error_handler(); - - /** Configure Analogue filter - */ if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK) return ws_setup_error_handler(); - - /** Configure Digital filter - */ if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK) return ws_setup_error_handler(); } @@ -98,23 +83,32 @@ static void ws_io_usart2_setup() { if (HAL_UART_Init(&huart2) != HAL_OK) return ws_setup_error_handler(); } -static void ws_io_gpio_setup() { +void HAL_MspInit() { + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); + HAL_NVIC_SetPriority(PendSV_IRQn, 3, 0); +} + +void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) { + if(hi2c->Instance != I2C1) return; + GPIO_InitTypeDef GPIO_InitStruct = {0}; - /**I2C1 GPIO Configuration - PB8 ------> I2C1_SCL - PB9 ------> I2C1_SDA - */ + __HAL_RCC_GPIOB_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; //TODO: use #defines in setup.h GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Alternate = GPIO_AF1_I2C1; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + __HAL_RCC_I2C1_CLK_ENABLE(); +} + +void HAL_UART_MspInit(UART_HandleTypeDef *huart) { + if(huart->Instance != USART2) return; - /**USART2 GPIO Configuration - PA2 ------> USART2_TX - PA3 ------> USART2_RX - */ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + __HAL_RCC_USART2_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = WS_PINOUT_USART_TX_PIN | WS_PINOUT_USART_RX_PIN; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; @@ -123,8 +117,20 @@ static void ws_io_gpio_setup() { HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); } +void SysTick_Handler() { + HAL_IncTick(); + if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) xPortSysTickHandler(); +} + static void ws_setup_error_handler() { __disable_irq(); for(;;); } +void NMI_Handler() { + for(;;); +} + +void HardFault_Handler() { + for(;;); +} diff --git a/stm32f091/setup.h b/stm32f091/setup.h index bca0e82..713ed58 100644 --- a/stm32f091/setup.h +++ b/stm32f091/setup.h @@ -1,5 +1,6 @@ #pragma once +#include <stm32f0xx_hal.h> #include <stm32f0xx_hal_i2c.h> #include <stm32f0xx_hal_uart.h> @@ -17,3 +18,9 @@ extern UART_HandleTypeDef huart2; void ws_io_setup(); +void NMI_Handler(); +void HardFault_Handler(); +void SysTick_Handler(); +void HAL_MspInit(); +void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c); +void HAL_UART_MspInit(UART_HandleTypeDef *huart); |