Prusa MINI Firmware overview
bsod.c File Reference
#include "bsod.h"
#include "stm32f4xx_hal.h"
#include "config.h"
#include "gui.h"
#include "term.h"
#include "st7789v.h"
#include "window_term.h"
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "safe_state.h"
#include <inttypes.h>
#include "jogwheel.h"
#include "gpio.h"
#include "sys.h"
#include "hwio.h"
#include "version.h"
#include "task.h"
#include "StackMacros.h"

Classes

struct  tskTaskControlBlock
 

Macros

#define PADDING   10
 
#define X_MAX   (display->w - PADDING * 2)
 

Typedefs

typedef struct tskTaskControlBlock tskTCB
 
typedef tskTCB TCB_t
 

Functions

static void get_fw_version (void)
 
static void stop_common (void)
 Put HW into safe state, activate display safe mode and initialize it twice. More...
 
static void print_error (term_t *term, color_t background_color)
 print white error message on background More...
 
void general_error (const char *error, const char *module)
 Marlin stopped. More...
 
void temp_error (const char *error, const char *module, float t_noz, float tt_noz, float t_bed, float tt_bed)
 
void _bsod (const char *fmt, const char *file_name, int line_number,...)
 

Variables

char FW_version_str [22] = { '\0' }
 
PRIVILEGED_INITIALIZED_DATA TCB_t *volatile pxCurrentTCB
 
IWDG_HandleTypeDef hiwdg
 

Macro Definition Documentation

◆ PADDING

#define PADDING   10

◆ X_MAX

#define X_MAX   (display->w - PADDING * 2)

Typedef Documentation

◆ tskTCB

typedef struct tskTaskControlBlock tskTCB

◆ TCB_t

typedef tskTCB TCB_t

Function Documentation

◆ get_fw_version()

static void get_fw_version ( void  )
static
115  {
116  uint8_t FW_version[3];
117  uint16_t fw_parser = FW_VERSION;
118 
119  FW_version[0] = (uint8_t)(fw_parser / 100);
120  fw_parser -= FW_version[0] * 100;
121  FW_version[1] = (uint8_t)(fw_parser / 10);
122  fw_parser -= FW_version[1] * 10;
123  FW_version[2] = (uint8_t)fw_parser;
124 
125 #ifdef PRERELEASE_STR
126  snprintf(FW_version_str, sizeof(FW_version_str), "%d.%d.%d-%s+%d",
127  FW_version[0], FW_version[1], FW_version[2],
128  PRERELEASE_STR, version_build_nr);
129 #else
130  sprintf(FW_version_str, "%d.%d.%d", FW_version[0],
131  FW_version[1], FW_version[2]);
132 #endif
133 }
Here is the caller graph for this function:

◆ stop_common()

static void stop_common ( void  )
static

Put HW into safe state, activate display safe mode and initialize it twice.

