diff options
Diffstat (limited to 'src/stm32f')
-rw-r--r-- | src/stm32f/Makefile | 2 | ||||
-rw-r--r-- | src/stm32f/includes/Core/delay.h | 33 | ||||
-rw-r--r-- | src/stm32f/src/Core/delay.c | 59 | ||||
-rw-r--r-- | src/stm32f/src/GPIO/temperature.c | 93 | ||||
l--------- | src/stm32f/src/GPIO/tm_stm32f4_ds18b20.c | 1 | ||||
l--------- | src/stm32f/src/GPIO/tm_stm32f4_ds18b20.h | 1 | ||||
l--------- | src/stm32f/src/GPIO/tm_stm32f4_onewire.c | 1 | ||||
l--------- | src/stm32f/src/GPIO/tm_stm32f4_onewire.h | 1 | ||||
l--------- | src/stm32f/tm_stm32f4_ds18b20.c | 1 | ||||
l--------- | src/stm32f/tm_stm32f4_ds18b20.h | 1 | ||||
l--------- | src/stm32f/tm_stm32f4_onewire.c | 1 | ||||
l--------- | src/stm32f/tm_stm32f4_onewire.h | 1 |
12 files changed, 190 insertions, 5 deletions
diff --git a/src/stm32f/Makefile b/src/stm32f/Makefile index a26cdbd..29bf265 100644 --- a/src/stm32f/Makefile +++ b/src/stm32f/Makefile @@ -20,7 +20,7 @@ ASOURCES=$(shell find -L $(SRCDIR) -name '*.s') CSOURCES+=$(shell find -L $(SRCDIR) -name '*.c') # Find header directories INC=$(shell find -L . -name '*.h' -exec dirname {} \; | uniq) -INCLUDES=$(INC:%=-I%) -I ../common/includes/ +INCLUDES=$(INC:%=-I%) -I ../common/includes/ -I ./includes/ # Create object list OBJECTS=$(ASOURCES:%.s=%.o) OBJECTS+=$(CSOURCES:%.c=obj/%.o) diff --git a/src/stm32f/includes/Core/delay.h b/src/stm32f/includes/Core/delay.h new file mode 100644 index 0000000..73ed669 --- /dev/null +++ b/src/stm32f/includes/Core/delay.h @@ -0,0 +1,33 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 Matthias P. Braendli, Maximilien Cuony + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. +*/ + + +// High-precisions delay (with approximations) + + +// Thoses functions works only if interupts are disabled +void delay_us(uint32_t micros); +void delay_ms(uint32_t millis); + +void delay_init(); diff --git a/src/stm32f/src/Core/delay.c b/src/stm32f/src/Core/delay.c new file mode 100644 index 0000000..8c9d24c --- /dev/null +++ b/src/stm32f/src/Core/delay.c @@ -0,0 +1,59 @@ + +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 Matthias P. Braendli, Maximilien Cuony + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. +*/ + + +#include <stdint.h> +#include "stm32f4xx_conf.h" +#include "stm32f4xx.h" + +#ifndef __DELAY_H +#define __DELAY_H + + +uint32_t delay_multiplier = 1; + +void delay_us(uint32_t micros) { + + micros = micros * delay_multiplier - 10; + while (micros--); +} + +void delay_ms(uint32_t millis) { + + for (int i = 0; i < 1000; i++) { + delay_us(millis); + } +} + +void delay_init() { + + RCC_ClocksTypeDef RCC_Clocks; + RCC_GetClocksFreq(&RCC_Clocks); + + delay_multiplier = RCC_Clocks.HCLK_Frequency / 4000000; + +} + +#endif diff --git a/src/stm32f/src/GPIO/temperature.c b/src/stm32f/src/GPIO/temperature.c new file mode 100644 index 0000000..780a019 --- /dev/null +++ b/src/stm32f/src/GPIO/temperature.c @@ -0,0 +1,93 @@ +/* On wire connection: PA1 + */ + +#define TEMPERATURE_ONEWIRE_PIN GPIO_Pin_1 + +#include "stm32f4xx_conf.h" +#include "stm32f4xx.h" + +#include "tm_stm32f4_ds18b20.h" +#include "tm_stm32f4_onewire.h" +#include "Core/delay.h" + + +#include "../../../common/src/GPIO/temperature.c" + +const TickType_t _temperature_delay = 60000 / portTICK_PERIOD_MS; // 60s + +static TM_OneWire_t tm_onewire; + + + +void ds18b20_init() { + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); + + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Pin = TEMPERATURE_ONEWIRE_PIN; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; + GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; + GPIO_Init(GPIOA, &GPIO_InitStructure); + + vTaskSuspendAll(); + TM_OneWire_Init(&tm_onewire, GPIOA, TEMPERATURE_ONEWIRE_PIN); + xTaskResumeAll(); +} + +int ds18b20_gettemp_one(float *temperature) { + + vTaskSuspendAll(); + + uint8_t rom_addr[8]; + + TM_DS18B20_StartAll(&tm_onewire); + int status = TM_OneWire_First(&tm_onewire); + if (status) { + //Save ROM number from device + TM_OneWire_GetFullROM(&tm_onewire, rom_addr); + TM_DS18B20_Start(&tm_onewire, rom_addr); + + // The sensor needs time to do the conversion + xTaskResumeAll(); + delay_ms(100); + vTaskSuspendAll(); + status = TM_DS18B20_Read(&tm_onewire, rom_addr, temperature); + } + + xTaskResumeAll(); + + return status; +} + +int ds18b20_gettemp(float *temperature) { + int status; + for (int i = 0; i < 10; i++) { + status = ds18b20_gettemp_one(temperature); + + if (status) { + break; + } + delay_ms(5); + } + return status; +} + +static void temperature_task(void *pvParameters) { + + while (1) { + + if (!_temperature_valid) { + ds18b20_init(); + } + + if (ds18b20_gettemp(&_temperature_last_value)) { + _temperature_valid = 1; + } else { + _temperature_valid = 0; + } + + vTaskDelay(_temperature_delay); + + } +} diff --git a/src/stm32f/src/GPIO/tm_stm32f4_ds18b20.c b/src/stm32f/src/GPIO/tm_stm32f4_ds18b20.c new file mode 120000 index 0000000..ffa5c2a --- /dev/null +++ b/src/stm32f/src/GPIO/tm_stm32f4_ds18b20.c @@ -0,0 +1 @@ +../../../ds18b20/tm_stm32f4_ds18b20.c
\ No newline at end of file diff --git a/src/stm32f/src/GPIO/tm_stm32f4_ds18b20.h b/src/stm32f/src/GPIO/tm_stm32f4_ds18b20.h new file mode 120000 index 0000000..51c9ece --- /dev/null +++ b/src/stm32f/src/GPIO/tm_stm32f4_ds18b20.h @@ -0,0 +1 @@ +../../../ds18b20/tm_stm32f4_ds18b20.h
\ No newline at end of file diff --git a/src/stm32f/src/GPIO/tm_stm32f4_onewire.c b/src/stm32f/src/GPIO/tm_stm32f4_onewire.c new file mode 120000 index 0000000..241eefa --- /dev/null +++ b/src/stm32f/src/GPIO/tm_stm32f4_onewire.c @@ -0,0 +1 @@ +../../../ds18b20/tm_stm32f4_onewire.c
\ No newline at end of file diff --git a/src/stm32f/src/GPIO/tm_stm32f4_onewire.h b/src/stm32f/src/GPIO/tm_stm32f4_onewire.h new file mode 120000 index 0000000..81ebf8e --- /dev/null +++ b/src/stm32f/src/GPIO/tm_stm32f4_onewire.h @@ -0,0 +1 @@ +../../../ds18b20/tm_stm32f4_onewire.h
\ No newline at end of file diff --git a/src/stm32f/tm_stm32f4_ds18b20.c b/src/stm32f/tm_stm32f4_ds18b20.c deleted file mode 120000 index 1dca5f5..0000000 --- a/src/stm32f/tm_stm32f4_ds18b20.c +++ /dev/null @@ -1 +0,0 @@ -../ds18b20/tm_stm32f4_ds18b20.c
\ No newline at end of file diff --git a/src/stm32f/tm_stm32f4_ds18b20.h b/src/stm32f/tm_stm32f4_ds18b20.h deleted file mode 120000 index 6b8bae8..0000000 --- a/src/stm32f/tm_stm32f4_ds18b20.h +++ /dev/null @@ -1 +0,0 @@ -../ds18b20/tm_stm32f4_ds18b20.h
\ No newline at end of file diff --git a/src/stm32f/tm_stm32f4_onewire.c b/src/stm32f/tm_stm32f4_onewire.c deleted file mode 120000 index 21e6c82..0000000 --- a/src/stm32f/tm_stm32f4_onewire.c +++ /dev/null @@ -1 +0,0 @@ -../ds18b20/tm_stm32f4_onewire.c
\ No newline at end of file diff --git a/src/stm32f/tm_stm32f4_onewire.h b/src/stm32f/tm_stm32f4_onewire.h deleted file mode 120000 index 1779648..0000000 --- a/src/stm32f/tm_stm32f4_onewire.h +++ /dev/null @@ -1 +0,0 @@ -../ds18b20/tm_stm32f4_onewire.h
\ No newline at end of file |