Compare commits

..

21 Commits

Author SHA1 Message Date
f8076920fe Start doxygen documentation 2020-02-16 17:35:41 +01:00
9629c08da2 Add doxygen 2020-02-16 16:52:21 +01:00
a35f66f2cd Add code for rotary encoder 2020-02-16 16:38:31 +01:00
6fa071e1d1 Add rotary encoder module 2020-02-16 14:25:49 +01:00
47daf495bd Remove random calibration try 2020-02-16 14:21:40 +01:00
7ade829a70 Make ring buffers volatile 2020-02-16 11:42:18 +01:00
1d62bc22b8 Increase programming clock freq to 4 MHz 2020-02-16 00:42:00 +01:00
6ed7a4886d change programming speed to 1 MHz in order to prevent communication errors 2020-02-15 23:17:41 +01:00
3781ecb669 Update programming scripts 2020-02-15 23:09:23 +01:00
4c5b3add1d Add scripts for device programming using JLINK 2020-02-15 22:25:53 +01:00
c3be39b4e5 Add license header to all files 2020-02-15 22:09:55 +01:00
43473efcdd Add fallthrough warning for switch cases explicitly to CFLAGS 2020-02-15 21:06:45 +01:00
7df97831be Add conversion function for resistance to temperature conversion and add it to thept command of the shell 2020-02-15 20:31:38 +01:00
92526e71b2 Merge branch 'dev' of git.shimatta.de:mhu/reflow-oven-control-sw into dev 2020-02-15 17:55:31 +01:00
b13b3b4377 Add script for generating PT1000 lookup dat and generate first header file 2020-02-15 17:54:45 +01:00
c568b95cf2 Add calibration routine from shell 2020-02-15 17:54:13 +01:00
c565dab3ad Add calibration routine from shell 2020-02-15 17:53:15 +01:00
5a00950589 Add deactivated PT1000 measurement as error flag, startcode for calibration routine 2020-02-15 01:04:40 +01:00
b497537a78 Increse heap and stack sizes 2020-02-15 01:03:38 +01:00
723afd9f56 Fix arm math header 2020-02-15 01:03:19 +01:00
ebb95b902c Add python script that creates matching c and h files 2020-02-14 20:39:50 +01:00
37 changed files with 3804 additions and 71 deletions

View File

@ -10,12 +10,12 @@ INCLUDEPATH = -Icmsis -Iinclude
OBJDIR = obj
target = reflow-controller
LIBRARYPATH = -L. -Lmathlib
LIBRARIES = -larm_cortexM4lf_math
LIBRARIES = -larm_cortexM4lf_math -lm
DEFINES = -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4 -DHSE_VALUE=8000000UL
mapfile = memory-mapping
GIT_VER := $(shell git describe --always --dirty --tags)
export GIT_VER = $(shell git describe --always --dirty --tags)
DEFINES += -DGIT_VER=$(GIT_VER)
ifneq ($(VERBOSE),true)
@ -41,6 +41,12 @@ CFILES += digio.c
CFILES += stm-periph/unique-id.c
CFILES += calibration.c
CFILES += temp-converter.c
CFILES += rotary-encoder.c
DEFINES += -DDEBUGBUILD
#TODO
@ -56,7 +62,7 @@ LFLAGS += -Tstm32f407vet6_flash.ld -Wl,-Map=$(mapfile).map
CFLAGS = -c -fmessage-length=0 -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles -O0 -g
CFLAGS += -Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter
CFLAGS += -Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter -Wimplicit-fallthrough=3 -Wsign-compare
####################################################################################
OBJ = $(CFILES:%.c=$(OBJDIR)/%.c.o)
@ -75,6 +81,7 @@ $(target).elf: $(OBJ) $(ASOBJ)
@echo [LD] $@
$(QUIET)$(CC) $(LFLAGS) $(LIBRARYPATH) -o $@ $^ $(LIBRARIES)
$(QUIET)$(SIZE) $@
@echo "Built Version $(GIT_VER)"
#Compiling
$(OBJ):

View File

