so denke ich werden alle LEDs angesteuert

This commit is contained in:
Tobias Kachel 2026-03-09 11:32:15 +01:00
parent e08544a94e
commit ed2f2736d0
17 changed files with 1609 additions and 1441 deletions

View File

@ -0,0 +1,152 @@
/* ***************************************************************************************
* Project: task1 - C:GPIO
* File: task1.c
*
* Language: C
*
* Hardware: STefi Light v1.1
* Processor: STM32G431KBT6U
*
* Author: Manuel Lederhofer
* Datum: 10.09.2021
*
* Version: 2.1
* History:
* 10.09.2021 ML create project
* 09.03.2022 ML port from STM32F042K6T6 to STM32G431KBT6U
* 18.02.2025 TK changed projectname to "C: GPIO)
*
* Status: under development
*
* Description:
* Blinks the red LED of STefi Light, currently.
* This file contains the main routine and the initialization.
*
* 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.
*
************************************************************************************** */
/* ------------------------------------ INCLUDES -------------------------------------- */
#include "stm32g431xx.h"
#include "STefi-Light.h"
/* ------------------------------------ DEFINES --------------------------------------- */
#define LOOPS_PER_MS 1244 // NOP-loops for delay()
#define WAITTIME 500
/* ------------------------------------ TYPE DEFINITIONS ------------------------------ */
/* ------------------------------------ GLOBAL VARIABLES ------------------------------ */
int state = 0;
/* ------------------------------------ PRIVATE VARIABLES ----------------------------- */
/* ------------------------------------ PROTOTYPES ------------------------------------ */
static void GPIO_init(void);
static void delay(const uint16_t ms);
/* ------------------------------------ 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)
{
/* ... add your code to implement the lab assignment ... */
switch (state) {
case 0:
GPIOA->ODR &= ~(1 << 0); // LED0 on
state++;
break;
case 1:
delay(WAITTIME); // wait
state++;
break;
case 2:
GPIOA->ODR |= (1 << 0); // LED0 off
delay(WAITTIME); // wait
state = 0;
break;
default:
break;
}
}
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 |= MASK_LED_ALL;
GPIOA->MODER &= ~(3 << 0);
GPIOA->MODER &= ~(3 << 2);
GPIOA->MODER &= ~(3 << 4);
GPIOA->MODER &= ~(3 << 6);
GPIOA->MODER |= (1 << 0); // set LED pin to output
GPIOA->MODER |= (1 << 2);
GPIOA->MODER |= (1 << 4);
GPIOA->MODER |= (1 << 6);
}
/* ------------------------------------------------------------------------------------ *\
* method: static void delay(const uint16_t ms)
*
* Realizes a millisecond delay by very bad busy-wait.
*
* requires: - nothing -
* parameters: ms - delay time in milliseconds
* returns: - nothing -
\* ------------------------------------------------------------------------------------ */
static void delay(const uint16_t ms)
{
for (uint16_t i = 0; i < ms; ++i)
{
for (uint16_t j = 0; j < LOOPS_PER_MS; ++j)
{
__asm("NOP");
}
}
}
/* ************************************ E O F ***************************************** */

Binary file not shown.

View File

