forked from wangyeee/STM32F4-FreeRTOS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
165 lines (146 loc) · 5.5 KB
/
main.c
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "stm32f4xx.h"
#include "FreeRTOS.h"
#include "task.h"
#include "math.h"
#include "stdio.h"
#include "stm32f4xx_usart.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_sdio.h"
#include "example.h"
#include "reading_bmp.h"
#define USE_FILELIB_STDIO_COMPAT_NAMES
void init_USART3(void);
void init_LED(void);
void init_SDcard(void);
void test_FPU_test(void* p);
void test_SDcard(void* p);
int main(void) {
uint8_t ret = pdFALSE;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
init_USART3();
//init_LED();
//init_SDcard();
example_fat_fs();
example_bmp();
// ret = xTaskCreate(test_SDcard, "FPU", 512, NULL, 1, NULL);
ret = xTaskCreate(test_FPU_test, "FPU", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
if (ret == pdTRUE) {
printf("System Started!\n");
vTaskStartScheduler(); // should never return
} else {
printf("System Error!\n");
// --TODO blink some LEDs to indicates fatal system error
}
for (;;);
}
void vApplicationTickHook(void) {
}
/* vApplicationMallocFailedHook() will only be called if
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
function that will get called if a call to pvPortMalloc() fails.
pvPortMalloc() is called internally by the kernel whenever a task, queue,
timer or semaphore is created. It is also called by various parts of the
demo application. If heap_1.c or heap_2.c are used, then the size of the
heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
to query the size of free heap space that remains (although it does not
provide information on how the remaining heap might be fragmented). */
void vApplicationMallocFailedHook(void) {
taskDISABLE_INTERRUPTS();
for(;;);
}
/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
task. It is essential that code added to this hook function never attempts
to block in any way (for example, call xQueueReceive() with a block time
specified, or call vTaskDelay()). If the application makes use of the
vTaskDelete() API function (as this demo application does) then it is also
important that vApplicationIdleHook() is permitted to return to its calling
function, because it is the responsibility of the idle task to clean up
memory allocated by the kernel to any task that has since been deleted. */
void vApplicationIdleHook(void) {
}
void vApplicationStackOverflowHook(xTaskHandle pxTask, signed char *pcTaskName) {
(void) pcTaskName;
(void) pxTask;
/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
function is called if a stack overflow is detected. */
taskDISABLE_INTERRUPTS();
for(;;);
}
void init_SDcard(){
SD_Init();
}
#if 0
void test_SDcard(void* p){
SDIO_CmdInitTypeDef SDIO_CmdInitStruct;
for(;;){
SDIO_CmdStructInit(&SDIO_CmdInitStruct);
SDIO_CmdInitStruct.SDIO_Response=SDIO_Response_Short;
SDIO_CmdInitStruct.SDIO_CmdIndex
SDIO_CmdInitStruct.SDIO_CPSM=SDIO_CPSM_Enable;
SDIO_CmdInitStruct.SDIO_Wait=SDIO_Wait_No;
SDIO_SendCommand(&SDIO_CmdInitStruct);
while(SDIO_GetFlagStatus(SDIO_FLAG_CMDACT)==SET);
GPIO_ToggleBits( GPIOD,GPIO_Pin_12);
vTaskDelay(1000);
}
vTaskDelete(NULL);
SD_CMD
}
#endif
void test_FPU_test(void* p) {
float ff = 1.0f;
printf("Start FPU test task.\n");
for (;;) {
float s = sinf(ff);
ff += s;
// TODO some other test
GPIO_ToggleBits( GPIOD,GPIO_Pin_13);
vTaskDelay(1000);
}
vTaskDelete(NULL);
}
void init_LED(void){
GPIO_InitTypeDef GPIO_InitStruct;
/* Enable GPIO C clock. */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD, ENABLE);
// Setup Blue & Green LED on STM32-Discovery Board to use PWM.
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15; //PD12->LED3 PD13->LED4 PD14->LED5 PDa5->LED6
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; // Alt Function - Push Pull
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init( GPIOD, &GPIO_InitStruct );
GPIO_WriteBit(GPIOD,GPIO_Pin_12,Bit_RESET);
GPIO_WriteBit(GPIOD,GPIO_Pin_13,Bit_RESET);
GPIO_WriteBit(GPIOD,GPIO_Pin_14,Bit_RESET);
GPIO_WriteBit(GPIOD,GPIO_Pin_15,Bit_RESET);
}
/*
* Configure USART3(PB10, PB11) to redirect printf data to host PC.
*/
void init_USART3(void) {
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruct;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);
USART_InitStruct.USART_BaudRate = 115200;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_Init(USART3, &USART_InitStruct);
USART_Cmd(USART3, ENABLE);
}