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 7f33a85..5415662 100644 Binary files a/README.md and b/README.md differ 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