Merge branch 'dev' into ui

This commit is contained in:
Mario Hüttel 2020-04-27 19:28:32 +02:00
commit eb3b0eb459
17 changed files with 240 additions and 30 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
"""
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')

View File

@ -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<<INS_PIN) ? 0 : 1);
return ((INS_PORT->IDR & (1<<INS_PIN)) == (INS_ACTIVE_LEVEL<<INS_PIN) ? 0 : 1);
#else
return 0; // Assume Card is inserted
#endif
@ -46,7 +46,7 @@ static int sdio_check_inserted() {
*/
static int sdio_check_write_protection() {
#if SDIO_ENABLE_WRITEPROT
return ((WRITEPROT_PORT->IDR & WRITEPROT_PIN) == (WRITEPROT_ACTIVE_LEVEL<<WRITEPROT_PIN) ? 1 : 0);
return ((WRITEPROT_PORT->IDR & (1<<WRITEPROT_PIN)) == (WRITEPROT_ACTIVE_LEVEL<<WRITEPROT_PIN) ? 1 : 0);
#else
return 0; // Assume Card is not write protected
#endif

View File

@ -20,6 +20,8 @@ DRESULT sdio_disk_write(const BYTE *buff, DWORD sector, UINT count);
DRESULT sdio_disk_ioctl(BYTE cmd, void* buff);
DWORD get_fattime();
int sdio_check_inserted();
//Defines for Card Status in struct _CardStatus
#define CURRENT_STATE_IDLE 0

View File

@ -24,7 +24,7 @@
/* Port Definitions */
#define PORTCLKMASK (RCC_AHB1ENR_GPIODEN | RCC_AHB1ENR_GPIOCEN)
#define PORTCLKMASK (RCC_AHB1ENR_GPIODEN | RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIOAEN)
#define ALTFUNC 12
@ -50,10 +50,10 @@
#define WRITEPROT_ACTIVE_LEVEL 0
// Card inserted pin
#define SDIO_ENABLE_INS 0
#define INS_PORT GPIOD // Add this port to port clock mask!
#define INS_PIN 0
#define INS_PULLUP 0
#define SDIO_ENABLE_INS 1
#define INS_PORT GPIOA // Add this port to port clock mask!
#define INS_PIN 8
#define INS_PULLUP 1
#define INS_ACTIVE_LEVEL 0

View File

@ -59,6 +59,12 @@
*/
#define ADC_PT1000_UPPER_WATCHDOG 4000U
/**
* @brief Number of ADC samples the value has to be outside the Watchdog limit (@ref ADC_PT1000_UPPER_WATCHDOG and @ref ADC_PT1000_LOWER_WATCHDOG)
* in order to produce a watchdog error
*/
#define ADC_PT1000_WATCHDOG_SAMPLE_COUNT 25U
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)};
/**

View File

@ -0,0 +1,24 @@
/* 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.
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef __SETTINGS_SETTINGS_SD_CARD_H__
#define __SETTINGS_SETTINGS_SD_CARD_H__
#endif /* __SETTINGS_SETTINGS_SD_CARD_H__ */

View File

@ -0,0 +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.
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef __SETTINGS_SETTINGS_H__
#define __SETTINGS_SETTINGS_H__
settings_save_calibration();
#endif /* __SETTINGS_SETTINGS_H__ */

View File

@ -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__ */

View File

@ -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;

View File

@ -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.

View File

@ -34,6 +34,7 @@
#include <reflow-controller/shell.h>
#include <reflow-controller/pid-controller.h>
#include <reflow-controller/digio.h>
#include "fatfs/shimatta_sdio_driver/shimatta_sdio.h"
#include <reflow-controller/temp-converter.h>
#include <reflow-controller/rotary-encoder.h>
#include <stm-periph/stm32-gpio-macros.h>
@ -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) {

View File

@ -0,0 +1,21 @@
/* 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.
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <reflow-controller/settings/settings-sd-card.h>

View File

@ -0,0 +1,21 @@
/* 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.
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <reflow-controller/settings/settings.h>

View File

@ -18,6 +18,8 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stm32/stm32f4xx.h>
#include <cmsis/core_cm4.h>
#include <reflow-controller/shell.h>
#include <stm-periph/uart.h>
#include <string.h>
@ -30,7 +32,7 @@
#include <stm-periph/unique-id.h>
#include <reflow-controller/calibration.h>
#include <reflow-controller/temp-converter.h>
#include <fatfs/ff.h>
#include <reflow-controller/stack-check.h>
#include <reflow-controller/rotary-encoder.h>
@ -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)
{

@ -1 +1 @@
Subproject commit 6c76dfc7aed2594579f09d0b797d6a51cffff343
Subproject commit ebf65d744838a5c7bbf6ddfff6cb4428f012fd97