Changed the delay function to use SysTicks

interrupts
key 4 years ago
parent 3a61f9f35e
commit cd61c08ab6

@ -5,7 +5,9 @@
extern "C" {
#endif
#include <stdint.h>
#include "../stm32f042/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f0xx.h"
void delayInitMs(uint32_t clk, uint32_t ticks);
void delayMs(uint16_t delay);

@ -1,7 +1,21 @@
#include "delay.h"
#include "../Inc/stm32f0xx_csl.h"
void delayInitMs(uint32_t clk, uint32_t ticks)
{
/* Configure the SysTick to have interrupt in 1ms time base */
SysTick->LOAD = (uint32_t)((clk / ticks) - 1UL); /* set reload register */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk; /* Enable the Systick Timer */
}
void delayMs(uint16_t delay)
{
LL_mDelay(delay);
uint16_t i = 0;
while (delay)
{
if ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) != 0U)
{
delay--;
}
}
}

@ -19,48 +19,10 @@
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "stm32f0xx_csl.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* 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 -----------------------------------------------*/
void SystemClock_Config(void);
//static void MX_GPIO_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int stmStart()
{
/* USER CODE BEGIN 1 */
@ -83,25 +45,6 @@ int stmStart()
/* USER CODE END Init */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
//MX_GPIO_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
// while (1)
// {
/* USER CODE END WHILE */
//LL_GPIO_TogglePin(LED_G_GPIO_Port,LED_G_Pin);
// LL_mDelay(100);
/* USER CODE BEGIN 3 */
// }
/* USER CODE END 3 */
return 1;
}
@ -136,37 +79,6 @@ void SystemClock_Config(void)
LL_SetSystemCoreClock(8000000);
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
/*
static void MX_GPIO_Init(void)
{
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
LL_GPIO_ResetOutputPin(LED_G_GPIO_Port, LED_G_Pin);
GPIO_InitStruct.Pin = LED_G_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(LED_G_GPIO_Port, &GPIO_InitStruct);
}
*/
/* USER CODE BEGIN 4 */
/* 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 */

@ -13,7 +13,10 @@
* and manipulation. It's based on the CMSIS/Device/ST/STM32F0xx/Include/stm32f042x6.h Header file
* to get the obtain the right Registers.
*
*
* @todo:
* - 04.11.21 check if the buad rate calcutation is working good for all awailable baud rates
* - 04.11.21 Implment interrupts asap
* - 04.11.21 Implment other functionalities as they are needed
**************************************************************************************************
*/

@ -10,6 +10,8 @@ int main(int argc, char *argv[])
uint8_t a = '0';
stmStart();
delayInitMs(8000000, 1000);
pinConfig(pinB3, output, pushPull, def_res, def_speed);
pinConfig(pinA0, input, def_stage, pullDown, def_speed);
usartInit( usart2,

Loading…
Cancel
Save