Skip to content

Commit 530e9d3

Browse files
committed
Changed variable names for registers to avoid namespace conflicts and rtos disabled build fixes
1 parent 2e28dd9 commit 530e9d3

File tree

5 files changed

+59
-56
lines changed

5 files changed

+59
-56
lines changed

platform/mbed_error.c

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
#include <stdlib.h>
1717
#include <stdarg.h>
18-
#include "rtx_os.h"
19-
#include "mbed_rtx.h"
2018
#include "device.h"
2119
#include "platform/mbed_critical.h"
2220
#include "platform/mbed_error.h"
@@ -34,22 +32,6 @@ static mbed_error_ctx first_error_ctx = {0};
3432
static mbed_error_ctx last_error_ctx = {0};
3533
static MbedErrorHook error_hook = NULL;
3634

37-
//Helper function to get the current SP
38-
static unsigned int get_current_sp()
39-
{
40-
//If in Handler mode we are always using MSP
41-
if( __get_IPSR() != 0U ) {
42-
return __get_MSP();
43-
} else {
44-
//Look into CONTROL.SPSEL value
45-
if ((__get_CONTROL() & 2U) == 0U) {
46-
return __get_PSP();//Read PSP
47-
} else {
48-
return __get_MSP();//Read MSP
49-
}
50-
}
51-
}
52-
5335
//Helper function to halt the system
5436
static void mbed_halt_system(void)
5537
{
@@ -124,19 +106,6 @@ MbedErrorStatus handle_error(MbedErrorStatus error_status, const char *error_msg
124106
}
125107
#endif
126108

127-
//Capture thread info
128-
osRtxThread_t *current_thread = osRtxInfo.thread.run.curr;
129-
current_error_ctx.thread_id = (uint32_t)current_thread;
130-
current_error_ctx.thread_entry_address = (uint32_t)current_thread->thread_addr;
131-
current_error_ctx.thread_stack_size = current_thread->stack_size;
132-
current_error_ctx.thread_stack_mem = (uint32_t)current_thread->stack_mem;
133-
current_error_ctx.thread_current_sp = get_current_sp();
134-
135-
#ifndef MBED_CONF_ERROR_LOG_DISABLED
136-
//Log the error with error log
137-
mbed_log_put_error(&current_error_ctx);
138-
#endif
139-
140109
//Use critsect here, as we don't want processing more than one error at the same time
141110
core_util_critical_section_enter();
142111
//Report the error
@@ -153,6 +122,11 @@ MbedErrorStatus handle_error(MbedErrorStatus error_status, const char *error_msg
153122
//Use critsect here, as we don't want processing more than one error at the same time
154123
core_util_critical_section_exit();
155124

125+
#ifndef MBED_CONF_ERROR_LOG_DISABLED
126+
//Log the error with error log
127+
mbed_log_put_error(&current_error_ctx);
128+
#endif
129+
156130
//Call the error hook if available
157131
if(error_hook != NULL) {
158132
error_hook(&last_error_ctx);

platform/mbed_error_report.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
#include <stdlib.h>
1717
#include <stdarg.h>
18-
#include "rtx_os.h"
19-
#include "mbed_rtx.h"
2018
#include "hal/serial_api.h"
2119
#include "hal/itm_api.h"
2220
#include "platform/mbed_error.h"
@@ -56,6 +54,22 @@ static void value_to_dec_str(uint32_t value, char *dec_str)
5654
}
5755
}
5856

57+
//Helper function to get the current SP
58+
static unsigned int get_current_sp()
59+
{
60+
//If in Handler mode we are always using MSP
61+
if( __get_IPSR() != 0U ) {
62+
return __get_MSP();
63+
} else {
64+
//Look into CONTROL.SPSEL value
65+
if ((__get_CONTROL() & 2U) == 0U) {
66+
return __get_PSP();//Read PSP
67+
} else {
68+
return __get_MSP();//Read MSP
69+
}
70+
}
71+
}
72+
5973
void mbed_error_init(void)
6074
{
6175
#if DEVICE_SERIAL && (MBED_CONF_ERROR_REPORT_INTERFACE==DEVICE_SERIAL)
@@ -148,6 +162,7 @@ void mbed_error_print(char *fmtstr, uint32_t *values)
148162
#endif
149163
}
150164

165+
#ifdef MBED_CONF_RTOS_PRESENT
151166
/* Prints thread info from a list */
152167
void print_threads_info(osRtxThread_t *threads)
153168
{
@@ -169,8 +184,9 @@ void print_thread(osRtxThread_t *thread)
169184
data[4]=thread->sp;
170185
mbed_error_print("\nState: 0x%x EntryFn: 0x%x Stack Size: 0x%x Mem: 0x%x SP: 0x%x", data);
171186
}
187+
#endif
172188

173-
void mbed_report_error(const mbed_error_ctx *error_ctx, char *error_msg)
189+
void mbed_report_error(mbed_error_ctx *error_ctx, char *error_msg)
174190
{
175191
int error_code = GET_MBED_ERROR_CODE(error_ctx->error_status);
176192
int error_entity = GET_MBED_ERROR_MODULE(error_ctx->error_status);
@@ -234,10 +250,21 @@ void mbed_report_error(const mbed_error_ctx *error_ctx, char *error_msg)
234250
mbed_error_print("\nFile:%s", &file_name);
235251
mbed_error_print("+0x%x", (uint32_t *)&error_ctx->error_line_number);
236252
}
237-
#endif
253+
#endif
254+
255+
#ifdef MBED_CONF_RTOS_PRESENT
256+
//Capture thread info
257+
osRtxThread_t *current_thread = osRtxInfo.thread.run.curr;
258+
error_ctx->thread_id = (uint32_t)current_thread;
259+
error_ctx->thread_entry_address = (uint32_t)current_thread->thread_addr;
260+
error_ctx->thread_stack_size = current_thread->stack_size;
261+
error_ctx->thread_stack_mem = (uint32_t)current_thread->stack_mem;
262+
error_ctx->thread_current_sp = get_current_sp();
263+
238264
//Take advantage of the fact that the thread info in context struct is consecutively placed
239265
mbed_error_print("\nError Value: 0x%x\nCurrent Thread: Id: 0x%x EntryFn: 0x%x StackSize: 0x%x StackMem: 0x%x SP: 0x%x ",
240266
(uint32_t *)&error_ctx->error_value);
267+
#endif
241268
}
242269