@ -1,3 +1,23 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <reflow-controller/adc-meas.h>
#include <stm32/stm32f4xx.h>
#include <cmsis/core_cm4.h>
@ -11,13 +31,16 @@ static bool calibration_active;
static float filter_alpha;
static volatile float pt1000_res_raw_lf;
static volatile bool filter_ready;
static volatile enum adc_pt1000_error pt1000_error;
static volatile uint8_t * volatile streaming_flag_ptr = NULL;
static volatile enum adc_pt1000_error pt1000_error = ADC_PT1000_INACTIVE;
static volatile int * volatile streaming_flag_ptr = NULL;
static uint32_t filter_startup_cnt;
static volatile float adc_pt1000_raw_reading_hf;
static volatile bool pt1000_measurement_active = false;
static volatile uint16_t dma_sample_buffer[ADC_PT1000_DMA_AVG_SAMPLES];
volatile float * volatile stream_buffer = NULL;
volatile uint32_t stream_count;
volatile uint32_t stream_pos;
#define ADC_TO_RES(adc) ((float)(adc) / 4096.0f * 2500.0f)
static inline void adc_pt1000_stop_sample_frequency_timer()
@ -49,7 +72,7 @@ static inline void adc_pt1000_disable_adc()
ADC1->CR2 &= ~ADC_CR2_ADON;
DMA2_Stream0->CR = 0;
pt1000_measurement_active = false;
pt1000_error |= ADC_PT1000_INACTIVE;
rcc_manager_disable_clock(&RCC->APB2ENR, BITMASK_TO_BITNO(RCC_APB2ENR_ADC1EN));
rcc_manager_disable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(ADC_PT1000_PORT_RCC_MASK));
@ -88,7 +111,7 @@ static inline void adc_pt1000_enable_dma_stream()
* Todo: Maybe use twice as big of a buffer and also use half-fill interrupt in order to prevent overruns
*/
DMA2_Stream0->CR = DMA_SxCR_PL_1 | DMA_SxCR_MSIZE_0 | DMA_SxCR_PSIZE_0 | DMA_SxCR_MINC |
DMA_SxCR_CIRC | DMA_SxCR_TCIE | DMA_SxCR_EN;
DMA_SxCR_CIRC | DMA_SxCR_TCIE | DMA_SxCR_TEIE | DMA_SxCR_EN;
}
static inline void adc_pt1000_disable_dma_stream()
@ -142,7 +165,7 @@ void adc_pt1000_setup_meas()
adc_pt1000_setup_sample_frequency_timer();
pt1000_measurement_active = true;
pt1000_error &= ~ADC_PT1000_INACTIVE;
}
void adc_pt1000_set_moving_average_filter_param(float alpha)
@ -201,17 +224,40 @@ return_value:
return ret_val;
}
/*
int adc_pt1000_stream_raw_value_to_memory(float *adc_array, uint32_t length, volatile uint8_t *flag_to_set)
int adc_pt1000_stream_raw_value_to_memory(volatile float *adc_array, uint32_t length, volatile int *flag_to_set)
{
return -1;
int ret = 0;
if (!flag_to_set)
return -1;
stream_buffer = adc_array;
stream_count = length;
stream_pos = 0U;
if (adc_array) {
*flag_to_set = 0;
streaming_flag_ptr = flag_to_set;
} else {
ret = -2;
}
return ret;
}
void adc_pt1000_convert_raw_value_array_to_resistance(float *resistance_dest, float *raw_source, uint32_t count)
{
uint32_t i;
if (!resistance_dest)
resistance_dest = raw_source;
if (!raw_source || !count)
return;
for (i = 0; i < count; i++)
resistance_dest[i] = ADC_TO_RES(raw_source[i]);
}
*/
enum adc_pt1000_error adc_pt1000_check_error()
{
@ -220,7 +266,7 @@ enum adc_pt1000_error adc_pt1000_check_error()
void adc_pt1000_clear_error()
{
pt1000_error = ADC_PT1000_NO_ERR;
pt1000_error &= ~ADC_PT1000_OVERFLOW & ~ADC_PT1000_WATCHDOG_ERROR;
}
void adc_pt1000_disable()
@ -231,6 +277,7 @@ void adc_pt1000_disable()
filter_ready = false;
pt1000_res_raw_lf = 0.0f;
pt1000_error |= ADC_PT1000_INACTIVE;
if (streaming_flag_ptr) {
*streaming_flag_ptr = -3;
@ -283,10 +330,6 @@ void ADC_IRQHandler(void)
pt1000_error |= ADC_PT1000_OVERFLOW;
/* Disable ADC in case of overrrun*/
adc_pt1000_disable();
if (streaming_flag_ptr) {
*streaming_flag_ptr = -1;
streaming_flag_ptr = NULL;
}
}
if (adc1_sr & ADC_SR_AWD) {
@ -295,6 +338,21 @@ void ADC_IRQHandler(void)
}
}
static void append_stream_buffer(float val)
{
if (!stream_buffer || !streaming_flag_ptr)
return;
if (stream_pos < stream_count)
stream_buffer[stream_pos++] = val;
if (stream_pos >= stream_count) {
*streaming_flag_ptr = 1;
streaming_flag_ptr = NULL;
}
}
void DMA2_Stream0_IRQHandler()
{
uint32_t lisr;
@ -308,13 +366,15 @@ void DMA2_Stream0_IRQHandler()
adc_val = adc_pt1000_dma_avg_pre_filter();
adc_pt1000_raw_reading_hf = adc_val;
if (streaming_flag_ptr)
append_stream_buffer(adc_val);
/* Call moving average filter */
adc_pt1000_filter(adc_val);
}
if (lisr & DMA_LISR_TEIF0) {
/* Wait for watchdog to kick in */
while(1);
adc_pt1000_disable();
}
}

171
stm-firmware/calibration.c Normal file
View File

