Skip to content

Commit 72573e1

Browse files
committed
Added an example of creating a structure and outputting data (for STM32F401RET6)
An example for STM32F401RET6 has been added using the scheduler's header file code - it describes how to create a structure object, create a build script, and create a project with HAL as a whole
1 parent 034c6f5 commit 72573e1

17 files changed

Lines changed: 1318 additions & 392 deletions

File tree

examples/stm32f4x/Makefile

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,30 @@ include config/chip.mk
55
CC = arm-none-eabi-gcc
66
OBJCOPY = arm-none-eabi-objcopy
77

8-
# Параметры ядра
9-
CPU = -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4-sp-d16
8+
CPU = -mcpu=cortex-m4
9+
FPU = -mfpu=fpv4-sp-d16
10+
FLOAT-ABI = -mfloat-abi=hard
11+
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
1012

11-
CFLAGS = $(CPU) -O2 -Wall
13+
OPT = -Og
14+
15+
CFLAGS = $(MCU) $(OPT) -Wall -fdata-sections -ffunction-sections
16+
CFLAGS += -DUSE_HAL_DRIVER
1217
CFLAGS += -Iapp/inc
1318
CFLAGS += -Iconfig
1419
CFLAGS += -Iplatform/hal/Inc
15-
CFLAGS += -I../../scheduler/inc
1620
CFLAGS += -Iplatform/cmsis/CMSIS/Include
1721
CFLAGS += -Iplatform/cmsis/CMSIS/Device/ST/STM32F4xx/Include
18-
CFLAGS += -DUSE_HAL_DRIVER $(DEFS)
22+
CFLAGS += -I../../scheduler/inc
23+
CFLAGS += $(DEFS)
24+
25+
ASFLAGS = $(MCU) $(OPT)
1926

20-
LDFLAGS = -T platform/linker/$(LDSCRIPT) -nostartfiles --specs=nosys.specs --specs=nano.specs
27+
LDFLAGS = -T platform/linker/$(LDSCRIPT) \
28+
-nostartfiles \
29+
--specs=nosys.specs \
30+
--specs=nano.specs \
31+
-Wl,--gc-sections
2132

2233
SRC = \
2334
app/src/main.c \
@@ -27,17 +38,22 @@ platform/cmsis/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c \
2738
platform/hal/Src/stm32f4xx_hal.c \
2839
platform/hal/Src/stm32f4xx_hal_gpio.c \
2940
platform/hal/Src/stm32f4xx_hal_rcc.c \
41+
platform/hal/Src/stm32f4xx_hal_rcc_ex.c \
3042
platform/hal/Src/stm32f4xx_hal_cortex.c \
3143
platform/hal/Src/stm32f4xx_hal_uart.c \
32-
platform/hal/Src/stm32f4xx_hal_dma.c
44+
platform/hal/Src/stm32f4xx_hal_dma.c \
45+
app/src/stm32f4xx_hal_msp.c \
46+
app/src/stm32f4xx_it.c \
47+
app/src/syscalls.c \
48+
app/src/sysmem.c
3349

3450
all: $(TARGET).elf
3551

3652
$(TARGET).elf:
3753
mkdir -p build
3854
$(CC) $(CFLAGS) $(SRC) $(LDFLAGS) -o build/$@
39-
$(OBJCOPY) -O ihex build/$(TARGET).elf build/$(TARGET).hex
40-
$(OBJCOPY) -O binary build/$(TARGET).elf build/$(TARGET).bin
55+
$(OBJCOPY) -O ihex build/$@ build/$(TARGET).hex
56+
$(OBJCOPY) -O binary build/$@ build/$(TARGET).bin
4157

4258
clean:
43-
rm -rf build/*
59+
rm -rf build

examples/stm32f4x/app/inc/main.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
#pragma once
1+
#ifndef STM32F401xE
2+
#define STM32F401xE
3+
#endif
24

3-
#include <stdint.h>
4-
#include <stdbool.h>
5+
#ifndef __MAIN_H
6+
#define __MAIN_H
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
511

612
#include "stm32f4xx_hal.h"
713

8-
/* Прототип clock-функции */
9-
//void SystemClock_Config(void);
14+
void Error_Handler(char* msg);
15+
16+
#ifdef __cplusplus
17+
}
18+
#endif
19+
20+
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef __STM32F4xx_IT_H
2+
#define __STM32F4xx_IT_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
void NMI_Handler(void);
9+
void HardFault_Handler(void);
10+
void MemManage_Handler(void);
11+
void BusFault_Handler(void);
12+
void UsageFault_Handler(void);
13+
void SVC_Handler(void);
14+
void DebugMon_Handler(void);
15+
void PendSV_Handler(void);
16+
void SysTick_Handler(void);
17+
void EXTI9_5_IRQHandler(void);
18+
void TIM3_IRQHandler(void);
19+
void EXTI15_10_IRQHandler(void);
20+
21+
#ifdef __cplusplus
22+
}
23+
#endif
24+
25+
#endif

