2026-03-09 11:24:32 +01:00

150 lines
4.5 KiB
C

/* ***************************************************************************************
# Project: task3 - C: Timer & Interrupts
# File: task3.s
#
# Language: C
#
# Hardware: STefi Light v1.1
# Processor: STM32G431KBT6U
#
# Author: Manuel Lederhofer
# Datum: 31.10.2014
#
# Version: 6.1
# History:
# 31.10.2014 ML create file
# 27.09.2018 ML edit comments, extend vector table
# 18.12.2018 ML port from MKL05Z32VLC4 to STM32L476RG
# 27.02.2019 ML move section of exception handlers to bottom of file,
# change ASM pseudo commands from .space to .org
# 25.09.2019 ML minor changes for a better code and comment understanding
# 04.09.2020 HL port from STM32L476RG to STM32F411xE
# 21.09.2020 ML tidy up, comments and formatting
# 29.09.2021 ML port from STM32F411xE to STM32F042K6T6
# 09.03.2022 ML port from STM32F042K6T6 to STM32G431KBT6U
# 17.02.2025 TK move ASM:Interrupts to task2, replace with C:Timer & Interrupts
# 24.06.2025 TK remove "... put your code here ...", remove Systick
#
# Status: working
#
# Description:
# See the description and requirements of the requested application
# in the lab exercise guide.
#
# Notes:
# - MCU speed at startup is 16 MHz
#
# ToDo:
# - Change the example code to match the description and requirements
# of the requested application in the lab exercise guide.
#
#
# Measurements:
# Timers used :
# Current with WFI :
# Current without WFI :
#
************************************************************************************** */
/* ------------------------------------ INCLUDES -------------------------------------- */
#include "stm32g431xx.h"
#include "STefi-Light.h"
/* ------------------------------------ DEFINES --------------------------------------- */
/* ------------------------------------ TYPE DEFINITIONS ------------------------------ */
/* ------------------------------------ GLOBAL VARIABLES ------------------------------ */
/* ------------------------------------ PRIVATE VARIABLES ----------------------------- */
/* ------------------------------------ PROTOTYPES ------------------------------------ */
static void GPIO_init(void);
/* ------------------------------------ M A I N --------------------------------------- */
int main(void)
{
/* --- initialization --- */
__disable_irq(); // disable interrupts globally
GPIO_init();
__enable_irq(); // enable interrupts globally
/* --- one time tasks --- */
/* --- infinite processing loop --- */
while (1)
{
GPIOA->ODR ^= (1 << 0); // toggle LED0
__WFI();
}
return 1;
}
/* ------------------------------------ GLOBAL FUNCTIONS ------------------------------ */
/* ------------------------------------ PRIVATE FUNCTIONS ----------------------------- */
/* ------------------------------------------------------------------------------------ *\
* method: static void GPIO_init(void)
*
* Initializes GPIOs on STefi Light for pins with peripherals attached.
*
* requires: - nothing -
* parameters: - none -
* returns: - nothing -
\* ------------------------------------------------------------------------------------ */
static void GPIO_init(void)
{
/* enable port clocks */
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN; // LEDs: A
/* --- LEDs --- */
GPIOA->ODR |= (1 << 0);
GPIOA->MODER &= ~(3 << 0);
GPIOA->MODER |= (1 << 0); // set LED pin to output
/* --- buttons --- */
/* init */
/* interrupt config for Buttons */
}
/* ------------------------------------------------------------------------------------ *\
* method: static void SysTick_init(void)
*
* At system startup SysTick runs with 1 MHz down to 0.
*
* Register names differ in datasheets.
* ST / CMSIS: ARM:
* - SysTick->CALIB - STK_CALIB
* - SysTick->CTRL - STK_CSR
* - SysTick->LOAD - STK_RVR
* - SysTick->VAL - STK_CVR
*
* requires: - nothing -
* parameters: - none -
* returns: - nothing -
\* ------------------------------------------------------------------------------------ */
/* ************************************ E O F ***************************************** */