add safety system, stub of new gui task

calib-gui
Ondřej Hruška 2 years ago
parent 0a0ccf7bc3
commit b397856366
  1. 2
      Core/Inc/main.h
  2. 2
      Core/Src/app_buzzer.c
  3. 83
      Core/Src/app_gui.c
  4. 23
      Core/Src/app_heater.c
  5. 269
      Core/Src/app_main.c
  6. 3
      Core/Src/app_oled.c
  7. 64
      Core/Src/app_safety.c
  8. 30
      Core/Src/app_safety.h
  9. 13
      Core/Src/app_temp.c
  10. 27
      Core/Src/main.c
  11. 31
      Core/Src/stm32f1xx_it.c
  12. 5
      Makefile

@ -51,6 +51,8 @@ extern "C" {
/* Private includes ----------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
extern void app_emergency_stop(void);
#define __weak __attribute__((weak)) #define __weak __attribute__((weak))
/* USER CODE END Includes */ /* USER CODE END Includes */

@ -19,8 +19,8 @@ void app_buzzer_init()
{ {
/* Enable buzzer PWM */ /* Enable buzzer PWM */
LL_TIM_OC_SetCompareCH1(TIM_BUZZER, 0); LL_TIM_OC_SetCompareCH1(TIM_BUZZER, 0);
LL_TIM_EnableCounter(TIM_BUZZER);
LL_TIM_CC_EnableChannel(TIM_BUZZER, LL_TIM_CHANNEL_CH1); LL_TIM_CC_EnableChannel(TIM_BUZZER, LL_TIM_CHANNEL_CH1);
LL_TIM_EnableCounter(TIM_BUZZER);
// HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); // HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
// s_timer = xTimerCreate("beep", 50, 0, NULL, app_beep_end); // s_timer = xTimerCreate("beep", 50, 0, NULL, app_beep_end);

@ -4,19 +4,90 @@
#include <stdbool.h> #include <stdbool.h>
#include "app_gui.h" #include "app_gui.h"
#include "app_heater.h"
#include "app_buzzer.h"
#include "app_temp.h"
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "task.h" #include "task.h"
#include "queue.h" #include "queue.h"
#include "ufb/framebuffer.h"
#include "ufb/fb_text.h"
#define MAX_TEMP 400
static struct State {
float oven_temp;
float soc_temp;
int set_temp;
int set_temp_wheel;
bool heater_enabled;
} s_app = {};
static void calc_set_temp() {
int clamped = s_app.set_temp_wheel;
if (clamped < 0) {
clamped = 0;
}
s_app.set_temp = (clamped / 2) * 5;
if (s_app.set_temp > MAX_TEMP) {
s_app.set_temp = MAX_TEMP;
}
app_heater_set_target((float) s_app.set_temp);
}
void app_task_gui(void *argument) { void app_task_gui(void *argument) {
PRINTF("app_task_gui\r\n"); // Wait until inited
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
PUTS("GUI task starts\r\n");
char tmp[100];
while (1) { while (1) {
uint8_t message = 0; s_app.oven_temp = app_temp_read_oven();
bool suc = osMessageQueueGet(guiEventQueHandle, &message, NULL, pdMS_TO_TICKS(1000)); s_app.soc_temp = app_temp_read_soc();
if (suc == osOK && (message != GUI_NOTIFY_TEMP_CHANGE)) { uint32_t message = GUI_EVENT_NONE;
// input events osMessageQueueGet(guiEventQueHandle, &message, NULL, pdMS_TO_TICKS(1000));
PRINTF("Event %d\r\n", message);
switch (message) {
case GUI_NOTIFY_KNOB_PLUS:
s_app.set_temp_wheel++;
calc_set_temp();
break;
case GUI_NOTIFY_KNOB_MINUS:
s_app.set_temp_wheel--;
calc_set_temp();
break;
case GUI_NOTIFY_KNOB_PRESS:
break;
case GUI_NOTIFY_KNOB_RELEASE:
s_app.heater_enabled ^= 1;
app_heater_enable(s_app.heater_enabled);
app_buzzer_beep();
break;
default:
break;
} }
fb_clear();
SPRINTF(tmp, "T=%.1f°C", s_app.oven_temp);
fb_text(3, 3, tmp, FONT_5X7, 1);
SPRINTF(tmp, "Cil=%d°C", s_app.set_temp);
fb_text(3, 11, tmp, FONT_5X7, 1);
SPRINTF(tmp, "Stav=%s", s_app.heater_enabled ? "ZAP" : "VYP");
fb_text(3, 19, tmp, FONT_5X7, 1);
SPRINTF(tmp, "Tsoc=%.1f°C", s_app.soc_temp);
fb_text(3, 27, tmp, FONT_5X7, 1);
if (s_app.heater_enabled) {
fb_frame(0, 0, FBW, FBH, 2, 1);
}
fb_blit();
} }
} }

@ -9,6 +9,7 @@
#include "tim.h" #include "tim.h"
#include "queue.h" #include "queue.h"
#include "app_gui.h" #include "app_gui.h"
#include "app_safety.h"
extern osMutexId_t heaterMutexHandle; extern osMutexId_t heaterMutexHandle;
@ -81,16 +82,31 @@ void app_heater_set_target(float target) {
heaterExitCritical(); heaterExitCritical();
} }
// emergency shutdown, this must not block use RTOS since it can be called from fault handlers or interrupt
void app_heater_emergency_shutdown() { void app_heater_emergency_shutdown() {
PID_SetCtlMode(&state.pid, PID_MANUAL); // Stop pwm
// TODO check if this really turns the channel off!
LL_TIM_OC_SetCompareCH1(TIM_HEATER, 0); LL_TIM_OC_SetCompareCH1(TIM_HEATER, 0);
LL_TIM_CC_DisableChannel(TIM_HEATER, LL_TIM_CHANNEL_CH1); LL_TIM_CC_DisableChannel(TIM_HEATER, LL_TIM_CHANNEL_CH1);
LL_TIM_DisableCounter(TIM_HEATER);
// Also kill the GPIO PWM output
LL_GPIO_InitTypeDef GPIO_InitStruct = {};
GPIO_InitStruct.Pin = PWM_HEATER_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(PWM_HEATER_GPIO_Port, &GPIO_InitStruct);
// Output zero
LL_GPIO_ResetOutputPin(PWM_HEATER_GPIO_Port, PWM_HEATER_Pin);
} }
void app_task_heater(void *argument) void app_task_heater(void *argument)
{ {
// Wait until inited
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
PUTS("Heater task starts\r\n");
heater_pwm_init(); heater_pwm_init();
heaterEnterCritical(); heaterEnterCritical();
@ -110,6 +126,7 @@ void app_task_heater(void *argument)
xQueueSend(guiEventQueHandle, &ev, pdMS_TO_TICKS(100)); xQueueSend(guiEventQueHandle, &ev, pdMS_TO_TICKS(100));
heaterEnterCritical(); heaterEnterCritical();
app_safety_pass_reg_loop_running();
PID_Compute(&state.pid, state.oven_temp); PID_Compute(&state.pid, state.oven_temp);
if (state.pid.ctlMode == PID_AUTOMATIC) { if (state.pid.ctlMode == PID_AUTOMATIC) {
PRINTF("temp %d, output %d\r\n", (int) state.oven_temp, (int) state.pid.Output); PRINTF("temp %d, output %d\r\n", (int) state.oven_temp, (int) state.pid.Output);

@ -12,101 +12,88 @@
#include "ufb/framebuffer.h" #include "ufb/framebuffer.h"
#include "iwdg.h" #include "iwdg.h"
#include "app_oled.h" #include "app_oled.h"
#include "ufb/fb_text.h" //#include "ufb/fb_text.h"
#include "ufb/fb_7seg.h" //#include "ufb/fb_7seg.h"
#include "app_temp.h" #include "app_temp.h"
#include "app_knob.h" #include "app_knob.h"
#include "app_buzzer.h" #include "app_buzzer.h"
#include "app_heater.h" //#include "app_heater.h"
#include "cmsis_os2.h" //#include "cmsis_os2.h"
#include "eeprom_emul.h" #include "eeprom_emul.h"
#include "app_safety.h"
#include "cmsis_os2.h"
static struct App { extern osThreadId_t heaterTskHandle;
float oven_temp; extern osThreadId_t mainTskHandle;
int16_t set_temp; extern osThreadId_t guiTskHandle;
int16_t wheel_normed;
uint16_t wheel; //static struct App {
bool run; // float oven_temp;
} s_app = {}; // int16_t set_temp;
// int16_t wheel_normed;
static void redraw_display() { // uint16_t wheel;
fb_clear(); // bool run;
//} s_app = {};
char tmp[100];
//static void redraw_display() {
SPRINTF(tmp, "T=%d°C", (int) s_app.oven_temp); // fb_clear();
fb_text(3, 3, tmp, FONT_5X7, 1); //
// char tmp[100];
SPRINTF(tmp, "Cil=%d°C", s_app.set_temp); //
fb_text(3, 11, tmp, FONT_5X7, 1); // SPRINTF(tmp, "T=%d°C", (int) s_app.oven_temp);
// fb_text(3, 3, tmp, FONT_5X7, 1);
SPRINTF(tmp, "Stav=%s", s_app.run ? "ZAP" : "VYP"); //
fb_text(3, 19, tmp, FONT_5X7, 1); // SPRINTF(tmp, "Cil=%d°C", s_app.set_temp);
// fb_text(3, 11, tmp, FONT_5X7, 1);
if (s_app.run) { //
fb_frame(0, 0, FBW, FBH, 2, 1); // SPRINTF(tmp, "Stav=%s", s_app.run ? "ZAP" : "VYP");
} // fb_text(3, 19, tmp, FONT_5X7, 1);
//
// some funny effects to showcase responsiveness and circle drawing // if (s_app.run) {
// fb_frame(0, 0, FBW, FBH, 2, 1);
fb_circle(FBW / 2, 70, 18, 1, 1); // }
//
for (int i = 0; i < 6; i++) { // // some funny effects to showcase responsiveness and circle drawing
float x = FBW / 2; //
float y = 70; // fb_circle(FBW / 2, 70, 18, 1, 1);
//
int ii = i; // for (int i = 0; i < 6; i++) {
// float x = FBW / 2;
float angle = (float) ii * (M_PI / 3.0) - s_app.wheel_normed * (M_PI / 24); // float y = 70;
//
x = x + sinf(angle) * 10; // int ii = i;
y = y + cosf(angle) * 10; //
// float angle = (float) ii * (M_PI / 3.0) - s_app.wheel_normed * (M_PI / 24);
fb_circle((fbpos_t) x, (fbpos_t) y, 4, i==0?4:1, 1); //
} // x = x + sinf(angle) * 10;
// y = y + cosf(angle) * 10;
fb_text(0, s_app.wheel_normed, ":3 :3", FONT_4X5, 1); //
// fb_circle((fbpos_t) x, (fbpos_t) y, 4, i==0?4:1, 1);
fb_7seg_number( // }
2, FBH - 20, //
10, 16, // fb_text(0, s_app.wheel_normed, ":3 :3", FONT_4X5, 1);
2, // th //
2, // spacing // fb_7seg_number(
1, // color // 2, FBH - 20,
s_app.wheel, // 10, 16,
4, // places // 2, // th
2);// decimals // 2, // spacing
// 1, // color
// s_app.wheel,
// 4, // places
fb_blit(); // 2);// decimals
} //
//
//
// fb_blit();
//}
void app_task_main(void *argument) void app_task_main(void *argument)
{ {
PUTS("Main task\r\n"); PUTS("Main task\r\n");
/* test the persistent storage */
EE_Init(EE_CONDITIONAL_ERASE); EE_Init(EE_CONDITIONAL_ERASE);
uint32_t cnt = 0;
EE_Status eest = EE_ReadVariable32bits(1, &cnt);
PRINTF("EE rd status %d, cnt %d\r\n", eest, cnt);
cnt++;
eest = EE_WriteVariable32bits(1, cnt);
PRINTF("EE wr status %d\r\n", eest);
if (eest == EE_CLEANUP_REQUIRED) {
eest = EE_CleanUp();
PRINTF("EE cleanup status %d\r\n", eest);
}
app_analog_init(); app_analog_init();
app_buzzer_init(); app_buzzer_init();
app_knob_init(); app_knob_init();
@ -115,74 +102,78 @@ void app_task_main(void *argument)
oled_init(); oled_init();
fb_clear(); fb_clear();
/* all inited */
// notify threads that we are ready
xTaskNotifyGive(guiTskHandle);
xTaskNotifyGive(heaterTskHandle);
// while(1) { // while(1) {
// LL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); // LL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
// vTaskDelay(pdMS_TO_TICKS(250)); // vTaskDelay(pdMS_TO_TICKS(250));
// LL_IWDG_ReloadCounter(IWDG); // LL_IWDG_ReloadCounter(IWDG);
// } // }
// /* Infinite loop */
// bool old_pushed = app_knob_pushed();
//
// bool any_change = true;
// uint32_t last_redraw = osKernelGetTickCount();
PUTS("Main loop\r\n");
/* Infinite loop */
bool old_pushed = app_knob_pushed();
bool any_change = true;
uint32_t last_redraw = osKernelGetTickCount();
PUTS("Loop\r\n");
for (;;) { for (;;) {
// sampling is done in the heater loop // sampling is done in the heater loop
s_app.oven_temp = app_temp_read_oven(); // s_app.oven_temp = app_temp_read_oven();
//
uint16_t old_wheel = s_app.wheel; // uint16_t old_wheel = s_app.wheel;
s_app.wheel = app_knob_get_raw(); // s_app.wheel = app_knob_get_raw();
//
// TODO do this with interrupt and/or debouncing // // TODO do this with interrupt and/or debouncing
bool pushed = app_knob_pushed(); // bool pushed = app_knob_pushed();
if (pushed && !old_pushed) { // if (pushed && !old_pushed) {
s_app.run ^= 1; // s_app.run ^= 1;
app_heater_enable(s_app.run); // app_heater_enable(s_app.run);
app_buzzer_beep(); // app_buzzer_beep();
any_change = true; // any_change = true;
} // }
old_pushed = pushed; // old_pushed = pushed;
//
//
int16_t wheel_change = (int16_t)(s_app.wheel - old_wheel); // int16_t wheel_change = (int16_t)(s_app.wheel - old_wheel);
if (wheel_change != 0) { // if (wheel_change != 0) {
s_app.wheel_normed += wheel_change; // s_app.wheel_normed += wheel_change;
if (s_app.wheel_normed < 0) { // if (s_app.wheel_normed < 0) {
s_app.wheel_normed = 0; // s_app.wheel_normed = 0;
} // }
if (s_app.wheel_normed > 500) { // if (s_app.wheel_normed > 500) {
s_app.wheel_normed = 500; // s_app.wheel_normed = 500;
} // }
//
int16_t old_temp = s_app.set_temp; // int16_t old_temp = s_app.set_temp;
//
s_app.set_temp = (s_app.wheel_normed / 2) * 5; // s_app.set_temp = (s_app.wheel_normed / 2) * 5;
//
if (old_temp != s_app.set_temp) { // if (old_temp != s_app.set_temp) {
app_buzzer_beep(); // app_buzzer_beep();
app_heater_set_target((float) s_app.set_temp); // app_heater_set_target((float) s_app.set_temp);
any_change = true; // any_change = true;
} // }
} // }
//
uint32_t now = osKernelGetTickCount(); // uint32_t now = osKernelGetTickCount();
if (any_change || (now - last_redraw > pdMS_TO_TICKS(500))) { // if (any_change || (now - last_redraw > pdMS_TO_TICKS(500))) {
last_redraw = now; // last_redraw = now;
redraw_display(); // redraw_display();
any_change = false; // any_change = false;
//
// Blink // // Blink
LL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); //
} // }
vTaskDelay(pdMS_TO_TICKS(10)); vTaskDelay(pdMS_TO_TICKS(100));
// feed dogs // feed dogs
LL_IWDG_ReloadCounter(IWDG); app_safety_poll();
} }
} }

@ -9,6 +9,7 @@
#include "gpio.h" #include "gpio.h"
#include "spi.h" #include "spi.h"
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "app_safety.h"
#define SSD1309_HEIGHT 64 #define SSD1309_HEIGHT 64
@ -236,6 +237,8 @@ void oled_data(uint8_t *data, int len)
void fb_blit() void fb_blit()
{ {
app_safety_pass_display_updating();
#if 0 #if 0
oled_data(fb, FB_LEN); oled_data(fb, FB_LEN);
#else #else

@ -0,0 +1,64 @@
/**
* TODO file description
*/
#include "app_safety.h"
#include "app_heater.h"
#include "snprintf.h"
#include "stm32f1xx_ll_iwdg.h"
#include "stm32f1xx_ll_gpio.h"
#include "main.h"
#define HB_FLAG_TEMP_NORMAL (1 << 0)
#define HB_FLAG_ADC_SAMPLING (1 << 1)
#define HB_FLAG_TEMP_CALCULATION (1 << 2)
#define HB_FLAG_REG_LOOP (1 << 3)
#define HB_FLAG_DISPLAY_UPDATING (1 << 4)
#define HB_FLAG_SOC_TEMP_OK (1 << 5)
#define HB_FLAG_ALL (0b111111)
static volatile uint32_t heartbeat_flags = 0;
void app_safety_pass_temp_normal() {
heartbeat_flags |= HB_FLAG_TEMP_NORMAL;
}
void app_safety_pass_adc_sampling() {
heartbeat_flags |= HB_FLAG_ADC_SAMPLING;
}
void app_safety_pass_temp_calculation() {
heartbeat_flags |= HB_FLAG_TEMP_CALCULATION;
}
void app_safety_pass_reg_loop_running() {
heartbeat_flags |= HB_FLAG_REG_LOOP;
}
void app_safety_pass_display_updating() {
heartbeat_flags |= HB_FLAG_DISPLAY_UPDATING;
}
void app_safety_pass_soc_temp_ok() {
heartbeat_flags |= HB_FLAG_SOC_TEMP_OK;
}
void app_safety_poll() {
if ((heartbeat_flags & HB_FLAG_ALL) == HB_FLAG_ALL) {
LL_IWDG_ReloadCounter(IWDG);
LL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
heartbeat_flags = 0;
}
}
// emergency shutdown, this must not block use RTOS since it can be called from fault handlers or interrupt
void __attribute__((noreturn)) app_emergency_stop() {
app_heater_emergency_shutdown();
PUTS("\r\n*** EMERGENCY STOP ***\r\n");
while (1) {
// wait for the watchdog to bite
}
}

@ -0,0 +1,30 @@
/**
* TODO file description
*/
#ifndef BLUEPILLTROUBA_APP_SAFETY_H
#define BLUEPILLTROUBA_APP_SAFETY_H
/**
* Check the pass flags. If all are set, reset the WD and clear flags.
*
* This effectively makes the WD bite when either of the subsystems fails.
*/
void app_safety_poll();
void app_emergency_stop()
__attribute__((noreturn));
void app_safety_pass_temp_normal();
void app_safety_pass_adc_sampling();
void app_safety_pass_temp_calculation();
void app_safety_pass_reg_loop_running();
void app_safety_pass_display_updating();
void app_safety_pass_soc_temp_ok();
#endif //BLUEPILLTROUBA_APP_SAFETY_H

@ -10,6 +10,7 @@
#include "app_temp.h" #include "app_temp.h"
#include "adc.h" #include "adc.h"
#include "snprintf.h" #include "snprintf.h"
#include "app_safety.h"
/* DMA dest */ /* DMA dest */
static volatile uint16_t adc_values[4]; static volatile uint16_t adc_values[4];
@ -233,6 +234,16 @@ void app_temp_sample()
sum /= depth; sum /= depth;
} }
s_analog.oven_temp = sum; s_analog.oven_temp = sum;
app_safety_pass_temp_calculation();
if (s_analog.oven_temp >= 5.0 && s_analog.oven_temp <= 455.0) {
app_safety_pass_temp_normal();
}
if (s_analog.soc_temp >= 5.0 && s_analog.soc_temp <= 80.0) {
app_safety_pass_soc_temp_ok();
}
} }
float app_temp_read_oven() float app_temp_read_oven()
@ -247,7 +258,7 @@ float app_temp_read_soc()
void app_temp_adc_eos() void app_temp_adc_eos()
{ {
//PUTCHAR('a'); app_safety_pass_adc_sampling();
// notify // notify
memcpy((void *) &s_analog.adc_averagebuf[s_analog.averagebuf_ptr * 4], (const void *) adc_values, 4 * sizeof(uint16_t)); memcpy((void *) &s_analog.adc_averagebuf[s_analog.averagebuf_ptr * 4], (const void *) adc_values, 4 * sizeof(uint16_t));

@ -59,6 +59,7 @@
/* Private function prototypes -----------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void); void SystemClock_Config(void);
void MX_FREERTOS_Init(void); void MX_FREERTOS_Init(void);
/* USER CODE BEGIN PFP */ /* USER CODE BEGIN PFP */
@ -136,8 +137,8 @@ int main(void)
/* We should never get here as control is now taken by the scheduler */ /* We should never get here as control is now taken by the scheduler */
/* Infinite loop */ /* Infinite loop */
/* USER CODE BEGIN WHILE */ /* USER CODE BEGIN WHILE */
while (1) app_emergency_stop();
{ while (1) {
/* USER CODE END WHILE */ /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */ /* USER CODE BEGIN 3 */
@ -152,30 +153,26 @@ int main(void)
void SystemClock_Config(void) void SystemClock_Config(void)
{ {
LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); LL_FLASH_SetLatency(LL_FLASH_LATENCY_2);
while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_2) while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_2) {
{
} }
LL_RCC_HSI_SetCalibTrimming(16); LL_RCC_HSI_SetCalibTrimming(16);
LL_RCC_HSI_Enable(); LL_RCC_HSI_Enable();
/* Wait till HSI is ready */ /* Wait till HSI is ready */
while(LL_RCC_HSI_IsReady() != 1) while (LL_RCC_HSI_IsReady() != 1) {
{
} }
LL_RCC_LSI_Enable(); LL_RCC_LSI_Enable();
/* Wait till LSI is ready */ /* Wait till LSI is ready */
while(LL_RCC_LSI_IsReady() != 1) while (LL_RCC_LSI_IsReady() != 1) {
{
} }
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI_DIV_2, LL_RCC_PLL_MUL_16); LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI_DIV_2, LL_RCC_PLL_MUL_16);
LL_RCC_PLL_Enable(); LL_RCC_PLL_Enable();
/* Wait till PLL is ready */ /* Wait till PLL is ready */
while(LL_RCC_PLL_IsReady() != 1) while (LL_RCC_PLL_IsReady() != 1) {
{
} }
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
@ -184,8 +181,7 @@ void SystemClock_Config(void)
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
/* Wait till System clock is ready */ /* Wait till System clock is ready */
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {
{
} }
LL_Init1msTick(64000000); LL_Init1msTick(64000000);
@ -207,13 +203,12 @@ void Error_Handler(void)
/* User can add his own implementation to report the HAL error return state */ /* User can add his own implementation to report the HAL error return state */
__disable_irq(); __disable_irq();
PUTS("Error_Handler\r\n"); PUTS("Error_Handler\r\n");
while (1) app_emergency_stop();
{
}
/* USER CODE END Error_Handler_Debug */ /* USER CODE END Error_Handler_Debug */
} }
#ifdef USE_FULL_ASSERT #ifdef USE_FULL_ASSERT
/** /**
* @brief Reports the name of the source file and the source line number * @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred. * where the assert_param error has occurred.
@ -225,8 +220,10 @@ void assert_failed(uint8_t *file, uint32_t line)
{ {
/* USER CODE BEGIN 6 */ /* USER CODE BEGIN 6 */
PRINTF("assert_failed %s:%d", (const char *) file, (int) line); PRINTF("assert_failed %s:%d", (const char *) file, (int) line);
app_emergency_stop();
/* User can add his own implementation to report the file name and line number, /* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */ /* USER CODE END 6 */
} }
#endif /* USE_FULL_ASSERT */ #endif /* USE_FULL_ASSERT */

