diff --git a/stm-firmware/Makefile b/stm-firmware/Makefile index a2f5d0e..8c1ac54 100644 --- a/stm-firmware/Makefile +++ b/stm-firmware/Makefile @@ -35,7 +35,7 @@ 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 += stm-periph/uart.c stm-periph/dma-ring-buffer.c stm-periph/backup-ram.c CFILES += digio.c CFILES += stm-periph/unique-id.c CFILES += calibration.c @@ -43,12 +43,11 @@ CFILES += temp-converter.c CFILES += rotary-encoder.c button.c CFILES += stack-check.c CFILES += ui/lcd.c ui/menu.c reflow-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 -CFILES += safety/safety-adc.c safety/safety-controller.c safety/watchdog.c +CFILES += safety/safety-adc.c safety/safety-controller.c safety/watchdog.c safety/fault.c DEBUG_DEFINES = -DDEBUGBUILD RELEASE_DEFINES = diff --git a/stm-firmware/include/reflow-controller/safety/fault.h b/stm-firmware/include/reflow-controller/safety/fault.h new file mode 100644 index 0000000..1cbe715 --- /dev/null +++ b/stm-firmware/include/reflow-controller/safety/fault.h @@ -0,0 +1,28 @@ +/* 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 . + */ + +/** + * @brief This function implements the panic mode + * + * This function will never return and ensures that the controller goes in a safe operating state + * The watchdog will eventually reset the controller from this state. Therefore, this function sets + * a flag in the backup SRAM that will prevent the controller from booting in normal operation. + */ +void panic_mode(void); diff --git a/stm-firmware/include/stm-periph/backup-ram.h b/stm-firmware/include/stm-periph/backup-ram.h new file mode 100644 index 0000000..ff23813 --- /dev/null +++ b/stm-firmware/include/stm-periph/backup-ram.h @@ -0,0 +1,51 @@ +/* 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 + +/** + * @brief Init the backup ram and make it accesible + */ +void backup_ram_init(); + +/** + * @brief Disable access to the backup RAM. This saves power + */ +void backup_ram_disable(); + +/** + * @brief Whis function overwrites the backup RAM with 0x00 + */ +void backup_ram_wipe(); + +/** + * @brief Read data from the backup RAM + * @param addr Address offset inside memory + * @param data read 32bit data + */ +int backup_ram_get_data(uint32_t addr, uint32_t *data); + +/** + * @brief Write data structure to backup RAM + * @param data + * @return + */ +int backup_ram_write_data(uint32_t addr, uint32_t data); + diff --git a/stm-firmware/main.c b/stm-firmware/main.c index f508952..a43e42f 100644 --- a/stm-firmware/main.c +++ b/stm-firmware/main.c @@ -26,8 +26,6 @@ #include #include #include -#include -/* #include */ #include #include #include diff --git a/stm-firmware/safety/fault.c b/stm-firmware/safety/fault.c new file mode 100644 index 0000000..79a743d --- /dev/null +++ b/stm-firmware/safety/fault.c @@ -0,0 +1,49 @@ +/* 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 +#include +#include + +void HardFault_Handler(void) +{ + /* This is a non recoverable fault. Hang here */ + + oven_driver_set_power(0); + oven_driver_apply_power_level(); + + led_set(0, 1); + + while (1); +} + +void panic_mode(void) +{ + /* Panic mode is esentially the same as a hardfault, + * but it can be expected, that more functionality is still usable + */ + + oven_driver_set_power(0); + oven_driver_apply_power_level(); + + /* TODO: implement panic mode */ + + while (1); +} diff --git a/stm-firmware/stm-periph/backup-ram.c b/stm-firmware/stm-periph/backup-ram.c new file mode 100644 index 0000000..b2b75a5 --- /dev/null +++ b/stm-firmware/stm-periph/backup-ram.c @@ -0,0 +1,54 @@ +/* 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 +#include +#include + +void backup_ram_init() +{ + rcc_manager_enable_clock(&RCC->APB1ENR, BITMASK_TO_BITNO(RCC_APB1ENR_PWREN)); + + /* Enable access to backup RAM register set */ + PWR->CR |= PWR_CR_DBP; + + /* Enable clock for backup ram interface */ + rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(RCC_AHB1ENR_BKPSRAMEN)); +} + +void backup_ram_disable() +{ + rcc_manager_disable_clock(&RCC->APB1ENR, BITMASK_TO_BITNO(RCC_APB1ENR_PWREN)); +} + +void backup_ram_wipe() +{ + +} + +int backup_ram_get_data(uint32_t addr, uint32_t *data) +{ + +} + +int backup_ram_write_data(uint32_t addr, uint32_t data) +{ + +}