-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
120 lines (102 loc) · 4.17 KB
/
Copy pathmain.c
File metadata and controls
120 lines (102 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
******************************************************************************
* file : main.c
* brief : Main program body
* main() calls the target system initialization, then calls the example entry point.
******************************************************************************
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "mx_basic_stdio_app.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* @user: configure the delay in milliseconds between 2 loop rounds */
#define EXAMPLE_LOOP_DELAY_MS 1000U
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
app_status_t ExecStatus = EXEC_STATUS_UNKNOWN; /* application status */
/* Private functions prototype -----------------------------------------------*/
static void error_handler(void);
/** brief: The application entry point.
* retval: none but we specify int to comply with C99 standard
*/
int main(void)
{
/** System Init: this generated code placed in targets folder initializes your system.
* It calls the initialization (and sets the initial configuration) of the peripherals.
* You can use STM32CubeMX to generate and call this code or not in this project.
* It also contains the HAL initialization and the initial clock configuration.
*/
if (mx_system_init() != SYSTEM_OK)
{
ExecStatus = EXEC_STATUS_ERROR; /* memorize the error */
}
else
{
#if defined(USE_TRACE) && USE_TRACE != 0
/* Initialize basic_stdio separately, but after system init. */
mx_basic_stdio_init();
#endif /* defined(USE_TRACE) && USE_TRACE != 0 */
/** Example execution: this hardware and IDE agnostic code contains the scenario that we demonstrate.
* This is the applicative code showing how to use the peripheral (functionality-wise).
* You might copy/paste it in your own application,
* while you might keep on generating the initialization and configuration code with STM32CubeMX.
*/
ExecStatus = app_init();
/* Run indefinitely app_process if no error occurs */
while (ExecStatus != EXEC_STATUS_ERROR)
{
ExecStatus = app_process();
/* Report success: status LED remains turned on */
led_on(MX_STATUS_LED);
HAL_Delay(EXAMPLE_LOOP_DELAY_MS);
} /* end while */
} /* end applicative part */
/* Reaching this point means a problem occurred */
error_handler();
/* This point must not be reached */
return (0);
} /* end main */
/** The functions below are used to report the example status.
* ----------------------------------------------------------
*/
/** brief: Error notification
* retval: None (infinite loop)
*/
static void error_handler(void)
{
while (1)
{
/* Repeated flashing status LED (50ms on and 2sec off) when execution loop is exited */
led_on(MX_STATUS_LED);
HAL_Delay(50);
led_off(MX_STATUS_LED);
HAL_Delay(2000);
}
} /* end error_handler */
/** Redefines the HardFault handler from the startup file.
* brief: Hard Fault Handler
* retval: None (infinite loop)
*
* The default handler is redefined here so that:
* 1. The example status can be updated.
* 2. You can easily set a breakpoint to investigate the issue.
*/
void HardFault_Handler(void)
{
/* The example encountered an unrecoverable error */
ExecStatus = EXEC_STATUS_ERROR;
/* Take a chance to turn the status LED off (this might fail) */
led_off(MX_STATUS_LED);
/* Unrecoverable error: infinite loop */
while (1);
}