@ -80,10 +80,11 @@ void NMI_Handler(void)
return; return;
} }
app_emergency_stop();
/* USER CODE END NonMaskableInt_IRQn 0 */ /* USER CODE END NonMaskableInt_IRQn 0 */
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */ /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
while (1) while (1) {
{
} }
/* USER CODE END NonMaskableInt_IRQn 1 */ /* USER CODE END NonMaskableInt_IRQn 1 */
} }
@ -95,10 +96,10 @@ void HardFault_Handler(void)
{ {
/* USER CODE BEGIN HardFault_IRQn 0 */ /* USER CODE BEGIN HardFault_IRQn 0 */
PUTS("HardFault_Handler\r\n"); PUTS("HardFault_Handler\r\n");
app_emergency_stop();
/* USER CODE END HardFault_IRQn 0 */ /* USER CODE END HardFault_IRQn 0 */
while (1) while (1) {
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */ /* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */ /* USER CODE END W1_HardFault_IRQn 0 */
} }
@ -111,10 +112,10 @@ void MemManage_Handler(void)
{ {
/* USER CODE BEGIN MemoryManagement_IRQn 0 */ /* USER CODE BEGIN MemoryManagement_IRQn 0 */
PUTS("MemManage_Handler\r\n"); PUTS("MemManage_Handler\r\n");
app_emergency_stop();
/* USER CODE END MemoryManagement_IRQn 0 */ /* USER CODE END MemoryManagement_IRQn 0 */
while (1) while (1) {
{
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
/* USER CODE END W1_MemoryManagement_IRQn 0 */ /* USER CODE END W1_MemoryManagement_IRQn 0 */
} }
@ -127,10 +128,10 @@ void BusFault_Handler(void)
{ {
/* USER CODE BEGIN BusFault_IRQn 0 */ /* USER CODE BEGIN BusFault_IRQn 0 */
PUTS("BusFault_Handler\r\n"); PUTS("BusFault_Handler\r\n");
app_emergency_stop();
/* USER CODE END BusFault_IRQn 0 */ /* USER CODE END BusFault_IRQn 0 */
while (1)
{ while (1) {
/* USER CODE BEGIN W1_BusFault_IRQn 0 */ /* USER CODE BEGIN W1_BusFault_IRQn 0 */
/* USER CODE END W1_BusFault_IRQn 0 */ /* USER CODE END W1_BusFault_IRQn 0 */
} }
@ -143,10 +144,10 @@ void UsageFault_Handler(void)
{ {
/* USER CODE BEGIN UsageFault_IRQn 0 */ /* USER CODE BEGIN UsageFault_IRQn 0 */
PUTS("UsageFault_Handler\r\n"); PUTS("UsageFault_Handler\r\n");
app_emergency_stop();
/* USER CODE END UsageFault_IRQn 0 */ /* USER CODE END UsageFault_IRQn 0 */
while (1)
{ while (1) {
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */ /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
/* USER CODE END W1_UsageFault_IRQn 0 */ /* USER CODE END W1_UsageFault_IRQn 0 */
} }
@ -174,8 +175,7 @@ void SysTick_Handler(void)
/* USER CODE END SysTick_IRQn 0 */ /* USER CODE END SysTick_IRQn 0 */
#if (INCLUDE_xTaskGetSchedulerState == 1) #if (INCLUDE_xTaskGetSchedulerState == 1)
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
{
#endif /* INCLUDE_xTaskGetSchedulerState */ #endif /* INCLUDE_xTaskGetSchedulerState */
xPortSysTickHandler(); xPortSysTickHandler();
#if (INCLUDE_xTaskGetSchedulerState == 1) #if (INCLUDE_xTaskGetSchedulerState == 1)
@ -221,8 +221,7 @@ void EXTI9_5_IRQHandler(void)
bool state = LL_GPIO_IsInputPinSet(KNOB_PUSH_GPIO_Port, KNOB_PUSH_Pin); bool state = LL_GPIO_IsInputPinSet(KNOB_PUSH_GPIO_Port, KNOB_PUSH_Pin);
/* USER CODE END EXTI9_5_IRQn 0 */ /* USER CODE END EXTI9_5_IRQn 0 */
if (LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_8) != RESET) if (LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_8) != RESET) {
{
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_8); LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_8);
/* USER CODE BEGIN LL_EXTI_LINE_8 */ /* USER CODE BEGIN LL_EXTI_LINE_8 */

@ -52,6 +52,7 @@ Core/Src/app_temp.c \
Core/Src/app_knob.c \ Core/Src/app_knob.c \
Core/Src/app_buzzer.c \ Core/Src/app_buzzer.c \
Core/Src/app_heater.c \ Core/Src/app_heater.c \
Core/Src/app_safety.c \
Core/Src/uart_stdout.c \ Core/Src/uart_stdout.c \
Core/Src/stm32f1xx_it.c \ Core/Src/stm32f1xx_it.c \
Core/Src/system_stm32f1xx.c \ Core/Src/system_stm32f1xx.c \
@ -244,10 +245,10 @@ build: all
size: $(BUILD_DIR)/$(TARGET).elf size: $(BUILD_DIR)/$(TARGET).elf
$(SZ) $< $(SZ) $<
flash-stlink: $(BUILD_DIR)/$(TARGET).bin flash: $(BUILD_DIR)/$(TARGET).bin
st-flash write $< 0x8000000 st-flash write $< 0x8000000
flash: $(BUILD_DIR)/$(TARGET).bin flash-pico: $(BUILD_DIR)/$(TARGET).bin
pico-openocd -f target/stm32f1x.cfg -c "program $< 0x08000000 verify reset exit" pico-openocd -f target/stm32f1x.cfg -c "program $< 0x08000000 verify reset exit"
analyze: $(BUILD_DIR)/$(TARGET).elf analyze: $(BUILD_DIR)/$(TARGET).elf

Loading…
Cancel
Save