examples/stm32f4x/app/src/main.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ void SystemClock_Config(void);
1010
void MX_GPIO_Init(void);
1111
void MX_USART2_UART_Init(void);
1212
void sch_task_dispatch(sch_task_t* task);
13-
void SysTick_Handler(void);
1413

1514
int main(void)
1615
{
@@ -77,9 +76,9 @@ void sch_task_dispatch(sch_task_t* task) {
7776

7877
}
7978

80-
void SysTick_Handler(void) {
81-
HAL_IncTick();
82-
}
79+
// void SysTick_Handler(void) {
80+
// HAL_IncTick();
81+
// }
8382

8483
void _init(void) {}
8584

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#include "main.h"
2+
3+
void HAL_MspInit(void)
4+
{
5+
__HAL_RCC_SYSCFG_CLK_ENABLE();
6+
__HAL_RCC_PWR_CLK_ENABLE();
7+
}
8+
9+
/*void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
10+
{
11+
GPIO_InitTypeDef GPIO_InitStruct = {0};
12+
if(hi2c->Instance==I2C1)
13+
{
14+
__HAL_RCC_GPIOB_CLK_ENABLE();
15+
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
16+
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
17+
GPIO_InitStruct.Pull = GPIO_NOPULL;
18+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
19+
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
20+
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
21+
__HAL_RCC_I2C1_CLK_ENABLE();
22+
}
23+
}
24+
25+
void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
26+
{
27+
if(hi2c->Instance==I2C1)
28+
{
29+
__HAL_RCC_I2C1_CLK_DISABLE();
30+
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6);
31+
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);
32+
}
33+
34+
}*/
35+
36+
void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
37+
{
38+
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
39+
if(hrtc->Instance==RTC)
40+
{
41+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
42+
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
43+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
44+
{
45+
//Error_Handler("Error: periph init failure\n");
46+
}
47+
__HAL_RCC_RTC_ENABLE();
48+
}
49+
}
50+
51+
void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
52+
{
53+
if(hrtc->Instance==RTC)
54+
{
55+
__HAL_RCC_RTC_DISABLE();
56+
}
57+
}
58+
59+
/*void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
60+
{
61+
if(htim_base->Instance==TIM3)
62+
{
63+
__HAL_RCC_TIM3_CLK_ENABLE();
64+
HAL_NVIC_SetPriority(TIM3_IRQn, 9, 0);
65+
HAL_NVIC_EnableIRQ(TIM3_IRQn);
66+
}
67+
}
68+
69+
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
70+
{
71+
if(htim_base->Instance==TIM3)
72+
{
73+
__HAL_RCC_TIM3_CLK_DISABLE();
74+
HAL_NVIC_DisableIRQ(TIM3_IRQn);
75+
}
76+
}*/
77+
78+
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
79+
{
80+
GPIO_InitTypeDef GPIO_InitStruct = {0};
81+
if(huart->Instance==USART2)
82+
{
83+
__HAL_RCC_USART2_CLK_ENABLE();
84+
85+
__HAL_RCC_GPIOA_CLK_ENABLE();
86+
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
87+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
88+
GPIO_InitStruct.Pull = GPIO_NOPULL;
89+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
90+
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
91+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
92+
}
93+
}
94+
95+
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
96+
{
97+
if(huart->Instance==USART2)
98+
{
99+
__HAL_RCC_USART2_CLK_DISABLE();
100+
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
101+
}
102+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include "main.h"
2+
#include "stm32f4xx_it.h"
3+
4+
void NMI_Handler(void)
5+
{
6+
while (1)
7+
{
8+
}
9+
}
10+
11+
void HardFault_Handler(void)
12+
{
13+
while (1)
14+
{
15+
}
16+
}
17+
18+
void MemManage_Handler(void)
19+
{
20+
while (1)
21+
{
22+
}
23+
}
24+
25+
void BusFault_Handler(void)
26+
{
27+
while (1)
28+
{
29+
}
30+
}
31+
32+
void UsageFault_Handler(void)
33+
{
34+
while (1)
35+
{
36+
37+
}
38+
}
39+
40+
void SVC_Handler(void)
41+
{
42+
43+
}
44+
45+
void DebugMon_Handler(void)
46+
{
47+
48+
}
49+
50+
void PendSV_Handler(void)
51+
{
52+
53+
}
54+
55+
void SysTick_Handler(void)
56+
{
57+
HAL_IncTick();
58+
}

0 commit comments

Comments
 (0)