/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * 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. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "stm32f4xx_it.h" #include "stdint.h" #include "stm32f411_sfr.h" #include "rcc_drv.h" #include "gpio_drv.h" #include "uart_drv.h" #include "stdio.h" #include "events.h" #include "stimer.h" #include "counter.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ enum { STATE_SLOW, STATE_MES, STATE_FAST, STATE_RESTART, // ... STATES_TOTAL } state; /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ #define ENABLE (1U) #define STACK_SIZE 100 /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ void delay(uint32_t ms); void alarmMes(uint16_t val); void printValue(uint16_t val); event_t getEvent(); /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ uint8_t buttonPressed = 0; uint8_t bl_enable = 1; void newData(uint8_t data){ UART_WriteChar(USART2, data); if (data == '0'){ GPIO_Write_Pin(GPIOA, 5, GPIO_STATE_LOW); } else{ GPIO_Write_Pin(GPIOA, 5, GPIO_STATE_HIGH); } } uint32_t stack_mes1[STACK_SIZE]; uint32_t* sp_mes1 = &stack_mes1[STACK_SIZE]; uint32_t stack_mes2[STACK_SIZE]; uint32_t* sp_mes2 = &stack_mes2[STACK_SIZE]; void mes1(){ while (1){ UART_WriteStr(USART2, "Process 1\n\r"); delay(1000); } } void mes2(){ while (1){ UART_WriteStr(USART2, "Process 2\n\r"); delay(1000); } } /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ RCC_Init(); SysTickInit(); GPIO_Interrupt_Enable(); RCC->AHB1ENR.B.GPIOAEN = ENABLE; RCC->AHB1ENR.B.GPIOCEN = ENABLE; UART_Init(); UART_SetCallback(newData); /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ /* USER CODE BEGIN 2 */ // GPIOA->MODER.B.MODER5 = GPIO_TYPE_OUTPUT; GPIO_Set_Pin_Mode(GPIOA, 5, GPIO_MODE_OUTPUT); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ *(--sp_mes1) = 0x61000000U; //xPSR *(--sp_mes1) = (uint32_t)&mes1; //PC *(--sp_mes1) = 1; //LR *(--sp_mes1) = 2; //R12 *(--sp_mes1) = 3; //R3 *(--sp_mes1) = 4; //R2 *(--sp_mes1) = 5; //R1 *(--sp_mes1) = 6; //R0 *(--sp_mes2) = 0x61000000U; //xPSR *(--sp_mes2) = (uint32_t)&mes2; //PC *(--sp_mes2) = 7; //LR *(--sp_mes2) = 8; //R12 *(--sp_mes2) = 9; //R3 *(--sp_mes2) = 10; //R2 *(--sp_mes2) = 11; //R1 *(--sp_mes2) = 12; //R0 mes1(); mes2(); while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } void printValue(uint16_t val) { char buf[30]; uint16_t len = sprintf(buf, "Value: %d\n\r", val); UART_WriteStr(USART2, buf); } void alarmMes(uint16_t val) { char buf[30]; uint16_t len = sprintf(buf, "Alarm: %d\n\r", val); UART_WriteStr(USART2, buf); } void EXTI15_10_IRQHandler() { buttonPressed = 1; EXTI->PR.B.PR13 = 1; } /* USER CODE BEGIN 4 */ void delay(uint32_t ms){ uint32_t cur_ticks = GetTicks(); while(GetTicks() - cur_ticks < ms) { } } /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ while (1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */