Skip to content

Commit fb06bfc

Browse files
committed
stmhal: Clean up fatality indications; remove long-obsolete malloc0.c.
1 parent c9f6f6b commit fb06bfc

5 files changed

Lines changed: 31 additions & 79 deletions

File tree

stmhal/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ SRC_C = \
7171
printf.c \
7272
math.c \
7373
mathsincos.c \
74-
malloc0.c \
7574
gccollect.c \
7675
pybstdio.c \
7776
readline.c \

stmhal/main.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#include <stdio.h>
22
#include <string.h>
33

4-
#include <stm32f4xx_hal.h>
5-
#include <stm32f4xx_hal_gpio.h>
6-
#include "std.h"
4+
#include "stm32f4xx_hal.h"
75

86
#include "misc.h"
97
#include "systick.h"
@@ -14,11 +12,10 @@
1412
#include "lexer.h"
1513
#include "parse.h"
1614
#include "obj.h"
17-
#include "parsehelper.h"
18-
#include "compile.h"
1915
#include "runtime.h"
2016
#include "gc.h"
2117
#include "gccollect.h"
18+
#include "pybstdio.h"
2219
#include "readline.h"
2320
#include "pyexec.h"
2421
#include "usart.h"
@@ -64,12 +61,25 @@ void flash_error(int n) {
6461
}
6562

6663
void __fatal_error(const char *msg) {
67-
#if MICROPY_HW_HAS_LCD
64+
for (volatile uint delay = 0; delay < 10000000; delay++) {
65+
}
66+
led_state(1, 1);
67+
led_state(2, 1);
68+
led_state(3, 1);
69+
led_state(4, 1);
70+
stdout_tx_strn("\nFATAL ERROR:\n", 14);
71+
stdout_tx_strn(msg, strlen(msg));
72+
#if 0 && MICROPY_HW_HAS_LCD
6873
lcd_print_strn("\nFATAL ERROR:\n", 14);
6974
lcd_print_strn(msg, strlen(msg));
7075
#endif
71-
for (;;) {
72-
flash_error(1);
76+
for (uint i = 0;;) {
77+
led_toggle(((i++) & 3) + 1);
78+
for (volatile uint delay = 0; delay < 10000000; delay++) {
79+
}
80+
if (i >= 8) {
81+
__WFI();
82+
}
7383
}
7484
}
7585

@@ -109,16 +119,6 @@ STATIC mp_obj_t pyb_usb_mode(mp_obj_t usb_mode) {
109119

110120
MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_mode_obj, pyb_usb_mode);
111121

112-
void fatality(void) {
113-
led_state(PYB_LED_R1, 1);
114-
led_state(PYB_LED_G1, 1);
115-
led_state(PYB_LED_R2, 1);
116-
led_state(PYB_LED_G2, 1);
117-
for (;;) {
118-
flash_error(1);
119-
}
120-
}
121-
122122
static const char fresh_boot_py[] =
123123
"# boot.py -- run on boot-up\n"
124124
"# can run arbitrary Python, but best to keep it minimal\n"

stmhal/malloc0.c

Lines changed: 0 additions & 37 deletions
This file was deleted.

stmhal/std.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
typedef unsigned int size_t;
22

3-
void __assert_func(void);
4-
53
void *memcpy(void *dest, const void *src, size_t n);
64
void *memmove(void *dest, const void *src, size_t n);
75
void *memset(void *s, int c, size_t n);

stmhal/stm32f4xx_it.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
/* Private macro -------------------------------------------------------------*/
6565
/* Private variables ---------------------------------------------------------*/
6666

67-
extern void fatality();
67+
extern void __fatal_error(const char*);
6868
extern PCD_HandleTypeDef hpcd;
6969

7070
/* Private function prototypes -----------------------------------------------*/
@@ -88,12 +88,10 @@ void NMI_Handler(void)
8888
* @param None
8989
* @retval None
9090
*/
91-
void HardFault_Handler(void)
92-
{
91+
void HardFault_Handler(void) {
9392
/* Go to infinite loop when Hard Fault exception occurs */
94-
while (1)
95-
{
96-
fatality();
93+
while (1) {
94+
__fatal_error("HardFault");
9795
}
9896
}
9997

@@ -102,12 +100,10 @@ void HardFault_Handler(void)
102100
* @param None
103101
* @retval None
104102
*/
105-
void MemManage_Handler(void)
106-
{
103+
void MemManage_Handler(void) {
107104
/* Go to infinite loop when Memory Manage exception occurs */
108-
while (1)
109-
{
110-
fatality();
105+
while (1) {
106+
__fatal_error("MemManage");
111107
}
112108
}
113109

@@ -116,12 +112,10 @@ void MemManage_Handler(void)
116112
* @param None
117113
* @retval None
118114
*/
119-
void BusFault_Handler(void)
120-
{
115+
void BusFault_Handler(void) {
121116
/* Go to infinite loop when Bus Fault exception occurs */
122-
while (1)
123-
{
124-
fatality();
117+
while (1) {
118+
__fatal_error("BusFault");
125119
}
126120
}
127121

@@ -130,12 +124,10 @@ void BusFault_Handler(void)
130124
* @param None
131125
* @retval None
132126
*/
133-
void UsageFault_Handler(void)
134-
{
127+
void UsageFault_Handler(void) {
135128
/* Go to infinite loop when Usage Fault exception occurs */
136-
while (1)
137-
{
138-
fatality();
129+
while (1) {
130+
__fatal_error("UsageFault");
139131
}
140132
}
141133

0 commit comments

Comments
 (0)