@ -0,0 +1,171 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <reflow-controller/calibration.h>
#include <reflow-controller/adc-meas.h>
#include <stm-periph/uart.h>
#include <helper-macros/helper-macros.h>
#include <arm_math.h>
#include <stdlib.h>
#include <float.h>
void calibration_calculate(float low_measured, float low_setpoint, float high_measured, float high_setpoint,
float *sens_deviation, float *sens_corrected_offset)
{
if (!sens_deviation || !sens_corrected_offset)
return;
float delta_y;
float delta_x;
float sens_corr_mult;
delta_y = high_measured - low_measured;
delta_x = high_setpoint - low_setpoint;
sens_corr_mult = delta_x / delta_y;
*sens_deviation = sens_corr_mult - 1.0f;
*sens_corrected_offset = low_setpoint - low_measured * sens_corr_mult;
}
int calibration_acquire_data(float *mu, float *max_dev, uint32_t count)
{
int status;
float *stream_mem;
float min_val = FLT_MAX;
float max_val = -FLT_MAX;
uint32_t i;
int ret_val = 0;
static volatile int flag = 0;
if (!mu || !max_dev || !count)
return -1000;
stream_mem = (float *)calloc(count, sizeof(float));
if (!stream_mem)
return -2;
status = adc_pt1000_stream_raw_value_to_memory(stream_mem, count, &flag);
if (status)
return status;
/* Wait for data to be transferred */
while (flag == 0);
if (flag != 1) {
/* Error */
ret_val = -1;
goto ret_free_mem;
}
/* Convert the stream memory to Ohm readings */
adc_pt1000_convert_raw_value_array_to_resistance(NULL, stream_mem, count);
/* Do not compute std-deviation. Too imprecise
* arm_std_f32(stream_mem, count, sigma);
*/
arm_mean_f32(stream_mem, count, mu);
/* Find min and max values of array */
for (i = 0U; i < count; i++) {
min_val = MIN(min_val, stream_mem[i]);
max_val = MAX(max_val, stream_mem[i]);
}
/* Compute maximum deviation range */
*max_dev = max_val - min_val;
ret_free_mem:
free(stream_mem);
return ret_val;
}
static void wait_for_uart_enter()
{
int enter_received = 0;
const char *recv_data;
size_t recv_len;
size_t iter;
int uart_recv_status;
do {
uart_recv_status = uart_receive_data_with_dma(&recv_data, &recv_len);
if (uart_recv_status >= 1) {
for (iter = 0; iter < recv_len; iter++) {
if (recv_data[iter] == '\n' || recv_data[iter] == '\r')
enter_received = 1;
}
}
} while (enter_received == 0);
}
int calibration_sequence_shell_cmd(shellmatta_handle_t shell)
{
float mu, mu2, dev, dev2;
float sens_dev, offset;
/* Clear errors of PT1000 reading */
adc_pt1000_clear_error();
shellmatta_printf(shell, "Starting calibration: Insert 1000 Ohm calibration resistor and press ENTER\r\n");
wait_for_uart_enter();
shellmatta_printf(shell, "Measurement...\r\n");
/* Clear errors of PT1000 reading */
adc_pt1000_clear_error();
calibration_acquire_data(&mu, &dev, 512UL);
shellmatta_printf(shell, "R=%.2f, Noise peak-peak: %.2f\r\n", mu, dev);
if (adc_pt1000_check_error() != ADC_PT1000_NO_ERR) {
shellmatta_printf(shell, "Error in resistance measurement: %d", adc_pt1000_check_error());
return -1;
}
/* Measure 2nd calibration point */
shellmatta_printf(shell, "Insert 2000 Ohm calibration resistor and press ENTER\r\n");
wait_for_uart_enter();
shellmatta_printf(shell, "Measurement...\r\n");
/* Clear errors of PT1000 reading */
adc_pt1000_clear_error();
calibration_acquire_data(&mu2, &dev2, 512UL);
shellmatta_printf(shell, "R=%.2f, Noise peak-peak: %.2f\r\n", mu2, dev2);
if (adc_pt1000_check_error() != ADC_PT1000_NO_ERR) {
shellmatta_printf(shell, "Error in resistance measurement: %d", adc_pt1000_check_error());
return -2;
}
/* Check noise values */
if (dev > CALIBRATION_MAX_PEAK_PEAK_NOISE_OHM || dev2 > CALIBRATION_MAX_PEAK_PEAK_NOISE_OHM) {
shellmatta_printf(shell, "Calibration failed! Too much noise. Check you're hardware.\r\n");
return -3;
}
/* Calculate calibration */
calibration_calculate(mu, 1000.0f, mu2, 2000.0f, &sens_dev, &offset);
shellmatta_printf(shell, "Calibration done:\r\n\tSENS_DEVIATION: %.4f\r\n\tOFFSET_CORR: %.2f\r\n", sens_dev, offset);
adc_pt1000_set_resistance_calibration(offset, sens_dev, true);
return 0;
}

View File

@ -0,0 +1,61 @@
#!/usr/bin/env python3
import os
import sys
license_header = """/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
"""
project_dir = os.path.dirname(os.path.realpath(__file__))
include_prefix = 'reflow-controller'
module_include_dir = os.path.join(project_dir, os.path.join('include', include_prefix))
if len(sys.argv) < 2:
print('Supply module name')
sys.exit()
cpath = os.path.join(project_dir, sys.argv[1]+'.c')
hfile = sys.argv[1]+'.h'
hpath = os.path.join(module_include_dir, hfile)
h_define = '__'+hfile.replace('.', '_').replace('-', '_').upper()+'__'
if os.path.exists(cpath) or os.path.exists(hpath):
print("File already exists! Abort!")
sys.exit()
print('Creating C file: %s' % (cpath))
with open(cpath, 'x') as f:
f.write(license_header)
f.write('\n')
f.write('#include <%s>' % (os.path.join(include_prefix, hfile)))
print('Creating H file: %s' % (hpath))
with open(hpath, 'x') as f:
f.write(license_header)
f.write('\n')
f.write('#ifndef %s\n' % h_define)
f.write('#define %s\n' % h_define)
f.write('\n')
f.write('#endif /* %s */\n' % h_define)

View File

@ -0,0 +1,74 @@
#!/usr/bin/env python3
import os
import sys
import numpy as np
license_header = """/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
"""
hfile="temp-converter-data.h"
project_dir = os.path.dirname(os.path.realpath(__file__))
include_prefix = 'reflow-controller'
module_include_dir = os.path.join(project_dir, os.path.join('include', include_prefix))
include_file = os.path.join(module_include_dir, hfile)
h_define = '__'+hfile.replace('.', '_').replace('-', '_').upper()+'__'
min_res = 1000
max_res = 2200
res_step = 20
R_zero = 1000.0
A = 3.9083E-3
B = -5.7750E-7
def calc_temp(resistance):
temp = (-R_zero * A + np.sqrt(R_zero*R_zero * A * A - 4* R_zero * B * (R_zero - resistance)))/(2*R_zero*B)
return temp
if ((max_res-min_res) % res_step) != 0:
print('Resistance range must be a multiple of res_step!')
sys.exit(-1)
print('Calculating temperature table for %f Ohm to %f Ohm in %f Ohm steps' % (min_res, max_res, res_step))
temp_array = ''
for res in range(min_res, max_res+res_step, res_step):
temp = calc_temp(res)
temp_array = temp_array+ ',%.2ff' % temp
temp_array = temp_array[1:]
with open(include_file, 'x') as f:
f.write(license_header)
f.write('\n')
f.write('#ifndef %s\n' % h_define)
f.write('#define %s\n\n' % h_define)
f.write('#define TEMP_CONVERSION_ARRAY_DATA %s\n' % temp_array)
f.write('#define TEMP_CONVERSION_MIN_RES %d\n' % min_res)
f.write('#define TEMP_CONVERSION_MAX_RES %d\n' % max_res)
f.write('#define TEMP_CONVERSION_RES_STEP %d\n' % res_step)
f.write('\n')
f.write('#endif /* %s */\n' % h_define)

