Browse Source

add debug_suspend() / assert print works

makefile_for_cmsis
heck 2 years ago
parent
commit
84fd09ae54
  1. 27
      src/cppmain.cc
  2. 4
      src/cppmain.h

27
src/cppmain.cc

@ -10,6 +10,12 @@ const double pi{ std::acos(-1) };
#define BUFFER_SIZE 512 #define BUFFER_SIZE 512
namespace Heck { namespace Heck {
bool debug_suspend_active = false;
void debug_suspend_continue() {
debug_suspend_active = false;
}
// Serial Logging // Serial Logging
// -------------- // --------------
void log(std::string msg) void log(std::string msg)
@ -72,10 +78,7 @@ namespace Heck {
// CALLBACKS // CALLBACKS
void irq1_cb() void irq1_cb()
{ {
if (!is_running) { debug_suspend_continue();
is_running = true;
return;
}
} }
void timer2_cb() void timer2_cb()
@ -121,7 +124,7 @@ namespace Heck {
{ {
log("buffer_init_sin()"); log("buffer_init_sin()");
for (int i = 0; i < BUFFER_SIZE; i++) { for (int i = 0; i < BUFFER_SIZE; i++) {
float p = float(i) / (float)BUFFER_SIZE - 0.5; float p = float(i) / (float)BUFFER_SIZE - 0.5 / 2.;
u32 val = sin(p) * 4096; u32 val = sin(p) * 4096;
audio_buffer[i] = val; audio_buffer[i] = val;
log(std::to_string(val)); log(std::to_string(val));
@ -149,9 +152,7 @@ namespace Heck {
void main() void main()
{ {
while (!is_running) { heck_debug_suspend();
HAL_Delay(1);
}
log("Starting..."); log("Starting...");
dac_start_dma(); dac_start_dma();
@ -177,6 +178,14 @@ namespace Heck {
// C Linkage (Bridging) // C Linkage (Bridging)
// ---------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------
void heck_debug_suspend(void) {
Heck::debug_suspend_active = true;
while(Heck::debug_suspend_active == true) {
Heck::log("debug_suspend...");
HAL_Delay(1000);
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{ {
if (GPIO_Pin == GPIO_PIN_0) { if (GPIO_Pin == GPIO_PIN_0) {
@ -238,7 +247,7 @@ void assert_failed(uint8_t *file, uint32_t line)
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
int str_size = 1024; int str_size = 1024;
char str[str_size]; char str[str_size];
snprintf(str, str_size, "assert failed: %s:%d"); snprintf(str, str_size, "assert failed: %s:%d",file,line);
heck_log(str); heck_log(str);
} }

4
src/cppmain.h

@ -12,6 +12,7 @@ extern "C" {
void heck_cppmain(void); void heck_cppmain(void);
void heck_log(char* msg); void heck_log(char* msg);
void heck_debug_suspend(void);
void assert_failed(uint8_t* file, uint32_t line); void assert_failed(uint8_t* file, uint32_t line);
void Error_Handler(void); void Error_Handler(void);
@ -32,8 +33,7 @@ extern "C" {
using u32 = uint32_t; using u32 = uint32_t;
namespace Heck { namespace Heck {
bool is_running{ false }; void debug_suspend_continue();
// Serial Logging // Serial Logging
void log(std::string msg); void log(std::string msg);

Loading…
Cancel
Save