243270
mbed_error_print("\n-- MbedOS Error Info --", NULL);

platform/mbed_error_report.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ extern "C" {
2727
#define MBED_CONF_ERROR_REPORT_INTERFACE DEVICE_SERIAL
2828
#endif
2929

30-
/* Routine to report the error */
31-
void mbed_report_error(const mbed_error_ctx *error_ctx, char *error_msg);
32-
30+
#ifdef MBED_CONF_RTOS_PRESENT
31+
#include "rtx_os.h"
3332
/* Prints thread info from a list */
3433
void print_threads_info(osRtxThread_t *threads);
3534

3635
/* Prints info of a thread(using osRtxThread_t struct)*/
3736
void print_thread(osRtxThread_t *thread);
37+
#endif
3838

39+
/* Routine to report the error */
40+
void mbed_report_error(mbed_error_ctx *error_ctx, char *error_msg);
41+
3942
/* Limited print functionality which prints the string out to
4043
stdout/uart without using stdlib by directly calling serial-api
4144
and also uses less resources

rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "rtx_os.h"
1818
#include "device.h"
19-
#include "mbed_rtx.h"
2019
#include "platform/mbed_error.h"
2120
#include "platform/mbed_error_report.h"
2221

@@ -83,7 +82,7 @@ __NO_RETURN void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_conte
8382
mbed_error_print("\n\n-- MbedOS Fault Handler --\n\n",NULL);
8483

8584
//Now call set_error, to log the error and halt the system
86-
set_error( MAKE_ERROR( MODULE_UNKNOWN, faultStatus ), "System encountered an unrecoverable fault excaption, halting system.", mbed_fault_context.PC, NULL, 0 );
85+
set_error( MAKE_ERROR( MODULE_UNKNOWN, faultStatus ), "System encountered an unrecoverable fault excaption, halting system.", mbed_fault_context.PC_reg, NULL, 0 );
8786

8887
/* In case we return, just spin here, we have already crashed */
8988
for (;;) {

rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@
2121
//WARNING: DO NOT CHANGE THIS STRUCT WITHOUT MAKING CORRESPONDING CHANGES in except.S files.
2222
//Offset of these registers are used by fault handler in except.S
2323
typedef struct {
24-
uint32_t R0;
25-
uint32_t R1;
26-
uint32_t R2;
27-
uint32_t R3;
28-
uint32_t R4;
29-
uint32_t R5;
30-
uint32_t R6;
31-
uint32_t R7;
32-
uint32_t R8;
33-
uint32_t R9;
34-
uint32_t R10;
35-
uint32_t R11;
36-
uint32_t R12;
37-
uint32_t SP;
38-
uint32_t LR;
39-
uint32_t PC;
24+
uint32_t R0_reg;
25+
uint32_t R1_reg;
26+
uint32_t R2_reg;
27+
uint32_t R3_reg;
28+
uint32_t R4_reg;
29+
uint32_t R5_reg;
30+
uint32_t R6_reg;
31+
uint32_t R7_reg;
32+
uint32_t R8_reg;
33+
uint32_t R9_reg;
34+
uint32_t R10_reg;
35+
uint32_t R11_reg;
36+
uint32_t R12_reg;
37+
uint32_t SP_reg;
38+
uint32_t LR_reg;
39+
uint32_t PC_reg;
4040
uint32_t xPSR;
4141
uint32_t PSP;
4242
uint32_t MSP;

0 commit comments

Comments
 (0)