@ -1,10 +1,19 @@
StringVariablePreferencePage=184,154,153,122,
eclipse.preferences.version=1
org.eclipse.debug.ui.MemoryHistoryKnownColor=235,235,235
org.eclipse.debug.ui.MemoryHistoryUnknownColor=170,175,185
org.eclipse.debug.ui.MemoryView.orientation=0
org.eclipse.debug.ui.PREF_CHANGED_VALUE_BACKGROUND=150,80,115
org.eclipse.debug.ui.PREF_LAUNCH_PERSPECTIVES=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>\n<launchPerspectives/>\n
org.eclipse.debug.ui.changedDebugElement=255,128,128
org.eclipse.debug.ui.consoleBackground=53,53,53
org.eclipse.debug.ui.errorColor=225,30,70
org.eclipse.debug.ui.inColor=140,175,210
org.eclipse.debug.ui.outColor=235,235,235
org.eclipse.debug.ui.save_dirty_editors_before_launch=always
org.eclipse.debug.ui.switch_perspective_on_suspend=always
org.eclipse.debug.ui.user_view_bindings=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>\n<viewBindings>\n <view id\="org.eclipse.debug.ui.ExpressionView">\n <perspective id\="org.eclipse.debug.ui.DebugPerspective" userAction\="opened"/>\n </view>\n</viewBindings>\n
overriddenByCSS=,org.eclipse.debug.ui.MemoryHistoryKnownColor,org.eclipse.debug.ui.MemoryHistoryUnknownColor,org.eclipse.debug.ui.PREF_CHANGED_VALUE_BACKGROUND,org.eclipse.debug.ui.changedDebugElement,org.eclipse.debug.ui.consoleBackground,org.eclipse.debug.ui.errorColor,org.eclipse.debug.ui.inColor,org.eclipse.debug.ui.outColor,
pref_state_memento.org.eclipse.debug.ui.BreakpointView=<?xml version\="1.0" encoding\="UTF-8"?>\n<VariablesViewMemento org.eclipse.debug.ui.SASH_DETAILS_PART\="315" org.eclipse.debug.ui.SASH_VIEW_PART\="684">\n<PRESENTATION_CONTEXT_PROPERTIES IMemento.internal.id\="org.eclipse.debug.ui.BreakpointView">\n<BOOLEAN BOOLEAN\="true" IMemento.internal.id\="org.eclipse.debug.ui.check"/>\n</PRESENTATION_CONTEXT_PROPERTIES>\n</VariablesViewMemento>
pref_state_memento.org.eclipse.debug.ui.DebugVieworg.eclipse.debug.ui.DebugView=<?xml version\="1.0" encoding\="UTF-8"?>\r\n<DebugViewMemento org.eclipse.debug.ui.BREADCRUMB_DROPDOWN_AUTO_EXPAND\="false"/>
pref_state_memento.org.eclipse.debug.ui.ExpressionView=<?xml version\="1.0" encoding\="UTF-8"?>\n<VariablesViewMemento org.eclipse.debug.ui.SASH_DETAILS_PART\="315" org.eclipse.debug.ui.SASH_VIEW_PART\="684">\n<PRESENTATION_CONTEXT_PROPERTIES IMemento.internal.id\="org.eclipse.debug.ui.ExpressionView">\n<INTEGER IMemento.internal.id\="initialChildCountLimitForCollections" INTEGER\="100"/>\n<BOOLEAN BOOLEAN\="true" IMemento.internal.id\="PRESENTATION_SHOW_LOGICAL_STRUCTURES"/>\n</PRESENTATION_CONTEXT_PROPERTIES>\n</VariablesViewMemento>

View File

@ -4,7 +4,7 @@ LaunchTargetManager/org.eclipse.launchbar.core.launchTargetType.local,Local/os=w
configDescList=org.eclipse.cdt.dsf.gdb.gdbRemotedescriptorType\:task3 Debug,org.eclipse.cdt.dsf.gdb.gdbRemotedescriptorType\:task3,org.eclipse.cdt.dsf.gdb.gdbRemotedescriptorType\:task4,org.eclipse.cdt.dsf.gdb.gdbRemotedescriptorType\:task2,org.eclipse.cdt.dsf.gdb.gdbRemotedescriptorType\:task1
eclipse.preferences.version=1
org.eclipse.cdt.dsf.gdb.gdbRemotedescriptorType\:A3_Timer/activeLaunchMode=run
org.eclipse.cdt.dsf.gdb.gdbRemotedescriptorType\:task1/activeLaunchMode=debug
org.eclipse.cdt.dsf.gdb.gdbRemotedescriptorType\:task1/activeLaunchMode=run
org.eclipse.cdt.dsf.gdb.gdbRemotedescriptorType\:task1/activeLaunchTarget=null\:---
org.eclipse.cdt.dsf.gdb.gdbRemotedescriptorType\:task2/activeLaunchMode=run
org.eclipse.cdt.dsf.gdb.gdbRemotedescriptorType\:task2/activeLaunchTarget=null\:---

File diff suppressed because one or more lines are too long

View File

@ -74,6 +74,9 @@ int main(void)
switch (state) {
case 0:
GPIOA->ODR &= ~(1 << 0); // LED0 on
GPIOA->ODR &= ~(1 << 1);
GPIOA->ODR &= ~(1 << 2);
GPIOA->ODR &= ~(1 << 3);
state++;
break;
@ -83,6 +86,9 @@ int main(void)
break;
case 2:
GPIOA->ODR |= (1 << 0); // LED0 off
GPIOA->ODR |= (1 << 1);
GPIOA->ODR |= (1 << 2);
GPIOA->ODR |= (1 << 3);
delay(WAITTIME); // wait
state = 0;
break;