diff --git a/stm-firmware/Makefile b/stm-firmware/Makefile
index 10988c5..8eac35f 100644
--- a/stm-firmware/Makefile
+++ b/stm-firmware/Makefile
@@ -34,28 +34,18 @@ DEFINES += -DSHELLMATTA_HELP_ALIAS=\"?\"
# RCC Manager
CFILES += stm-periph/clock-enable-manager.c
-
CFILES += stm-periph/uart.c stm-periph/dma-ring-buffer.c
-
CFILES += digio.c
-
CFILES += stm-periph/unique-id.c
-
CFILES += calibration.c
-
CFILES += temp-converter.c
-
CFILES += rotary-encoder.c button.c
-
CFILES += stack-check.c
-
CFILES += ui/lcd.c ui/menu.c
-
#CFILES += onewire-temp-sensors.c
-
CFILES += fatfs/diskio.c fatfs/ff.c fatfs/ffsystem.c fatfs/ffunicode.c fatfs/shimatta_sdio_driver/shimatta_sdio.c
-
CFILES += pid-controller.c oven-driver.c
+CFILES += settings/settings.c settings/settings-sd-card.c
DEFINES += -DDEBUGBUILD
diff --git a/stm-firmware/adc-meas.c b/stm-firmware/adc-meas.c
index 1699efb..2ea8762 100644
--- a/stm-firmware/adc-meas.c
+++ b/stm-firmware/adc-meas.c
@@ -36,6 +36,7 @@ static volatile int * volatile streaming_flag_ptr = NULL;
static uint32_t filter_startup_cnt;
static volatile float adc_pt1000_raw_reading_hf;
static volatile uint16_t dma_sample_buffer[ADC_PT1000_DMA_AVG_SAMPLES];
+static volatile uint32_t adc_watchdog_counter = 0UL;
volatile float * volatile stream_buffer = NULL;
volatile uint32_t stream_count;
@@ -334,7 +335,9 @@ void ADC_IRQHandler(void)
if (adc1_sr & ADC_SR_AWD) {
ADC1->SR &= ~ADC_SR_AWD;
- pt1000_error |= ADC_PT1000_WATCHDOG_ERROR;
+ adc_watchdog_counter++;
+ if (adc_watchdog_counter >= ADC_PT1000_WATCHDOG_SAMPLE_COUNT)
+ pt1000_error |= ADC_PT1000_WATCHDOG_ERROR;
}
}
@@ -369,6 +372,9 @@ void DMA2_Stream0_IRQHandler()
if (streaming_flag_ptr)
append_stream_buffer(adc_val);
+ if (adc_watchdog_counter > 0UL)
+ adc_watchdog_counter--;
+
/* Call moving average filter */
adc_pt1000_filter(adc_val);
}
diff --git a/stm-firmware/create-c-file-with-header.py b/stm-firmware/create-c-file-with-header.py
index 67176c1..5ad8c48 100755
--- a/stm-firmware/create-c-file-with-header.py
+++ b/stm-firmware/create-c-file-with-header.py
@@ -2,6 +2,7 @@
import os
import sys
+import pathlib
license_header = """/* Reflow Oven Controller
*
@@ -22,7 +23,6 @@ license_header = """/* Reflow Oven Controller
* along with the reflow oven controller project.
* If not, see .
*/
-
"""
project_dir = os.path.dirname(os.path.realpath(__file__))
@@ -37,19 +37,23 @@ 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()+'__'
+h_define = '__'+hfile.replace('.', '_').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))
+cfile_folder = os.path.dirname(cpath)
+pathlib.Path(cfile_folder).mkdir(parents=True, exist_ok=True)
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))
+hfile_folder = os.path.dirname(hpath)
+pathlib.Path(hfile_folder).mkdir(parents=True, exist_ok=True)
with open(hpath, 'x') as f:
f.write(license_header)
f.write('\n')
diff --git a/stm-firmware/fatfs/shimatta_sdio_driver/shimatta_sdio.c b/stm-firmware/fatfs/shimatta_sdio_driver/shimatta_sdio.c
index 4867957..d764419 100644
--- a/stm-firmware/fatfs/shimatta_sdio_driver/shimatta_sdio.c
+++ b/stm-firmware/fatfs/shimatta_sdio_driver/shimatta_sdio.c
@@ -32,9 +32,9 @@ static struct sd_info card_info; // = {.type = CARD_NONE};
* @brief checkNotInserted
* @return return 0 if card is inserted, else 1
*/
-static int sdio_check_inserted() {
+int sdio_check_inserted() {
#if SDIO_ENABLE_INS
- return ((INS_PORT->IDR & INS_PIN) == (INS_ACTIVE_LEVEL<IDR & (1<IDR & WRITEPROT_PIN) == (WRITEPROT_ACTIVE_LEVEL<IDR & (1<
+*
+* 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.
+*
+* The Reflow Oven Control Firmware 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 .
+*/
+
+#ifndef __SETTINGS_SETTINGS_SD_CARD_H__
+#define __SETTINGS_SETTINGS_SD_CARD_H__
+
+#endif /* __SETTINGS_SETTINGS_SD_CARD_H__ */
diff --git a/stm-firmware/include/reflow-controller/settings/settings.h b/stm-firmware/include/reflow-controller/settings/settings.h
new file mode 100644
index 0000000..31a02b4
--- /dev/null
+++ b/stm-firmware/include/reflow-controller/settings/settings.h
@@ -0,0 +1,27 @@
+/* Reflow Oven Controller
+*
+* Copyright (C) 2020 Mario Hüttel
+*
+* 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.
+*
+* The Reflow Oven Control Firmware 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 .
+*/
+
+
+#ifndef __SETTINGS_SETTINGS_H__
+#define __SETTINGS_SETTINGS_H__
+
+settings_save_calibration();
+
+#endif /* __SETTINGS_SETTINGS_H__ */
diff --git a/stm-firmware/include/reflow-controller/shell.h b/stm-firmware/include/reflow-controller/shell.h
index 72a94d2..935e3ca 100644
--- a/stm-firmware/include/reflow-controller/shell.h
+++ b/stm-firmware/include/reflow-controller/shell.h
@@ -30,4 +30,6 @@ void shell_handle_input(shellmatta_handle_t shell, const char *data, size_t len)
void shell_print_string(shellmatta_handle_t shell, const char *string);
+void shell_print_motd(shellmatta_handle_t shell);
+
#endif /* __SHELL_H__ */
diff --git a/stm-firmware/include/reflow-controller/stack-check.h b/stm-firmware/include/reflow-controller/stack-check.h
index f73dd29..8e0e290 100644
--- a/stm-firmware/include/reflow-controller/stack-check.h
+++ b/stm-firmware/include/reflow-controller/stack-check.h
@@ -29,6 +29,18 @@ int32_t stack_check_get_usage();
int32_t stack_check_get_free();
+static inline int stack_check_collision()
+{
+ int ret = 0;
+ int32_t free_space = stack_check_get_free();
+
+ if ((unsigned int)free_space < STACK_CHECK_MIN_HEAP_GAP) {
+ ret = -1;
+ }
+
+ return ret;
+}
+
static inline uint32_t read_stack_pointer()
{
uint32_t stack_pointer;
diff --git a/stm-firmware/include/reflow-controller/temp-converter-data.h b/stm-firmware/include/reflow-controller/temp-converter-data.h
index d4517e4..7719127 100644
--- a/stm-firmware/include/reflow-controller/temp-converter-data.h
+++ b/stm-firmware/include/reflow-controller/temp-converter-data.h
@@ -8,7 +8,7 @@
* 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,
+ * The Reflow Oven Control Firmware 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.
diff --git a/stm-firmware/main.c b/stm-firmware/main.c
index be83450..b8981ba 100644
--- a/stm-firmware/main.c
+++ b/stm-firmware/main.c
@@ -34,6 +34,7 @@
#include
#include
#include
+#include "fatfs/shimatta_sdio_driver/shimatta_sdio.h"
#include
#include
#include
@@ -60,6 +61,9 @@ static uint32_t rot;
static volatile float pid_out;
static volatile float current_temperature;
+FATFS fs;
+FATFS *fs_ptr = &fs;
+
static inline void uart_gpio_config()
{
#ifdef DEBUGBUILD
@@ -104,11 +108,32 @@ static inline void setup_sell_uart(struct stm_uart *uart)
NVIC_EnableIRQ(DMA2_Stream7_IRQn);
}
+static bool mount_sd_card_if_avail(bool mounted)
+{
+ FRESULT res;
+
+ if (sdio_check_inserted() && mounted) {
+ memset(fs_ptr, 0, sizeof(FATFS));
+ return false;
+ }
+
+ if (!sdio_check_inserted() && !mounted) {
+ res = f_mount(fs_ptr, "0:/", 1);
+ if (res == FR_OK) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ return mounted;
+}
+
const char *oven_controller_hello_world = "Hello world :)\n";
int main()
{
- FATFS fs;
+ bool sd_card_mounted = false;
FIL test_file;
const char *uart_input;
size_t uart_input_len;
@@ -132,8 +157,10 @@ int main()
setup_sell_uart(&shell_uart);
shell_handle = shell_init(write_shell_callback);
+ shell_print_motd(shell_handle);
- if (f_mount(&fs, "0:/", 1) == FR_OK) {
+ if (f_mount(fs_ptr, "0:/", 1) == FR_OK) {
+ sd_card_mounted = true;
f_open(&test_file, "hello-world.txt", FA_OPEN_APPEND | FA_WRITE);
f_write(&test_file, oven_controller_hello_world, strlen(oven_controller_hello_world), NULL);
f_close(&test_file);
@@ -143,6 +170,9 @@ int main()
pid_zero(&pid);
while (1) {
+
+ sd_card_mounted = mount_sd_card_if_avail(sd_card_mounted);
+
pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value);
if (pt1000_value_status >= 0) {
diff --git a/stm-firmware/settings/settings-sd-card.c b/stm-firmware/settings/settings-sd-card.c
new file mode 100644
index 0000000..5239091
--- /dev/null
+++ b/stm-firmware/settings/settings-sd-card.c
@@ -0,0 +1,21 @@
+/* Reflow Oven Controller
+*
+* Copyright (C) 2020 Mario Hüttel
+*
+* 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.
+*
+* The Reflow Oven Control Firmware 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 .
+*/
+
+#include
diff --git a/stm-firmware/settings/settings.c b/stm-firmware/settings/settings.c
new file mode 100644
index 0000000..07643ce
--- /dev/null
+++ b/stm-firmware/settings/settings.c
@@ -0,0 +1,21 @@
+/* Reflow Oven Controller
+*
+* Copyright (C) 2020 Mario Hüttel
+*
+* 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.
+*
+* The Reflow Oven Control Firmware 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 .
+*/
+
+#include
diff --git a/stm-firmware/shell.c b/stm-firmware/shell.c
index 4e25aa8..17f1ba4 100644
--- a/stm-firmware/shell.c
+++ b/stm-firmware/shell.c
@@ -18,6 +18,8 @@
* If not, see .
*/
+#include
+#include
#include
#include
#include
@@ -30,7 +32,7 @@
#include
#include
#include
-
+#include
#include
#include
@@ -275,8 +277,11 @@ static shellmatta_retCode_t shell_cmd_pt1000_res_loop(const shellmatta_handle_t
shellmatta_printf(handle, "\x1b[1A\x1b[150D\x1b[K");
shell_cmd_pt1000_res(handle, "", 0UL);
- led_set(0, led_status);
- led_set(1, !led_status);
+ led_set(1, led_status);
+ if (adc_pt1000_check_error() & ADC_PT1000_WATCHDOG_ERROR) {
+ led_set(0, 1);
+ }
+
led_status ^= 0x1;
systick_wait_ms(150);
@@ -288,6 +293,43 @@ static shellmatta_retCode_t shell_cmd_pt1000_res_loop(const shellmatta_handle_t
return SHELLMATTA_OK;
}
+static shellmatta_retCode_t shell_cmd_ls(const shellmatta_handle_t handle, const char *arguments,
+ uint32_t length)
+{
+ (void)length;
+ (void)arguments;
+ DIR dir;
+ FRESULT res;
+ FILINFO fno;
+
+ res = f_opendir(&dir, "/");
+ if (res != FR_OK) {
+ shellmatta_printf(handle, "Filesystem inaccessible. Is an SD Card inserted?\r\n");
+ return SHELLMATTA_OK;
+ }
+
+ while (f_readdir(&dir, &fno) == FR_OK) {
+ if (fno.fname[0] == 0)
+ break;
+ shellmatta_printf(handle, "%c\t%s\r\n", (fno.fattrib & AM_DIR ? 'd' : 'f'), fno.fname);
+ }
+
+ f_closedir(&dir);
+
+ return SHELLMATTA_OK;
+}
+
+static shellmatta_retCode_t shell_cmd_reset(const shellmatta_handle_t handle, const char *arguments,
+ uint32_t length)
+{
+ (void)handle;
+ (void)length;
+ (void)arguments;
+
+ NVIC_SystemReset();
+
+ return SHELLMATTA_BUSY;
+}
//typedef struct shellmatta_cmd
//{
// char *cmd; /**< command name */
@@ -298,7 +340,7 @@ static shellmatta_retCode_t shell_cmd_pt1000_res_loop(const shellmatta_handle_t
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
//} shellmatta_cmd_t;
-static shellmatta_cmd_t cmd[10] = {
+static shellmatta_cmd_t cmd[12] = {
{
.cmd = "version",
.cmdAlias = "ver",
@@ -377,8 +419,25 @@ static shellmatta_cmd_t cmd[10] = {
.helpText = "Get current rotary encoder value",
.usageText = "",
.cmdFct = shell_cmd_rot,
+ .next = &cmd[10],
+ },
+ {
+ .cmd = "ls",
+ .cmdAlias = NULL,
+ .helpText = "List filesystem contents",
+ .usageText = "",
+ .cmdFct = shell_cmd_ls,
+ .next = &cmd[11],
+ },
+ {
+ .cmd = "reset",
+ .cmdAlias = NULL,
+ .helpText = "Reset controller",
+ .usageText = "Resets the controller",
+ .cmdFct = shell_cmd_reset,
.next = NULL,
}
+
};
shellmatta_handle_t shell_init(shellmatta_write_t write_func)
@@ -394,6 +453,12 @@ shellmatta_handle_t shell_init(shellmatta_write_t write_func)
return handle;
}
+void shell_print_motd(shellmatta_handle_t shell)
+{
+ shellmatta_printf(shell, "\r\nShimatta 仕舞った Reflow Controller ready\r\n\r\n");
+ shell_cmd_ver(shell, NULL, 0UL);
+ shell_handle_input(shell, "\r\n", 2UL);
+}
void shell_handle_input(shellmatta_handle_t shell, const char *data, size_t len)
{
diff --git a/stm-firmware/shellmatta b/stm-firmware/shellmatta
index 6c76dfc..ebf65d7 160000
--- a/stm-firmware/shellmatta
+++ b/stm-firmware/shellmatta
@@ -1 +1 @@
-Subproject commit 6c76dfc7aed2594579f09d0b797d6a51cffff343
+Subproject commit ebf65d744838a5c7bbf6ddfff6cb4428f012fd97