View File

@ -1,3 +1,23 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <reflow-controller/digio.h>
#include <stm32/stm32f4xx.h>
#include <stm-periph/clock-enable-manager.h>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,20 @@
#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )"
cd "$DIR"
export PROJECT_NUMBER=`git describe --always --tags --dirty`
if [ $# != 1 ]; then
export OUTPUT_DIRECTORY="./output"
else
export OUTPUT_DIRECTORY="$1"
fi
doxygen Doxyconfig

View File

@ -0,0 +1,3 @@
*
*/
!.gitignore

View File

@ -267,7 +267,7 @@
#define __CMSIS_GENERIC /* disable NVIC and Systick functions */
#if defined (ARM_MATH_CM4)
#include "core_cm4.h"
#include <cmsis/core_cm4.h>
#elif defined (ARM_MATH_CM3)
#include "core_cm3.h"
#elif defined (ARM_MATH_CM0)
@ -282,8 +282,8 @@
#endif
#undef __CMSIS_GENERIC /* enable NVIC and Systick functions */
#include "string.h"
#include "math.h"
#include <string.h>
#include <math.h>
#ifdef __cplusplus
extern "C"
{

View File

@ -1,3 +1,23 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __HELPER_MACROS_H__
#define __HELPER_MACROS_H__
@ -11,4 +31,7 @@
#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif /* __HELPER_MACROS_H__ */

View File

@ -1,3 +1,23 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ADCMEAS_H__
#define __ADCMEAS_H__
@ -39,7 +59,7 @@
*/
#define ADC_PT1000_UPPER_WATCHDOG 4000U
enum adc_pt1000_error {ADC_PT1000_NO_ERR= 0, ADC_PT1000_WATCHDOG_ERROR=(1UL<<0), ADC_PT1000_OVERFLOW=(1UL<<1)};
enum adc_pt1000_error {ADC_PT1000_NO_ERR= 0, ADC_PT1000_WATCHDOG_ERROR=(1UL<<0), ADC_PT1000_OVERFLOW=(1UL<<1), ADC_PT1000_INACTIVE = (1UL<<2)};
/**
* @brief This function sets up the ADC measurement fo the external PT1000 temperature sensor
@ -102,16 +122,12 @@ int adc_pt1000_get_current_resistance(float *resistance);
/**
* @brief Stream the raw ADC data to an array in memory.
*
* Streaming is done using DMA2 Stream0.
* This function is used for gathering fullspeed sampling data for external interfaces or calibration
*
* @param adc_array Array to stream data to
* @param length Amount of data points to be measured
* @param flag_to_set This flag is set to 1 once the data has been measured and is transferred. A negative value indicates an error
* @return 0 if measurement could be started
*/
int adc_pt1000_stream_raw_value_to_memory(float *adc_array, uint32_t length, volatile uint8_t *flag_to_set);
int adc_pt1000_stream_raw_value_to_memory(volatile float *adc_array, uint32_t length, volatile int *flag_to_set);
void adc_pt1000_convert_raw_value_array_to_resistance(float *resistance_dest, float *raw_source, uint32_t count);

View File

@ -0,0 +1,36 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __CALIBRATION_H__
#define __CALIBRATION_H__
#define CALIBRATION_MAX_PEAK_PEAK_NOISE_OHM 8.0f
#include <stdint.h>
#include <shellmatta.h>
void calibration_calculate(float low_measured, float low_setpoint, float high_measured, float high_setpoint,
float *sens_deviation, float *sens_corrected_offset);
int calibration_acquire_data(float *mu, float *max_dev, uint32_t count);
int calibration_sequence_shell_cmd(shellmatta_handle_t shell);
#endif /* __CALIBRATION_H__ */

View File

@ -1,3 +1,23 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __DIGIO_H__
#define __DIGIO_H__

View File

@ -0,0 +1,42 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ROTARY_ENCODER_H__
#define __ROTARY_ENCODER_H__
#include <stm32/stm32f4xx.h>
#define ROTARY_ENCODER_TIMER TIM5
#define ROTARY_ENCODER_TIMER_RCC_MASK RCC_APB1ENR_TIM5EN
#define ROTARY_ENCODER_PIN1 0
#define ROTARY_ENCODER_PIN2 1
#define ROTARY_ENCODER_PORT GPIOA
#define ROTARY_ENCODER_PORT_ALTFUNC 2
#define ROTARY_ENCODER_RCC_MASK RCC_AHB1ENR_GPIOAEN
void rotary_encoder_setup(void);
uint32_t rotary_encoder_get_abs_val(void);
int32_t rotary_encoder_get_chage_val(void);
void rotary_encoder_stop(void);
#endif /* __ROTARY_ENCODER_H__ */

View File

@ -1,3 +1,23 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SHELL_H__
#define __SHELL_H__

View File

@ -1,3 +1,27 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file systick.h
*/
#ifndef __SYSTICK_H__
#define __SYSTICK_H__

View File

@ -0,0 +1,29 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __TEMP_CONVERTER_DATA_H__
#define __TEMP_CONVERTER_DATA_H__
#define TEMP_CONVERSION_ARRAY_DATA -0.00f,5.12f,10.25f,15.39f,20.53f,25.68f,30.84f,36.01f,41.19f,46.37f,51.57f,56.77f,61.98f,67.19f,72.42f,77.65f,82.89f,88.14f,93.40f,98.67f,103.94f,109.23f,114.52f,119.82f,125.13f,130.45f,135.77f,141.11f,146.45f,151.81f,157.17f,162.54f,167.92f,173.31f,178.71f,184.11f,189.53f,194.96f,200.39f,205.84f,211.29f,216.75f,222.22f,227.71f,233.20f,238.70f,244.21f,249.73f,255.26f,260.80f,266.35f,271.91f,277.48f,283.06f,288.65f,294.25f,299.86f,305.48f,311.11f,316.75f,322.40f
#define TEMP_CONVERSION_MIN_RES 1000
#define TEMP_CONVERSION_MAX_RES 2200
#define TEMP_CONVERSION_RES_STEP 20
#endif /* __TEMP_CONVERTER_DATA_H__ */

View File

@ -0,0 +1,32 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __TEMP_CONVERTER_H__
#define __TEMP_CONVERTER_H__
/**
* @brief Convert PT1000 resistance to temperature in degrees celsius
* @param resistance PT1000 resistance value
* @param[out] temp_out Temperature output
* @return 0 if ok, -1 if value is below conversion range, 1 if value is above conversion range,-1000 in case of pointer error
*/
int temp_converter_convert_resistance_to_temp(float resistance, float *temp_out);
#endif /* __TEMP_CONVERTER_H__ */

View File

@ -1,3 +1,23 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __CLOCK_ENABLE_MANAGER_H__
#define __CLOCK_ENABLE_MANAGER_H__

View File

@ -1,3 +1,32 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file dma-ring-buffer.h
* @brief Header for DMA Ring buffer implemenation
*/
/**
* @defgroup dma-ring-buffer DMA Ring Buffers from and to Peripherals
*/
#ifndef __DMA_RING_BUFFER_H__
#define __DMA_RING_BUFFER_H__
@ -5,11 +34,16 @@
#include <stm32/stm32f4xx.h>
#include <stddef.h>
/**
* @addtogroup dma-ring-buffer
* @{
*/
/**
* @brief DMA ring buffer for data transfer from peripheral to memory
*/
struct dma_ring_buffer_to_mem {
void *data_ptr; /**< @brief Ring buffer */
volatile void *data_ptr; /**< @brief Ring buffer */
size_t buffer_count; /**< @brief Size of buffer in multiples of elements */
DMA_Stream_TypeDef *dma; /**< @brief DMA Stream used to transfer data */
size_t get_idx; /**< @brief Get index for SW. Indicates the next element to be read */
@ -21,7 +55,7 @@ struct dma_ring_buffer_to_mem {
* @brief DMA ring buffer for data transfer from memory to peripheral
*/
struct dma_ring_buffer_to_periph {
void *src_buffer; /**< @brief Ring buffer */
volatile void *src_buffer; /**< @brief Ring buffer */
size_t buffer_count; /**< @brief Size of buffer in multiples of elements */
DMA_Stream_TypeDef *dma; /**< @brief DMA Stream used to transfer data */
volatile size_t dma_get_idx_current; /**< @brief Current get index of the (not yet) running DMA Stream. */
@ -44,16 +78,16 @@ struct dma_ring_buffer_to_periph {
* @note The ring buffers do not have an overrun detection. You have to make sure to empty the buffer in time.
* @return Status (0 is ok)
*/
int dma_ring_buffer_periph_to_mem_initialize(struct dma_ring_buffer_to_mem *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, void *data_buffer, void *src_reg, uint8_t dma_trigger_channel);
int dma_ring_buffer_periph_to_mem_initialize(struct dma_ring_buffer_to_mem *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, volatile void *data_buffer, void *src_reg, uint8_t dma_trigger_channel);
/**
* @brief Get data from a peripheral to memory ring buffer
* @param[in] buff Ring buffer structure
* @param[out] data_buff Pointer to set to new data. This must not be modified!
* @param[out] len Length in elements
* @return 0 if successful (data, no data), -1 if error, and 1 if data with wrap around. Call function again in this case to retrieve rest after wrap around.
* @return 0 if successful, but no data), -1 if error, 1 if data, and 2 if data with wrap around. Call function again in this case to retrieve rest after wrap around.
*/
int dma_ring_buffer_periph_to_mem_get_data(struct dma_ring_buffer_to_mem *buff, const void **data_buff, size_t *len);
int dma_ring_buffer_periph_to_mem_get_data(struct dma_ring_buffer_to_mem *buff, const volatile void **data_buff, size_t *len);
/**
* @brief Stop the ring buffer operation.
@ -74,7 +108,7 @@ void dma_ring_buffer_periph_to_mem_stop(struct dma_ring_buffer_to_mem *buff);
* @param[in] dest_reg Destination register to stream data to
* @return 0 if successful
*/
int dma_ring_buffer_mem_to_periph_initialize(struct dma_ring_buffer_to_periph *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, void *data_buffer, uint8_t dma_trigger_channel, void *dest_reg);
int dma_ring_buffer_mem_to_periph_initialize(struct dma_ring_buffer_to_periph *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, volatile void *data_buffer, uint8_t dma_trigger_channel, void *dest_reg);
/**
* @brief Insert data into the ring buffer
@ -104,6 +138,8 @@ void dma_ring_buffer_mem_to_periph_int_callback(struct dma_ring_buffer_to_periph
*/
void dma_ring_buffer_mem_to_periph_stop(struct dma_ring_buffer_to_periph *buff);
/** @} */
#endif /* __DMA_RING_BUFFER_H__ */

View File

@ -1,3 +1,23 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __STM32GPIOMACROS_H__
#define __STM32GPIOMACROS_H__

View File

@ -1,3 +1,23 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stddef.h>

View File

@ -1,3 +1,23 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __UNIQUE_ID_H__
#define __UNIQUE_ID_H__

View File

@ -1,3 +1,28 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file main.c
* @brief Main file for firmware
*/
#include <stdlib.h>
#include <string.h>
/* #include <arm_math.h> */
@ -8,6 +33,7 @@
#include <reflow-controller/adc-meas.h>
#include <reflow-controller/shell.h>
#include <reflow-controller/digio.h>
#include <reflow-controller/rotary-encoder.h>
#include <stm-periph/stm32-gpio-macros.h>
#include <stm-periph/clock-enable-manager.h>
#include <stm-periph/uart.h>
@ -25,12 +51,15 @@ static void setup_nvic_priorities()
static float pt1000_value;
static volatile int pt1000_value_status;
static uint32_t rot;
int main()
{
const char *uart_input;
size_t uart_input_len;
shellmatta_handle_t shell_handle;
int uart_receive_status;
setup_nvic_priorities();
systick_setup();
@ -40,6 +69,7 @@ int main()
digio_setup_default_all();
led_setup();
loudspeaker_setup();
rotary_encoder_setup();
uart_init_with_dma();
@ -47,11 +77,10 @@ int main()
while(1) {
pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value);
if (uart_receive_data_with_dma(&uart_input, &uart_input_len) >= 0) {
rot = rotary_encoder_get_abs_val();
uart_receive_status = uart_receive_data_with_dma(&uart_input, &uart_input_len);
if (uart_receive_status >= 1)
shell_handle_input(shell_handle, uart_input, uart_input_len);
}
//systick_wait_ms(300);
}
}

View File

@ -0,0 +1,8 @@
target extended-remote :2331
monitor speed 4000
monitor reset
load
monitor reset
kill
quit

18
stm-firmware/program-device.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
JLinkGDBServer -if SWD -device STM32F407VE &
sleep 2
# Check if GDB server is still running
gdbpid=`pidof JLinkGDBServer`
if [[ $gdbpid == "" ]]; then
echo ""
echo "GDB Server not running! Check target connection."
exit
fi
arm-none-eabi-gdb -x program-device.gdb reflow-controller.elf
sleep 2
kill $gdbpid

View File

@ -0,0 +1,78 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <reflow-controller/rotary-encoder.h>
#include <stm-periph/clock-enable-manager.h>
#include <stm-periph/stm32-gpio-macros.h>
static inline void rotary_encoder_setup_pins(void)
{
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(ROTARY_ENCODER_RCC_MASK));
ROTARY_ENCODER_PORT->MODER &= MODER_DELETE(ROTARY_ENCODER_PIN1) & MODER_DELETE(ROTARY_ENCODER_PIN2);
ROTARY_ENCODER_PORT->MODER |= ALTFUNC(ROTARY_ENCODER_PIN1) | ALTFUNC(ROTARY_ENCODER_PIN2);
SETAF(ROTARY_ENCODER_PORT, ROTARY_ENCODER_PIN1, ROTARY_ENCODER_PORT_ALTFUNC);
SETAF(ROTARY_ENCODER_PORT, ROTARY_ENCODER_PIN2, ROTARY_ENCODER_PORT_ALTFUNC);
}
void rotary_encoder_setup(void)
{
rcc_manager_enable_clock(&RCC->APB1ENR, BITMASK_TO_BITNO(ROTARY_ENCODER_TIMER_RCC_MASK));
rotary_encoder_setup_pins();
ROTARY_ENCODER_TIMER->ARR = 0xFFFF;
ROTARY_ENCODER_TIMER->CNT = 0;
ROTARY_ENCODER_TIMER->CR2 = 0;
ROTARY_ENCODER_TIMER->SMCR = TIM_SMCR_SMS_0 | TIM_SMCR_SMS_1;
ROTARY_ENCODER_TIMER->CCMR1 = TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_0;
ROTARY_ENCODER_TIMER->CCER = TIM_CCER_CC1P | TIM_CCER_CC2P;
ROTARY_ENCODER_TIMER->PSC = 0;
ROTARY_ENCODER_TIMER->CR1 = TIM_CR1_CEN;
}
uint32_t rotary_encoder_get_abs_val(void)
{
return (uint32_t)ROTARY_ENCODER_TIMER->CNT;
}
int32_t rotary_encoder_get_chage_val(void)
{
static uint32_t last_val = 0;
uint32_t val;
int32_t diff;
val = rotary_encoder_get_abs_val();
diff = val - last_val;
if (diff > 0xEFFF) {
diff = 0xFFFF - diff;
}
return diff;
}
void rotary_encoder_stop(void)
{
ROTARY_ENCODER_TIMER->CR1 = 0;
ROTARY_ENCODER_TIMER->CR2 = 0;
ROTARY_ENCODER_TIMER->ARR = 0;
rcc_manager_disable_clock(&RCC->APB1ENR, BITMASK_TO_BITNO(ROTARY_ENCODER_TIMER_RCC_MASK));
rcc_manager_disable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(ROTARY_ENCODER_RCC_MASK));
}

View File

@ -1,3 +1,23 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <reflow-controller/shell.h>
#include <stm-periph/uart.h>
#include <string.h>
@ -7,6 +27,8 @@
#include <helper-macros/helper-macros.h>
#include <reflow-controller/systick.h>
#include <stm-periph/unique-id.h>
#include <reflow-controller/calibration.h>
#include <reflow-controller/temp-converter.h>
#ifndef GIT_VER
#define GIT_VER "VERSION NOT SET"
@ -103,25 +125,46 @@ static shellmatta_retCode_t shell_cmd_pt1000_res(const shellmatta_handle_t han
(void)length;
float resistance;
int pt1000_status;
const char *display_status;
enum adc_pt1000_error pt1000_flags;
const char *status_text[] = {"VALID", "WATCHDOG", "DATA-OVERFLOW", "UNSTABLE"};
char display_status[100];
float temp;
int temp_conv_status;
const char *temp_prefix;
display_status[0] = 0;
display_status = status_text[0];
pt1000_status = adc_pt1000_get_current_resistance(&resistance);
if (pt1000_status == 2) {
display_status = status_text[3];
strcat(display_status, " UNSTABLE ");
} else if (pt1000_status) {
pt1000_flags = adc_pt1000_check_error();
if (pt1000_flags & ADC_PT1000_WATCHDOG_ERROR)
display_status = status_text[1];
if (pt1000_flags & ADC_PT1000_INACTIVE)
strcat(display_status, " DEACTIVATED ");
else if (pt1000_flags & ADC_PT1000_WATCHDOG_ERROR)
strcat(display_status, " WATCHDOG ");
else if (pt1000_flags & ADC_PT1000_OVERFLOW)
display_status = status_text[2];
strcat(display_status, " OVERFLOW ");
} else {
strcpy(display_status, "VALID");
}
shellmatta_printf(handle, "PT1000 resistance: %.2f Ohm [%s]\r\n", resistance, display_status);
temp_conv_status = temp_converter_convert_resistance_to_temp(resistance, &temp);
switch (temp_conv_status) {
case 1:
temp_prefix = ">";
break;
case -1:
temp_prefix = "<";
break;
case 0:
/* FALLTHRU */
default:
temp_prefix = "";
break;
}
shellmatta_printf(handle, "PT1000 resistance: %.2f Ohm (%s%.1f °C) [%s]\r\n", resistance, temp_prefix,temp, display_status);
return SHELLMATTA_OK;
}
@ -147,6 +190,17 @@ static shellmatta_retCode_t shell_cmd_uptime(const shellmatta_handle_t handle,
shellmatta_printf(handle, "Uptime: %llu secs", global_tick_ms/1000);
return SHELLMATTA_OK;
}
static shellmatta_retCode_t shell_cmd_cal(const shellmatta_handle_t handle,
const char *arguments,
uint32_t length)
{
(void)arguments;
(void)length;
calibration_sequence_shell_cmd(handle);
return SHELLMATTA_OK;
}
//typedef struct shellmatta_cmd
//{
// char *cmd; /**< command name */
@ -157,7 +211,7 @@ static shellmatta_retCode_t shell_cmd_uptime(const shellmatta_handle_t handle,
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
//} shellmatta_cmd_t;
static shellmatta_cmd_t cmd[6] = {
static shellmatta_cmd_t cmd[7] = {
{
.cmd = "version",
.cmdAlias = "ver",
@ -204,8 +258,16 @@ static shellmatta_cmd_t cmd[6] = {
.helpText = "Get uptime in seconds",
.usageText = "",
.cmdFct = shell_cmd_uptime,
.next = NULL,
.next = &cmd[6],
},
{
.cmd = "calibrate",
.cmdAlias = "cal",
.helpText = "Calibrate resistance measurement",
.usageText = "",
.cmdFct = shell_cmd_cal,
.next = NULL,
}
};
shellmatta_handle_t shell_init(void)

View File

@ -1,3 +1,23 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stm-periph/clock-enable-manager.h>
#include <helper-macros/helper-macros.h>
#include <stdlib.h>

View File

@ -1,3 +1,33 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file dma-ring-buffer.c
* @brief DMA Ring buffer implemenation
*/
/**
* @addtogroup dma-ring-buffer
* @{
*/
#include <stm-periph/dma-ring-buffer.h>
#include <stm-periph/clock-enable-manager.h>
#include <stdbool.h>
@ -30,7 +60,7 @@ static int dma_ring_buffer_switch_clock_enable(uint8_t base_dma, bool clk_en)
int dma_ring_buffer_periph_to_mem_initialize(struct dma_ring_buffer_to_mem *dma_buffer, uint8_t base_dma_id,
DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size,
void *data_buffer, void* src_reg, uint8_t dma_trigger_channel)
volatile void *data_buffer, void* src_reg, uint8_t dma_trigger_channel)
{
int ret_val = 0;
@ -63,7 +93,7 @@ int dma_ring_buffer_periph_to_mem_initialize(struct dma_ring_buffer_to_mem *dma_
return 0;
}
int dma_ring_buffer_periph_to_mem_get_data(struct dma_ring_buffer_to_mem *buff, const void **data_buff, size_t *len)
int dma_ring_buffer_periph_to_mem_get_data(struct dma_ring_buffer_to_mem *buff, const volatile void **data_buff, size_t *len)
{
int ret_code = 0;
uint32_t ndtr;
@ -72,20 +102,22 @@ int dma_ring_buffer_periph_to_mem_get_data(struct dma_ring_buffer_to_mem *buff,
if (!buff || !data_buff || !len)
return -1;
ndtr = buff->dma->NDTR;
put_idx = buff->buffer_count - ndtr;
/* Check if wrap around */
if (put_idx < buff->get_idx) {
/* Available data wraps around end of buffer: Return first part upt to the end of the ring buffer */
*data_buff = &(((char *)buff->data_ptr)[buff->get_idx * buff->element_size]);
*len = buff->buffer_count - buff->get_idx;
buff->get_idx = 0;
ret_code = 1;
ret_code = 2;
} else if (put_idx > buff->get_idx) {
/* Data does not wrap around ring buffer. Return full data */
*data_buff = &(((char *)buff->data_ptr)[buff->get_idx * buff->element_size]);
*len = put_idx - buff->get_idx;
buff->get_idx += *len;
ret_code = 1;
} else {
/* No new data */
*len = 0;
@ -109,7 +141,7 @@ void dma_ring_buffer_periph_to_mem_stop(struct dma_ring_buffer_to_mem *buff)
memset(buff, 0, sizeof(struct dma_ring_buffer_to_mem));
}
int dma_ring_buffer_mem_to_periph_initialize(struct dma_ring_buffer_to_periph *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, void *data_buffer, uint8_t dma_trigger_channel, void *dest_reg)
int dma_ring_buffer_mem_to_periph_initialize(struct dma_ring_buffer_to_periph *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, volatile void *data_buffer, uint8_t dma_trigger_channel, void *dest_reg)
{
if (!dma_buffer || !dma_stream || !data_buffer || !dest_reg)
return -1000;
@ -223,7 +255,7 @@ int dma_ring_buffer_mem_to_periph_insert_data(struct dma_ring_buffer_to_periph *
first_round_count = buff->element_size * (buff->buffer_count - buff->sw_put_idx);
memcpy(dest_ptr, insert_ptr, first_round_count);
insert_ptr += first_round_count;
memcpy(buff->src_buffer, insert_ptr, count - first_round_count);
memcpy((void *)buff->src_buffer, insert_ptr, count - first_round_count);
/* Move put index */
buff->sw_put_idx = count - first_round_count;
@ -256,3 +288,5 @@ void dma_ring_buffer_mem_to_periph_stop(struct dma_ring_buffer_to_periph *buff)
/* Reset the structure */
memset(buff, 0, sizeof(struct dma_ring_buffer_to_periph));
}
/** @} */

View File

@ -1,3 +1,23 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stm-periph/uart.h>
#include <stm32/stm32f4xx.h>
#include <stm-periph/clock-enable-manager.h>
@ -87,7 +107,7 @@ void uart_send_string_with_dma(const char *string)
int uart_receive_data_with_dma(const char **data, size_t *len)
{
return dma_ring_buffer_periph_to_mem_get_data(&ring_buff_rx, (const void **)data, len);
return dma_ring_buffer_periph_to_mem_get_data(&ring_buff_rx, (const volatile void **)data, len);
}
void DMA2_Stream7_IRQHandler()

View File

@ -1,3 +1,23 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stm-periph/unique-id.h>
#define LOW_WORD_ADDR (0x1FFF7A10UL)

View File

@ -36,8 +36,8 @@ ENTRY(Reset_Handler)
_estack = 0x20020000; /* end of 128K RAM on AHB bus*/
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x1500; /* required amount of heap (DEFAULT 0) */
_Min_Stack_Size = 0x2000 ; /* required amount of stack */
_Min_Heap_Size = 0x2100; /* required amount of heap (DEFAULT 0) */
_Min_Stack_Size = 0x3000 ; /* required amount of stack */
/* recommended min stack size for printf=0x2000, orig = 0x400 */
/* Specify the memory areas */
@ -162,14 +162,14 @@ SECTIONS
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack (NOLOAD):
{
. = ALIGN(4);
. = ALIGN(8);
PROVIDE (heap_low = .); /* for _sbrk */
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
PROVIDE (heap_top = .); /* for _sbrk */
. = . + _Min_Stack_Size;
. = ALIGN(4);
. = ALIGN(8);
} >RAM
/* MEMORY_bank1 section, code must be located here explicitly */

View File

@ -1,4 +1,28 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stm-periph/uart.h>
#include <sys/types.h>
#include <errno.h>
#include <stddef.h>
char* _sbrk(int incr)
{
@ -12,12 +36,16 @@ char* _sbrk(int incr)
}
prev_heap_end = heap_end;
if (heap_end + incr > &heap_top) {
return 0;
errno = ENOMEM;
return (char *)-1;
}
heap_end += incr;
return (char*) prev_heap_end;
return (char *) prev_heap_end;
}
int _isatty(int fd)
@ -59,6 +87,6 @@ int _read(void)
int _write(int fd, const void *buf, int count)
{
if (fd == 1)
uart_send_array((char*)buf, count);
uart_send_array_with_dma((char*)buf, count);
return count;
}

View File

@ -1,3 +1,27 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file systick.c
*/
#include <reflow-controller/systick.h>
#include <stm32/stm32f4xx.h>
#include <cmsis/core_cm4.h>
@ -11,14 +35,6 @@ void systick_setup(void)
SysTick_Config(SYSTICK_RELOAD);
}
/**
* @brief Wait for x milliseconds
*
* This function is not reentrant and must not be called from an interrupt
*
* @warning Do not use in interrupt context
* @param ms wait time in ms
*/
void systick_wait_ms(uint32_t ms)
{
wait_tick_ms = 0UL;

View File

@ -0,0 +1,75 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <reflow-controller/temp-converter.h>
#include <reflow-controller/temp-converter-data.h>
#include <helper-macros/helper-macros.h>
static const float temp_lookup[(TEMP_CONVERSION_MAX_RES-TEMP_CONVERSION_MIN_RES) / TEMP_CONVERSION_RES_STEP+1] = {TEMP_CONVERSION_ARRAY_DATA};
int temp_converter_convert_resistance_to_temp(float resistance, float *temp_out)
{
int ret_val;
unsigned int i;
unsigned int lower_idx = COUNT_OF(temp_lookup) - 1;
float diff_to_low_resistance;
float diff_high_low;
float low;
/* Check pointer */
if (!temp_out)
return -1000;
if (resistance < TEMP_CONVERSION_MIN_RES) {
*temp_out = temp_lookup[0];
ret_val = -1;
goto return_ret_val;
} else if (resistance > TEMP_CONVERSION_MAX_RES) {
*temp_out = temp_lookup[COUNT_OF(temp_lookup)-1];
ret_val = 1;
goto return_ret_val;
}
/* Resistance is in range */
ret_val = 0;
/* Calculate lower index for given reistance */
for (i = 1; i < COUNT_OF(temp_lookup); i++) {
if (resistance <= TEMP_CONVERSION_MIN_RES + TEMP_CONVERSION_RES_STEP * i) {
lower_idx = i - 1;
break;
}
}
/* Get the lower temperature limit of the current range */
low = temp_lookup[lower_idx];
/* Difference to higher limit */
diff_high_low = temp_lookup[lower_idx+1] - low;
/* Resistance difference to lower limit's resistance value */
diff_to_low_resistance = resistance - (float)(TEMP_CONVERSION_MIN_RES + TEMP_CONVERSION_RES_STEP * lower_idx);
/* Calculate output temperature */
*temp_out = (diff_to_low_resistance / TEMP_CONVERSION_RES_STEP) * diff_high_low + low;
return_ret_val:
return ret_val;
}