Hey guys! I'm working on a project that will hopefully make it's way into production at some point, so I need a way to override the default error(...) macro (and maybe exit() too while I'm at it) to stop it from spitting stuff out on the UART in a production design. In my case, the UART pins are being used for other things, so using them would be potentially destructive. Additionally, I'd like to be able to override these functions without having to modify the mbed libraries, making future library updates easier to implement.
Now, I noticed that mbed_die() is already weakly linked, making it easy to replace in the project code. Therefore, my proposal is to replace the error(...) macro with a weakly linked function. That would also give me the ability to capture any error text and redirect it somewhere else for later discovery by a desktop application. I realize I could accomplish this by creating a custom Stream class that redirects stderr, but since not all targets have DEVICE_STDIO_MESSAGES enabled (in my case the LPC11U35 doesn't, for good reason), this is a fragile solution.
A weakly linked exit() would also be nice to have, as my device is going to be battery powered. As such, exit() will need to ensure that the regulator enable pin gets pulled down if the code ever exits unexpectedly, otherwise the device will get stuck turned on until the battery dies.
Hey guys! I'm working on a project that will hopefully make it's way into production at some point, so I need a way to override the default error(...) macro (and maybe exit() too while I'm at it) to stop it from spitting stuff out on the UART in a production design. In my case, the UART pins are being used for other things, so using them would be potentially destructive. Additionally, I'd like to be able to override these functions without having to modify the mbed libraries, making future library updates easier to implement.
Now, I noticed that mbed_die() is already weakly linked, making it easy to replace in the project code. Therefore, my proposal is to replace the error(...) macro with a weakly linked function. That would also give me the ability to capture any error text and redirect it somewhere else for later discovery by a desktop application. I realize I could accomplish this by creating a custom Stream class that redirects stderr, but since not all targets have DEVICE_STDIO_MESSAGES enabled (in my case the LPC11U35 doesn't, for good reason), this is a fragile solution.
A weakly linked exit() would also be nice to have, as my device is going to be battery powered. As such, exit() will need to ensure that the regulator enable pin gets pulled down if the code ever exits unexpectedly, otherwise the device will get stuck turned on until the battery dies.