From 2ed6f1870c293e126d3f95343123883bea015cae Mon Sep 17 00:00:00 2001 From: Mark Rosenau Date: Mon, 22 May 2023 23:45:04 -0500 Subject: [PATCH] add main.h and SystemFault IRQ files. --- .gitignore | 3 +++ README.md | Bin 1408 -> 1644 bytes inc/main.h | 33 +++++++++++++++++++++++++++++++++ main.c | 3 +-- py-f002-project.ewp | 15 +++++++++++++++ py-f002-project.ewt | 15 +++++++++++++++ py-f002-project.eww | 27 +++++++++++++-------------- src/SystemFaultIRQ.c | 20 ++++++++++++++++++++ src/main.c | 19 ------------------- 9 files changed, 100 insertions(+), 35 deletions(-) create mode 100644 .gitignore create mode 100644 inc/main.h create mode 100644 src/SystemFaultIRQ.c delete mode 100644 src/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb86a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/Debug +/settings +/py-f002-project.dep diff --git a/README.md b/README.md index 7f33a8533971028b70b80279dafea1b509d3932e..54156625c51de1fcf1768b7fd1f6b3c417632aa7 100644 GIT binary patch delta 382 zcmZuryG{Z@6g|VzfDj5R3&X^Qf-IEU|l;tYDT|ABl@7 zg`Z(z%^%S51Du%zVqtOTo;mm4bI$w0x-vg0wb8;U>p80**E&$p=pu!WGsw(46f#>i zvya#60}@PdhX?_5ek8t~1X2DYhQkz7vQtQ&j))|&hkJ`IaE%*Wu_U=MLiR4s(PIy( zsPM?W#NKH3)Tr|{+CgFPCQ(HheL8FIG1A_n@vlz9>MC<@l_o?lBl$CCgmHEb5lr;B^V3f~_m%{z} NEOdn9a`;)`2g!00Q^NB ANdN!< diff --git a/inc/main.h b/inc/main.h new file mode 100644 index 0000000..855dddd --- /dev/null +++ b/inc/main.h @@ -0,0 +1,33 @@ +/// +// basic system macros +// + +#ifndef __main_h +#define __main_h + +// System Include Files +#include // offsetof() +#include // abs() +#include // bool type defined properly whether using C99 or C++ +#include // needed for NULL and debug printf. +#include // memset, memcpy +// needed for IAR v8.x+: +#include // including __no_operation() +// CPU specific defines +#include "py32f0xx.h" + +/// +// @brief DEBUG macros +// +#if defined (DEBUG) + #define DEBUG_BREAK() do { __asm("bkpt #0"); } while(0) + #define DEBUG_NOP() __no_operation() + // helps debugging local function vars in debug mode. + #define STATIC static +#else + #define DEBUG_BREAK() + #define DEBUG_NOP() + #define STATIC +#endif + +#endif \ No newline at end of file diff --git a/main.c b/main.c index ee64c80..e85c79b 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,4 @@ -#include -#include "py32f0xx.h" +#include "main.h" void SysTick_Handler() { diff --git a/py-f002-project.ewp b/py-f002-project.ewp index 4701d47..520e05f 100644 --- a/py-f002-project.ewp +++ b/py-f002-project.ewp @@ -1065,6 +1065,15 @@ $PROJ_DIR$\CMSIS\Device\PY32F0xx\Source\system_py32f0xx.c + + inc + + $PROJ_DIR$\inc\main.h + + + $PROJ_DIR$\inc\py32f0xx_hal_conf.h + + PY32_HAL_driver @@ -1353,6 +1362,12 @@ + + src + + $PROJ_DIR$\src\SystemFaultIRQ.c + + $PROJ_DIR$\main.c diff --git a/py-f002-project.ewt b/py-f002-project.ewt index 2d8331c..64be892 100644 --- a/py-f002-project.ewt +++ b/py-f002-project.ewt @@ -1195,6 +1195,15 @@ $PROJ_DIR$\CMSIS\Device\PY32F0xx\Source\system_py32f0xx.c + + inc + + $PROJ_DIR$\inc\main.h + + + $PROJ_DIR$\inc\py32f0xx_hal_conf.h + + PY32_HAL_driver @@ -1483,6 +1492,12 @@ + + src + + $PROJ_DIR$\src\SystemFaultIRQ.c + + $PROJ_DIR$\main.c diff --git a/py-f002-project.eww b/py-f002-project.eww index 0cd604a..c5ac3f0 100644 --- a/py-f002-project.eww +++ b/py-f002-project.eww @@ -1,16 +1,15 @@ - - + - - $WS_DIR$\py-f002-project.ewp - - - - all - - py-f002 project - Debug - - - + + $WS_DIR$\py-f002-project.ewp + + + + all + + py-f002-project + Debug + + + diff --git a/src/SystemFaultIRQ.c b/src/SystemFaultIRQ.c new file mode 100644 index 0000000..8821ad7 --- /dev/null +++ b/src/SystemFaultIRQ.c @@ -0,0 +1,20 @@ +/// +// system Fault handlers +// + +#include "main.h" + +void NMI_Handler(void) +{ + DEBUG_BREAK(); + + exit(ERROR); +} + +void HardFault_Handler(void) +{ + DEBUG_BREAK(); + + exit(ERROR); +} + diff --git a/src/main.c b/src/main.c deleted file mode 100644 index ce8e478..0000000 --- a/src/main.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include "py32f0xx.h" - -void SysTick_Handler() -{ - HAL_IncTick(); -} - -int main (void) -{ - HAL_Init(); - SystemCoreClockUpdate(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - HAL_GPIO_Init(GPIOB, &(GPIO_InitTypeDef){.Mode = GPIO_MODE_OUTPUT_OD, .Pin = GPIO_PIN_0}); - while(1) { - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0); - HAL_Delay(100); - } -} \ No newline at end of file