139  {
140  hwio_safe_state();
142  hwio_beeper_set_pwm(0, 0);
143  display->init();
144  display->init();
145 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_error()

static void print_error ( term_t term,
color_t  background_color 
)
static

print white error message on background

It prints also firmware version on bottom of the screen.

Parameters
terminput message
background_colorbackground color
153  {
155  get_fw_version();
157 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ general_error()

void general_error ( const char *  error,
const char *  module 
)

Marlin stopped.

Disable interrupts, print red error message and stop in infinite loop.

Known possible reasons.
MSG_INVALID_EXTRUDER_NUM
MSG_T_THERMAL_RUNAWAY
MSG_T_HEATING_FAILED
MSG_T_MAXTEMP
MSG_T_MINTEMP
"Emergency stop (M112)"
"Inactive time kill"

Parameters
errorNull terminated string shown in header
moduleNull terminated string shown in the rest of the screen
174  {
175  __disable_irq();
176  stop_common();
178  term_t term;
179  uint8_t buff[TERM_BUFF_SIZE(20, 16)];
180  term_init(&term, 20, 16, buff);
181 
182  display->draw_text(rect_ui16(PADDING, PADDING, X_MAX, 22), error, gui_defaults.font, //resource_font(IDR_FNT_NORMAL),
185 
186  term_printf(&term, module);
187  term_printf(&term, "\n");
188 
190 
191  render_text_align(rect_ui16(PADDING, 260, X_MAX, 30), "RESET PRINTER", gui_defaults.font,
193 
194  jogwheel_init();
195  gui_reset_jogwheel();
196 
197  //cannot use jogwheel_signals (disabled interrupt)
198  while (1) {
199 #ifndef _DEBUG
201 #endif //_DEBUG
203  sys_reset(); //button press
204  }
205 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ temp_error()

void temp_error ( const char *  error,
const char *  module,
float  t_noz,
float  tt_noz,
float  t_bed,
float  tt_bed 
)
207  {
208  char buff[128];
209  snprintf(buff, sizeof(buff),
210  "The requested %s\ntemperature was not\nreached.\n\nNozzle temp: %d/%d\nBed temp: %d/%d",
211  module, (int)t_noz, (int)tt_noz, (int)t_bed, (int)tt_bed);
212  general_error(error, buff);
213 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _bsod()

void _bsod ( const char *  fmt,
const char *  file_name,
int  line_number,
  ... 
)
215  {
216  va_list args;
217  va_start(args, line_number);
218  __disable_irq(); //disable irq
219 
220  char tskName[configMAX_TASK_NAME_LEN];
221  strncpy(tskName, pxCurrentTCB->pcTaskName, configMAX_TASK_NAME_LEN);
223  StackType_t *pBotOfStack = pxCurrentTCB->pxStack;
224 
225  stop_common();
226 
227 #ifdef PSOD_BSOD
228  display->clear(COLOR_BLACK); //clear with black color
229  //display->draw_icon(point_ui16(75, 40), IDR_PNG_icon_pepa, COLOR_BLACK, 0);
231  display->draw_text(rect_ui16(25, 200, 200, 22), "Happy printing!", resource_font(IDR_FNT_BIG), COLOR_BLACK, COLOR_WHITE);
232 #else
233  display->clear(COLOR_NAVY); //clear with dark blue color
234  term_t term; //terminal structure
235  uint8_t buff[TERM_BUFF_SIZE(20, 16)]; //terminal buffer for 20x16
236  term_init(&term, 20, 16, buff); //initialize terminal structure (clear buffer etc)
237 
238  //remove text before "/" and "\", to get filename without path
239  const char *pc;
240  pc = strrchr(file_name, '/');
241  if (pc != 0)
242  file_name = pc + 1;
243  pc = strrchr(file_name, '\\');
244  if (pc != 0)
245  file_name = pc + 1;
246 
247  vterm_printf(&term, fmt, args); //print text to terminal
248  term_printf(&term, "\n");
249  if (file_name != 0)
250  term_printf(&term, "%s", file_name); //print filename
251  if ((file_name != 0) && (line_number != -1))
252  term_printf(&term, " "); //print space
253  if (line_number != -1)
254  term_printf(&term, "%d", line_number); //print line number
255  if ((file_name != 0) || (line_number != -1))
256  term_printf(&term, "\n"); //new line if there is filename or line number
257 
258  term_printf(&term, "TASK:%s\n", tskName);
259  term_printf(&term, "b:%x", pBotOfStack);
260  term_printf(&term, "t:%x", pTopOfStack);
261 
262  int lines_to_print = term.rows - term.row - 1;
263  int stack_sz = pTopOfStack - pBotOfStack;
264 
265  StackType_t *lastAddr;
266  if (stack_sz < lines_to_print * 2)
267  lastAddr = pBotOfStack - 1;
268  else
269  lastAddr = pTopOfStack - 2 * lines_to_print;
270 
271  for (StackType_t *i = pTopOfStack; i != lastAddr; --i) {
272  term_printf(&term, "%08x ", *i);
273  }
274 
275  print_error(&term, COLOR_NAVY);
276 #endif
277 
278  while (1) //endless loop
279  {
280 #ifndef _DEBUG
281  HAL_IWDG_Refresh(&hiwdg); //watchdog reset
282 #endif //_DEBUG
283 
284  //TODO: safe delay with sleep
285  }
286 
287  va_end(args);
288 }
Here is the call graph for this function:

Variable Documentation

◆ FW_version_str

char FW_version_str[22] = { '\0' }

◆ pxCurrentTCB

PRIVILEGED_INITIALIZED_DATA TCB_t* volatile pxCurrentTCB

◆ hiwdg

Marlin 3D Printer Firmware Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]

Based on Sprinter and grbl. Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program 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 this program. If not, see http://www.gnu.org/licenses/.

hiwdg
IWDG_HandleTypeDef hiwdg
Definition: watchdog.h:24
jogwheel_config
jogwheel_config_t jogwheel_config
Definition: jogwheel.c:95
hwio_beeper_set_pwm
void hwio_beeper_set_pwm(uint32_t per, uint32_t pul)
Definition: hwio_a3ides_2209_02.c:491
COLOR_NAVY
#define COLOR_NAVY
Definition: guitypes.h:56
auto_build.error
bool error
Definition: auto_build.py:637
_term_t::row
uint8_t row
Definition: term.h:51
_term_t::rows
uint8_t rows
Definition: term.h:45
COLOR_WHITE
#define COLOR_WHITE
Definition: guitypes.h:41
hwio_safe_state
void hwio_safe_state(void)
Put hardware into safe state.
Definition: safe_state.c:8
sys_reset
void sys_reset(void)
Definition: sys.cpp:20
pxCurrentTCB
PRIVILEGED_INITIALIZED_DATA TCB_t *volatile pxCurrentTCB
Definition: tasks.c:372
_term_t
Definition: term.h:43
ALIGN_CENTER
#define ALIGN_CENTER
Definition: guitypes.h:19
rect_ui16
static rect_ui16_t rect_ui16(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
Definition: guitypes.h:159
_gui_defaults_t::font
font_t * font
Definition: guitypes.h:110
jogwheel_init
void jogwheel_init(void)
Definition: jogwheel.c:16
padding_ui8
static padding_ui8_t padding_ui8(uint8_t l, uint8_t t, uint8_t r, uint8_t b)
Definition: guitypes.h:164
i
uint8_t i
Definition: screen_test_graph.c:72
general_error
void general_error(const char *error, const char *module)
Marlin stopped.
Definition: bsod.c:174
_display_t::draw_text
display_draw_text_t * draw_text
Definition: display.h:35
get_fw_version
static void get_fw_version(void)
Definition: bsod.c:115
tskTaskControlBlock::pxStack
StackType_t * pxStack
Definition: tasks.c:304
gpio_get
static int gpio_get(uint8_t pin8)
Definition: gpio.h:94
tskTaskControlBlock::pxTopOfStack
volatile StackType_t * pxTopOfStack
Definition: tasks.c:295
HAL_IWDG_Refresh
HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg)
IDR_PNG_icon_pepa_psod
#define IDR_PNG_icon_pepa_psod
Definition: resource.h:61
version_build_nr
const int version_build_nr
build number
Definition: version.c:44
_display_t::init
display_init_t * init
Definition: display.h:27
StackType_t
portSTACK_TYPE StackType_t
Definition: portmacro.h:97
st7789v_enable_safe_mode
void st7789v_enable_safe_mode(void)
enable safe mode (direct acces + safe delay)
Definition: st7789v.c:923
render_term
void render_term(rect_ui16_t rc, term_t *pt, font_t *font, color_t clr0, color_t clr1)
Definition: window_term.c:13
_display_t::clear
display_clear_t * clear
Definition: display.h:29
tskTaskControlBlock::pcTaskName
char pcTaskName[configMAX_TASK_NAME_LEN]
Definition: tasks.c:305
render_text_align
void render_text_align(rect_ui16_t rc, const char *text, font_t *font, color_t clr0, color_t clr1, padding_ui8_t padding, uint16_t flags)
Definition: display_helper.c:6
uint8_t
const uint8_t[]
Definition: 404_html.c:3
IDR_FNT_BIG
#define IDR_FNT_BIG
Definition: resource.h:11
display
display_t * display
Definition: display.c:6
FW_version_str
char FW_version_str[22]
Definition: bsod.c:106
resource_font
font_t * resource_font(uint16_t id)
Definition: guitypes.c:186
term_init
void term_init(term_t *pt, uint8_t cols, uint8_t rows, uint8_t *buff)
Definition: term.c:6
vterm_printf
int vterm_printf(term_t *pt, const char *fmt, va_list va)
Definition: term.c:191
configMAX_TASK_NAME_LEN
#define configMAX_TASK_NAME_LEN
Definition: FreeRTOSConfig.h:113
PADDING
#define PADDING
Definition: bsod.c:135
COLOR_BLACK
#define COLOR_BLACK
Definition: guitypes.h:40
COLOR_RED_ALERT
#define COLOR_RED_ALERT
Definition: guitypes.h:43
stop_common
static void stop_common(void)
Put HW into safe state, activate display safe mode and initialize it twice.
Definition: bsod.c:139
print_error
static void print_error(term_t *term, color_t background_color)
print white error message on background
Definition: bsod.c:153
_display_t::draw_icon
display_draw_icon_t * draw_icon
Definition: display.h:36
_display_t::w
uint16_t w
Definition: display.h:25
TERM_BUFF_SIZE
#define TERM_BUFF_SIZE(c, r)
Definition: term.h:36
gui_defaults
gui_defaults_t gui_defaults
Definition: gui.c:20
background_color
png_structrp png_const_color_16p background_color
Definition: png.h:1302
createSpeedLookupTable.args
args
Definition: createSpeedLookupTable.py:17
_display_t::draw_line
display_draw_line_t * draw_line
Definition: display.h:31
_jogwheel_config_t::pinENC
uint8_t pinENC
Definition: jogwheel.h:23
term_printf
int term_printf(term_t *pt, const char *fmt,...)
Definition: term.c:178
point_ui16
static point_ui16_t point_ui16(uint16_t x, uint16_t y)
Definition: guitypes.h:154
X_MAX
#define X_MAX
Definition: bsod.c:136