29
29
#include < drivers/usart/usart_sync.h>
30
30
31
31
//
32
- // shared by both panic and PostMortem debugging
32
+ // Shared by both panic and PostMortem debugging
33
33
//
34
34
static void minserial_begin () {
35
35
#if !WITHIN(SERIAL_PORT, 1, 3)
36
36
#warning "MinSerial requires a physical UART port for output."
37
37
#warning "Disabling MinSerial because the used serial port is not a HW port."
38
38
#else
39
39
40
- // prepare usart_sync configuration
40
+ // Prepare usart_sync configuration
41
41
const stc_usart_uart_init_t usart_config = {
42
- .enClkMode = UsartIntClkCkNoOutput,
43
- .enClkDiv = UsartClkDiv_1,
44
- .enDataLength = UsartDataBits8,
45
- .enDirection = UsartDataLsbFirst,
46
- .enStopBit = UsartOneStopBit,
47
- .enParity = UsartParityNone,
48
- .enSampleMode = UsartSampleBit8,
49
- .enDetectMode = UsartStartBitFallEdge,
50
- .enHwFlow = UsartRtsEnable,
42
+ .enClkMode = UsartIntClkCkNoOutput,
43
+ .enClkDiv = UsartClkDiv_1,
44
+ .enDataLength = UsartDataBits8,
45
+ .enDirection = UsartDataLsbFirst,
46
+ .enStopBit = UsartOneStopBit,
47
+ .enParity = UsartParityNone,
48
+ .enSampleMode = UsartSampleBit8,
49
+ .enDetectMode = UsartStartBitFallEdge,
50
+ .enHwFlow = UsartRtsEnable,
51
51
};
52
52
53
- // initializes usart_sync driver
53
+ // Initializes usart_sync driver
54
54
#define __USART_SYNC_INIT (port_no, baud, config ) \
55
55
usart_sync_init (M4_USART##port_no, \
56
56
BOARD_USART##port_no##_TX_PIN, \
57
57
baud, \
58
58
config);
59
59
#define USART_SYNC_INIT (port_no, baud, config ) __USART_SYNC_INIT(port_no, baud, config)
60
60
61
- // this will reset the baudrate to what is defined in Configuration.h,
61
+ // This will reset the baudrate to what is defined in Configuration.h,
62
62
// ignoring any changes made with e.g. M575.
63
63
// keeping the dynamic baudrate would require re-calculating the baudrate
64
64
// using the register values, which is a pain...
@@ -74,8 +74,7 @@ static void minserial_begin() {
74
74
75
75
static void minserial_putc (char c) {
76
76
#if WITHIN(SERIAL_PORT, 1, 3)
77
- #define __USART_SYNC_PUTC (port_no, ch ) \
78
- usart_sync_putc (M4_USART##port_no, ch);
77
+ #define __USART_SYNC_PUTC (port_no, ch ) usart_sync_putc(M4_USART##port_no, ch);
79
78
#define USART_SYNC_PUTC (port_no, ch ) __USART_SYNC_PUTC(port_no, ch)
80
79
81
80
USART_SYNC_PUTC (SERIAL_PORT, c);
@@ -86,20 +85,19 @@ static void minserial_putc(char c) {
86
85
}
87
86
88
87
//
89
- // panic only
88
+ // Panic only
90
89
//
91
90
#ifdef PANIC_ENABLE
91
+
92
92
void panic_begin () {
93
93
minserial_begin ();
94
-
95
94
panic_puts (" \n\n PANIC:\n " );
96
95
}
97
96
98
97
void panic_puts (const char *str) {
99
- while (*str) {
100
- minserial_putc (*str++);
101
- }
98
+ while (*str) minserial_putc (*str++);
102
99
}
100
+
103
101
#endif // PANIC_ENABLE
104
102
105
103
//
@@ -111,9 +109,9 @@ void panic_puts(const char *str) {
111
109
#include < drivers/panic/fault_handlers.h>
112
110
113
111
void fault_handlers_init () {
114
- // enable cpu traps:
115
- // - divide by zero
116
- // - unaligned access
112
+ // Enable cpu traps:
113
+ // - Divide by zero
114
+ // - Unaligned access
117
115
SCB->CCR |= SCB_CCR_DIV_0_TRP_Msk; // | SCB_CCR_UNALIGN_TRP_Msk;
118
116
}
119
117
@@ -138,16 +136,14 @@ extern "C" {
138
136
#endif // POSTMORTEM_DEBUGGING || PANIC_ENABLE
139
137
140
138
//
141
- // panic_end is always required to print the '!!' to the host
139
+ // Panic_end is always required to print the '!!' to the host
142
140
//
143
141
void panic_end () {
144
- // print '!!' to signal error to host
145
- // do it 10x so it's not missed
146
- for (int i = 0 ; i < 10 ; i++) {
147
- panic_printf (" \n !!\n " );
148
- }
142
+ // Print '!!' to signal error to host
143
+ // Do it 10x so it's not missed
144
+ for (uint_fast8_t i = 10 ; i--;) panic_printf (" \n !!\n " );
149
145
150
- // then , reset the board
146
+ // Then , reset the board
151
147
NVIC_SystemReset ();
152
148
}
153
149
0 commit comments