mein code in task2

This commit is contained in:
2026-03-24 14:20:19 +01:00
parent 7e0e37a578
commit b19c7f6b51
87 changed files with 10976 additions and 3537 deletions
+1620
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -37,7 +37,7 @@
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_txt_serial_number" value=""/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.watchdog_config" value="none"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkenable_rtos" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkrestart_configurations" value="{&quot;fVersion&quot;:1,&quot;fItems&quot;:[{&quot;fDisplayName&quot;:&quot;Reset&quot;,&quot;fIsSuppressible&quot;:false,&quot;fResetAttribute&quot;:&quot;Software system reset&quot;,&quot;fResetStrategies&quot;:[{&quot;fDisplayName&quot;:&quot;Software system reset&quot;,&quot;fLaunchAttribute&quot;:&quot;system_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset\r\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Hardware reset&quot;,&quot;fLaunchAttribute&quot;:&quot;hardware_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset hardware\r\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Core reset&quot;,&quot;fLaunchAttribute&quot;:&quot;core_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset core\r\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;None&quot;,&quot;fLaunchAttribute&quot;:&quot;no_reset&quot;,&quot;fGdbCommands&quot;:[],&quot;fCmdOptions&quot;:[&quot;-g&quot;]}],&quot;fGdbCommandGroup&quot;:{&quot;name&quot;:&quot;Additional commands&quot;,&quot;commands&quot;:[]},&quot;fStartApplication&quot;:true}]}"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkrestart_configurations" value="{&quot;fVersion&quot;:1,&quot;fItems&quot;:[{&quot;fDisplayName&quot;:&quot;Reset&quot;,&quot;fIsSuppressible&quot;:false,&quot;fResetAttribute&quot;:&quot;Software system reset&quot;,&quot;fResetStrategies&quot;:[{&quot;fDisplayName&quot;:&quot;Software system reset&quot;,&quot;fLaunchAttribute&quot;:&quot;system_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Hardware reset&quot;,&quot;fLaunchAttribute&quot;:&quot;hardware_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset hardware\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Core reset&quot;,&quot;fLaunchAttribute&quot;:&quot;core_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset core\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;None&quot;,&quot;fLaunchAttribute&quot;:&quot;no_reset&quot;,&quot;fGdbCommands&quot;:[],&quot;fCmdOptions&quot;:[&quot;-g&quot;]}],&quot;fGdbCommandGroup&quot;:{&quot;name&quot;:&quot;Additional commands&quot;,&quot;commands&quot;:[]},&quot;fStartApplication&quot;:true}]}"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.enableRtosProxy" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyCustomProperties" value=""/>
<stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriver" value="threadx"/>
+156
View File
@@ -0,0 +1,156 @@
task2.elf: file format elf32-littlearm
Sections:
Idx Name Size VMA LMA File off Algn
0 .vectortable 00000014 08000000 08000000 00001000 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .text 00000074 08000400 08000400 00001400 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .exhand 00000068 08001000 08001000 00002000 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
SYMBOL TABLE:
08000000 l d .vectortable 00000000 .vectortable
08000400 l d .text 00000000 .text
08001000 l d .exhand 00000000 .exhand
08001000 l F .exhand 00000000 _ISR_NMI
08001028 l F .exhand 00000000 _ISR_HARDF
08001050 l F .exhand 00000000 _ISR_S0
08000466 l .text 00000000 .lp1
08001058 l F .exhand 00000000 _ISR_S1
0800105e l .exhand 00000000 .lp2
08000400 g F .text 00000000 init
08000444 g F .text 00000000 main
08000454 g F .text 00000000 delay
08000460 g .text 00000000 stop
Disassembly of section .vectortable:
08000000 <.vectortable>:
8000000: 20004000 .word 0x20004000
8000004: 08000401 .word 0x08000401
8000008: 08001001 .word 0x08001001
800000c: 08001029 .word 0x08001029
8000010: 08001051 .word 0x08001051
Disassembly of section .text:
08000400 <init>:
8000400: b672 cpsid i
8000402: 2000 movs r0, #0
8000404: 2100 movs r1, #0
8000406: 2200 movs r2, #0
8000408: 2300 movs r3, #0
800040a: 2400 movs r4, #0
800040c: 2500 movs r5, #0
800040e: 2600 movs r6, #0
8000410: 2700 movs r7, #0
8000412: 4680 mov r8, r0
8000414: 4681 mov r9, r0
8000416: 4682 mov sl, r0
8000418: 4683 mov fp, r0
800041a: 4684 mov ip, r0
800041c: 4912 ldr r1, [pc, #72] @ (8000468 <.lp1+0x2>)
800041e: f04f 0201 mov.w r2, #1
8000422: 6808 ldr r0, [r1, #0]
8000424: 4310 orrs r0, r2
8000426: 6008 str r0, [r1, #0]
8000428: f04f 4190 mov.w r1, #1207959552 @ 0x48000000
800042c: 2203 movs r2, #3
800042e: 6808 ldr r0, [r1, #0]
8000430: 4390 bics r0, r2
8000432: 2201 movs r2, #1
8000434: 4310 orrs r0, r2
8000436: 6008 str r0, [r1, #0]
8000438: 490c ldr r1, [pc, #48] @ (800046c <.lp1+0x6>)
800043a: 2201 movs r2, #1
800043c: 6808 ldr r0, [r1, #0]
800043e: 4310 orrs r0, r2
8000440: 6008 str r0, [r1, #0]
8000442: b662 cpsie i
08000444 <main>:
8000444: 4909 ldr r1, [pc, #36] @ (800046c <.lp1+0x6>)
8000446: 4050 eors r0, r2
8000448: 6008 str r0, [r1, #0]
800044a: f000 f803 bl 8000454 <delay>
800044e: f7ff bff9 b.w 8000444 <main>
8000452: bf00 nop
08000454 <delay>:
8000454: 2600 movs r6, #0
8000456: 4f06 ldr r7, [pc, #24] @ (8000470 <.lp1+0xa>)
8000458: 3601 adds r6, #1
800045a: 42be cmp r6, r7
800045c: d1fc bne.n 8000458 <delay+0x4>
800045e: 4770 bx lr
08000460 <stop>:
8000460: bf00 nop
8000462: f7ff bffd b.w 8000460 <stop>
08000466 <.lp1>:
8000466: 0000 .short 0x0000
8000468: 4002104c .word 0x4002104c
800046c: 48000014 .word 0x48000014
8000470: 001e8480 .word 0x001e8480
Disassembly of section .exhand:
08001000 <_ISR_NMI>:
8001000: 4917 ldr r1, [pc, #92] @ (8001060 <.lp2+0x2>)
8001002: f04f 0201 mov.w r2, #1
8001006: 6808 ldr r0, [r1, #0]
8001008: 4310 orrs r0, r2
800100a: 6008 str r0, [r1, #0]
800100c: f04f 4190 mov.w r1, #1207959552 @ 0x48000000
8001010: 22ff movs r2, #255 @ 0xff
8001012: 6808 ldr r0, [r1, #0]
8001014: 4390 bics r0, r2
8001016: 2244 movs r2, #68 @ 0x44
8001018: 4310 orrs r0, r2
800101a: 6008 str r0, [r1, #0]
800101c: 4911 ldr r1, [pc, #68] @ (8001064 <.lp2+0x6>)
800101e: 220a movs r2, #10
8001020: 6808 ldr r0, [r1, #0]
8001022: 4390 bics r0, r2
8001024: 6008 str r0, [r1, #0]
8001026: e7eb b.n 8001000 <_ISR_NMI>
08001028 <_ISR_HARDF>:
8001028: 490d ldr r1, [pc, #52] @ (8001060 <.lp2+0x2>)
800102a: f04f 0201 mov.w r2, #1
800102e: 6808 ldr r0, [r1, #0]
8001030: 4310 orrs r0, r2
8001032: 6008 str r0, [r1, #0]
8001034: f04f 4190 mov.w r1, #1207959552 @ 0x48000000
8001038: 22ff movs r2, #255 @ 0xff
800103a: 6808 ldr r0, [r1, #0]
800103c: 4390 bics r0, r2
800103e: 2211 movs r2, #17
8001040: 4310 orrs r0, r2
8001042: 6008 str r0, [r1, #0]
8001044: 4907 ldr r1, [pc, #28] @ (8001064 <.lp2+0x6>)
8001046: 2205 movs r2, #5
8001048: 6808 ldr r0, [r1, #0]
800104a: 4390 bics r0, r2
800104c: 6008 str r0, [r1, #0]
800104e: e7eb b.n 8001028 <_ISR_HARDF>
08001050 <_ISR_S0>:
8001050: b500 push {lr}
8001052: bc02 pop {r1}
8001054: 4708 bx r1
8001056: bf00 nop
08001058 <_ISR_S1>:
8001058: b500 push {lr}
800105a: bc02 pop {r1}
800105c: 4708 bx r1
0800105e <.lp2>:
800105e: 0000 .short 0x0000
8001060: 4002104c .word 0x4002104c
8001064: 48000014 .word 0x48000014
+92
View File
@@ -0,0 +1,92 @@
Memory Configuration
Name Origin Length Attributes
IVECS 0x08000000 0x000001d8 r
PGM 0x08000400 0x00000c00 xr
EXHANDS 0x08001000 0x00000400 xr
RAM 0x20000000 0x00001800 rw
*default* 0x00000000 0xffffffff
Linker script and memory map
.vectortable 0x08000000 0x14
0x08000000 . = ALIGN (0x4)
*(.vectortable)
.vectortable 0x08000000 0x14 task2.o
0x08000014 . = ALIGN (0x4)
.text 0x08000400 0x74
*(.text)
.text 0x08000400 0x74 task2.o
0x08000400 init
0x08000444 main
0x08000454 delay
0x08000460 stop
.glue_7 0x08000474 0x0
.glue_7 0x08000474 0x0 linker stubs
.glue_7t 0x08000474 0x0
.glue_7t 0x08000474 0x0 linker stubs
.vfp11_veneer 0x08000474 0x0
.vfp11_veneer 0x08000474 0x0 linker stubs
.v4_bx 0x08000474 0x0
.v4_bx 0x08000474 0x0 linker stubs
.iplt 0x08000474 0x0
.iplt 0x08000474 0x0 task2.o
.exhand 0x08001000 0x68
*(.exhand)
.exhand 0x08001000 0x68 task2.o
LOAD task2.o
OUTPUT(task2.elf elf32-littlearm)
LOAD linker stubs
.rel.dyn 0x08001068 0x0
.rel.iplt 0x08001068 0x0 task2.o
.data 0x08001068 0x0
.data 0x08001068 0x0 task2.o
.igot.plt 0x08001068 0x0
.igot.plt 0x08001068 0x0 task2.o
.bss 0x08001068 0x0
.bss 0x08001068 0x0 task2.o
.ARM.attributes
0x00000000 0x21
.ARM.attributes
0x00000000 0x21 task2.o
.debug_line 0x00000000 0xc1
.debug_line 0x00000000 0xc1 task2.o
.debug_info 0x00000000 0x22
.debug_info 0x00000000 0x22 task2.o
.debug_abbrev 0x00000000 0x12
.debug_abbrev 0x00000000 0x12 task2.o
.debug_aranges 0x00000000 0x28
.debug_aranges
0x00000000 0x28 task2.o
.debug_str 0x00000000 0x68
.debug_str 0x00000000 0x68 task2.o
.debug_ranges 0x00000000 0x20
.debug_ranges 0x00000000 0x20 task2.o
Cross Reference Table
Symbol File
delay task2.o
init task2.o
main task2.o
stop task2.o
BIN
View File
Binary file not shown.
+184 -170
View File
@@ -1,45 +1,32 @@
#****************************************************************************************#
# Project: task2 - ASM: Interrupts
# File: task2.s
#
# Language: ASM
#
# Hardware: STefi Light v1.1
# Processor: STM32G431KBT6U
#
# Author: Manuel Lederhofer
# Datum: 31.10.2014
#
# Version: 6.0
# 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
# 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
# 10.02.2025 TK remove ASM:Polling,move ASM:Interrupts to task2
# 24.06.2025 TK remove /* ... place your code here ... */
#
# 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.
#****************************************************************************************#
.include "G431_addr.s"
// Zusätzliche und benötigte Adressen
.equ RCC_AHB2ENR, 0x4002104C
.equ RCC_APB2ENR, 0x40021060
.equ GPIOA_MODER, 0x48000000
.equ GPIOA_ODR, 0x48000014
.equ GPIOC_MODER, 0x48000800
.equ GPIOC_PUPDR, 0x4800080C
.equ GPIOC_IDR, 0x48000810
.equ SYSCFG_BASE, 0x40010000
.equ SYSCFG_EXTICR4, (SYSCFG_BASE + 0x14)
.equ EXTI_BASE, 0x40010400
.equ EXTI_IMR1, (EXTI_BASE + 0x00)
.equ EXTI_FTSR1, (EXTI_BASE + 0x0C)
.equ EXTI_PR1, (EXTI_BASE + 0x14)
.equ NVIC_ISER1, 0xE000E104
#----------------------------------------------------------------------------------------#
.section .vectortable,"a" // vector table at begin of ROM
@@ -47,20 +34,13 @@
.align 2
.word 0x20004000 // initial Stack Pointer: 0x20000000 (RAM base) + 0x4000 (16K SRAM1 length)
.word 0x20004000 // initial Stack Pointer
.word 0x08000401 // initial Program Counter
.word _ISR_NMI // non-masking interrupt
.word _ISR_HARDF // hard fault interrupt
/* N.B.
Look at the .space or the .org assembler directive to insert the address of the
ISRs at the right place in the vector table. Verify your settings by the help of
the list file. */
.word _ISR_S0
.space 0xD0 // padding 208 Bytes bis Offset 0xE0 (EXTI15_10 IRQ 40)
.word _ISR_S0_S1 // gemeinsamer Interrupt für PC13 (S0) und PC14 (S1)
#----------------------------------------------------------------------------------------#
.text // section .text (default section for program code)
@@ -90,57 +70,85 @@ init:
MOV r12, r0
#--- enable port clocking
LDR r1, =RCC_AHB2ENR // load address of RCC_AHB2ENR
MOV r2, #0x01 // load mask for adjusting port clock gating (A: LEDs)
LDR r0, [r1, #0] // get current value of RCC_AHB2ENR
ORRS r0, r0, r2 // configure clock gating for ports
STR r0, [r1, #0] // apply settings
LDR r1, =RCC_AHB2ENR
MOVS r2, #0x05 // Bit 0 (GPIOA) und Bit 2 (GPIOC)
LDR r0, [r1, #0]
ORRS r0, r2
STR r0, [r1, #0]
#--- port init
#- LEDs
LDR r1, =GPIOA_MODER // load port A mode register address
MOVS r2, #0x03 // prepare mask
LDR r0, [r1, #0] // get current value of port A mode register
BICS r0, r2 // delete bits
MOVS r2, #0x01 // load configuration mask
ORRS r0, r0, r2 // apply mask
STR r0, [r1, #0] // apply result to port A mode register
#- LEDs (PA0-PA3)
LDR r1, =GPIOA_MODER
LDR r2, =0x000000FF // Maske PA0-PA3
LDR r0, [r1, #0]
BICS r0, r2
LDR r2, =0x00000055 // Maske Output 0101 0101
ORRS r0, r2
STR r0, [r1, #0]
#- switch LED off
LDR r1, =GPIOA_ODR // load port A output data register
MOVS r2, #0x01 // load mask for LED
LDR r0, [r1, #0] // get current value of GPIOA
ORRS r0, r0, r2 // configure pin state
STR r0, [r1, #0] // apply settings
LDR r1, =GPIOA_ODR
MOVS r2, #0x0F // Maske LED0-3
LDR r0, [r1, #0]
ORRS r0, r2
STR r0, [r1, #0]
#- buttons
/* ... place your code here ... */
#- buttons (PC13, PC14 als Input)
LDR r1, =GPIOC_MODER
LDR r2, =0x3C000000 // Maske Bits 26-29
LDR r0, [r1, #0]
BICS r0, r2
STR r0, [r1, #0]
#- Pull-Up für PC13, PC14
LDR r1, =GPIOC_PUPDR
LDR r2, =0x3C000000
LDR r0, [r1, #0]
BICS r0, r2
LDR r2, =0x14000000 // 01 = Pull-Up für PC13 (Bits 27:26) und PC14 (Bits 29:28)
ORRS r0, r2
STR r0, [r1, #0]
#--- button interrupt config
#- enable clock for SYSCFG module
LDR r1, =RCC_APB2ENR
MOVS r2, #0x01
LDR r0, [r1, #0]
ORRS r0, r2
STR r0, [r1, #0]
#- connect GPIO pins of the buttons to EXTended Interrupt controller lines (EXTI)
# in SYSCFG module (SYSCFG_* registers)
LDR r1, =SYSCFG_EXTICR4
LDR r2, =0x00000FF0 // Maske für EXTI13 (Bits 7:4) und EXTI14 (Bits 11:8)
LDR r0, [r1, #0]
BICS r0, r2
LDR r2, =0x00000220 // Port C (0010) für EXTI13 und EXTI14
ORRS r0, r2
STR r0, [r1, #0]
#- configure lines in EXTI module (EXTI_* registers)
LDR r1, =EXTI_FTSR1 // Fallende Flanke
LDR r2, =0x00006000 // Bits 13 und 14
LDR r0, [r1, #0]
ORRS r0, r2
STR r0, [r1, #0]
LDR r1, =EXTI_IMR1 // Maskierung aufheben
LDR r2, =0x00006000
LDR r0, [r1, #0]
ORRS r0, r2
STR r0, [r1, #0]
#- NVIC: set interrupt priority, clear pending bits
# and enable interrupts for buttons (see: PM, ch. 4.3, NVIC)
LDR r1, =NVIC_ISER1
LDR r2, =0x00000100 // Bit 8 für IRQ 40 (EXTI15_10)
LDR r0, [r1, #0]
ORRS r0, r2
STR r0, [r1, #0]
CPSIE i // enable interrupts globally
#----------------------------------------------------------------------------------------#
.align 2
@@ -150,16 +158,9 @@ init:
.global main
.type main, %function
main:
LDR r1, =GPIOA_ODR
EORS r0, r0, r2
STR r0, [r1, #0]
BL delay
WFI
B main
#----------------------------------------------------------------------------------------#
.align 2
@@ -169,30 +170,25 @@ main:
.global delay
.type delay, %function
delay:
MOVS r6, #0 // ...
LDR r7, =2000000 // ...
LDR r0, =106000 // Entprell-Zeit ~20ms
.L1:
ADDS r6, r6, #1 // ...
CMP r6, r7 // ...
BNE .L1 // ...
BX lr // ...
SUBS r0, r0, #1
BNE .L1
BX lr
#----------------------------------------------------------------------------------------#
.align 2
.global stop
stop:
NOP // do nothing (NOP is here to avoid a debugger crash, only)
B stop // if this line is reached, something went wrong
NOP
B stop
#----------------------------------------------------------------------------------------#
.lp1: // this label is only to nicify the line up in the .lst file
.lp1:
.ltorg
#----------------------------------------------------------------------------------------#
#----------------------------------------------------------------------------------------#
.section .exhand,"ax" // section for exception handlers
#----------------------------------------------------------------------------------------#
@@ -202,32 +198,28 @@ stop:
.thumb
.type _ISR_NMI, %function
_ISR_NMI:
#--- enable clock
LDR r1, =RCC_AHB2ENR // load address of RCC_AHB2ENR
MOV r2, #0x01 // load mask
LDR r0, [r1, #0] // get current value of RCC_AHB2ENR
ORRS r0, r0, r2 // configure clock gating for port
STR r0, [r1, #0] // apply settings
#--- init pins
LDR r1, =GPIOA_MODER // load port A mode register address
MOVS r2, #0xFF // prepare mask
LDR r0, [r1, #0] // get current value of port A mode register
BICS r0, r0, r2 // delete bits
MOVS r2, #0x44 // load configuration mask
ORRS r0, r0, r2 // configure pins
STR r0, [r1, #0] // apply settings to port A mode register
#--- switch some LEDs on
LDR r1, =GPIOA_ODR // load port A data output register address
MOVS r2, #0x0A // load mask for blue and yellow LED
LDR r1, =RCC_AHB2ENR
MOV r2, #0x01
LDR r0, [r1, #0]
BICS r0, r0, r2
STR r0, [r1, #0] // switch LEDs on
ORRS r0, r2
STR r0, [r1, #0]
LDR r1, =GPIOA_MODER
MOVS r2, #0xFF
LDR r0, [r1, #0]
BICS r0, r2
MOVS r2, #0x44
ORRS r0, r2
STR r0, [r1, #0]
LDR r1, =GPIOA_ODR
MOVS r2, #0x0A
LDR r0, [r1, #0]
BICS r0, r2
STR r0, [r1, #0]
B _ISR_NMI
#----------------------------------------------------------------------------------------#
.align 2
@@ -235,77 +227,99 @@ _ISR_NMI:
.thumb
.type _ISR_HARDF, %function
_ISR_HARDF:
#--- enable clock
LDR r1, =RCC_AHB2ENR // load address of RCC_AHB2ENR
MOV r2, #0x01 // load mask
LDR r0, [r1, #0] // get current value of RCC_AHB2ENR
ORRS r0, r0, r2 // configure clock gating for port
STR r0, [r1, #0] // apply settings
#--- init pins
LDR r1, =GPIOA_MODER // load port A mode register address
MOVS r2, #0xFF // prepare mask
LDR r0, [r1, #0] // get current value of port A mode register
BICS r0, r0, r2 // delete bits
MOVS r2, #0x11 // load configuration mask
ORRS r0, r0, r2 // configure pins
STR r0, [r1, #0] // apply settings to port A mode register
#--- switch some LEDs on
LDR r1, =GPIOA_ODR // load port A data output register address
MOVS r2, #0x05 // load mask for red and green LED
LDR r1, =RCC_AHB2ENR
MOV r2, #0x01
LDR r0, [r1, #0]
BICS r0, r0, r2
STR r0, [r1, #0] // switch LEDs on
ORRS r0, r2
STR r0, [r1, #0]
LDR r1, =GPIOA_MODER
MOVS r2, #0xFF
LDR r0, [r1, #0]
BICS r0, r2
MOVS r2, #0x11
ORRS r0, r2
STR r0, [r1, #0]
LDR r1, =GPIOA_ODR
MOVS r2, #0x05
LDR r0, [r1, #0]
BICS r0, r2
STR r0, [r1, #0]
B _ISR_HARDF
#----------------------------------------------------------------------------------------#
.align 2
.syntax unified
.thumb
.type _ISR_S0, %function
_ISR_S0:
PUSH {lr} // save special content
.type _ISR_S0_S1, %function
_ISR_S0_S1:
PUSH {r4, r5, lr} // Wichtig: Register sichern gemäß AAPCS
#--- do the work
_check_S0:
LDR r4, =EXTI_PR1
LDR r5, [r4, #0]
LDR r2, =0x2000 // Maske für S0 (PC13 / Bit 13)
TST r5, r2
BEQ _check_S1 // Wenn Bit 13 nicht gesetzt, überspringen
#--- do the work S0
BL delay // Entprellen
#--- clear interrupt flag
LDR r0, =GPIOC_IDR
LDR r1, [r0, #0]
LDR r2, =0x2000
TST r1, r2
BNE _clear_S0 // Abbruch, wenn High (Taster prellt / schon losgelassen)
LDR r0, =GPIOA_ODR
LDR r1, [r0, #0]
MOVS r2, #0x09 // LED0 & LED3 toggeln (1001)
EORS r1, r2
STR r1, [r0, #0]
_clear_S0:
#--- clear interrupt flag S0
LDR r4, =EXTI_PR1
LDR r5, =0x2000
STR r5, [r4, #0]
_check_S1:
LDR r4, =EXTI_PR1
LDR r5, [r4, #0]
LDR r2, =0x4000 // Maske für S1 (PC14 / Bit 14)
TST r5, r2
BEQ _leave_ISR // Wenn Bit 14 nicht gesetzt, Ende
#--- do the work S1
BL delay
LDR r0, =GPIOC_IDR
LDR r1, [r0, #0]
LDR r2, =0x4000
TST r1, r2
BNE _clear_S1 // Abbruch, wenn High
LDR r0, =GPIOA_ODR
LDR r1, [r0, #0]
MOVS r2, #0x06 // LED1 & LED2 toggeln (0110)
EORS r1, r2
STR r1, [r0, #0]
_clear_S1:
#--- clear interrupt flag S1
LDR r4, =EXTI_PR1
LDR r5, =0x4000
STR r5, [r4, #0]
_leave_ISR:
#--- leave ISR
POP {r1} // get special content back
BX r1 // go back to where we came from
POP {r4, r5, pc} // Register wiederherstellen und zurückkehren
#----------------------------------------------------------------------------------------#
.align 2
.syntax unified
.thumb
.type _ISR_S1, %function
_ISR_S1:
PUSH {lr} // save special content
#--- do the work
#--- clear interrupt flag
#--- leave ISR
POP {r1} // get special content back
BX r1 // go back to where we came from
#----------------------------------------------------------------------------------------#
.lp2: // this label is only to nicify the line up in the .lst file
.lp2:
.ltorg
#----------------------------------------------------------------------------------------#
+325
View File
@@ -0,0 +1,325 @@
#****************************************************************************************#
# Project: task2 - ASM: Interrupts
# File: task2.s
#
# Language: ASM
#
# Hardware: STefi Light v1.1
# Processor: STM32G431KBT6U
#
# Author: Manuel Lederhofer
# Datum: 31.10.2014
#
# Version: 6.0
# 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
# 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
# 10.02.2025 TK remove ASM:Polling,move ASM:Interrupts to task2
# 24.06.2025 TK remove /* ... place your code here ... */
#
# 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.
#****************************************************************************************#
.include "G431_addr.s"
#----------------------------------------------------------------------------------------#
.section .vectortable,"a" // vector table at begin of ROM
#----------------------------------------------------------------------------------------#
.align 2
.word 0x20004000 // initial Stack Pointer: 0x20000000 (RAM base) + 0x4000 (16K SRAM1 length)
.word 0x08000401 // initial Program Counter
.word _ISR_NMI // non-masking interrupt
.word _ISR_HARDF // hard fault interrupt
/* N.B.
Look at the .space or the .org assembler directive to insert the address of the
ISRs at the right place in the vector table. Verify your settings by the help of
the list file. */
.word _ISR_S0
#----------------------------------------------------------------------------------------#
.text // section .text (default section for program code)
#----------------------------------------------------------------------------------------#
.align 2
.syntax unified
.thumb
.thumb_func
.global init
.type init, %function
init:
CPSID i // disable interrupts globally
MOVS r0, #0 // safely initialize the GPRs
MOVS r1, #0
MOVS r2, #0
MOVS r3, #0
MOVS r4, #0
MOVS r5, #0
MOVS r6, #0
MOVS r7, #0
MOV r8, r0
MOV r9, r0
MOV r10, r0
MOV r11, r0
MOV r12, r0
#--- enable port clocking
LDR r1, =RCC_AHB2ENR // load address of RCC_AHB2ENR
MOV r2, #0x01 // load mask for adjusting port clock gating (A: LEDs)
LDR r0, [r1, #0] // get current value of RCC_AHB2ENR
ORRS r0, r0, r2 // configure clock gating for ports
STR r0, [r1, #0] // apply settings
#--- port init
#- LEDs
LDR r1, =GPIOA_MODER // load port A mode register address
MOVS r2, #0x03 // prepare mask
LDR r0, [r1, #0] // get current value of port A mode register
BICS r0, r2 // delete bits
MOVS r2, #0x01 // load configuration mask
ORRS r0, r0, r2 // apply mask
STR r0, [r1, #0] // apply result to port A mode register
# LDR r1, =GPIOB_MODER
# MOVS r3, #0x03
# LDR r0, [r1, #1]
# BICS r0, r3
# MOVS r3, #0x01
# ORRS r0, r0, r3
# STR r0, [r1, #1]
#- switch LED off
LDR r1, =GPIOA_ODR // load port A output data register
MOVS r2, #0x01 // load mask for LED
LDR r0, [r1, #0] // get current value of GPIOA
ORRS r0, r0, r2 // configure pin state
STR r0, [r1, #0] // apply settings
#- buttons
/* ... place your code here ... */
#--- button interrupt config
#- enable clock for SYSCFG module
#- connect GPIO pins of the buttons to EXTended Interrupt controller lines (EXTI)
# in SYSCFG module (SYSCFG_* registers)
#- configure lines in EXTI module (EXTI_* registers)
#- NVIC: set interrupt priority, clear pending bits
# and enable interrupts for buttons (see: PM, ch. 4.3, NVIC)
CPSIE i // enable interrupts globally
#----------------------------------------------------------------------------------------#
.align 2
.syntax unified
.thumb
.thumb_func
.global main
.type main, %function
main:
LDR r1, =GPIOA_ODR
EORS r0, r0, r2
STR r0, [r1, #0]
BL delay
B main
#----------------------------------------------------------------------------------------#
.align 2
.syntax unified
.thumb
.thumb_func
.global delay
.type delay, %function
delay:
MOVS r6, #0 // ...
LDR r7, =2000000 // ...
.L1:
ADDS r6, r6, #1 // ...
CMP r6, r7 // ...
BNE .L1 // ...
BX lr // ...
#----------------------------------------------------------------------------------------#
.align 2
.global stop
stop:
NOP // do nothing (NOP is here to avoid a debugger crash, only)
B stop // if this line is reached, something went wrong
#----------------------------------------------------------------------------------------#
.lp1: // this label is only to nicify the line up in the .lst file
.ltorg
#----------------------------------------------------------------------------------------#
#----------------------------------------------------------------------------------------#
.section .exhand,"ax" // section for exception handlers
#----------------------------------------------------------------------------------------#
.align 2
.syntax unified
.thumb
.type _ISR_NMI, %function
_ISR_NMI:
#--- enable clock
LDR r1, =RCC_AHB2ENR // load address of RCC_AHB2ENR
MOV r2, #0x01 // load mask
LDR r0, [r1, #0] // get current value of RCC_AHB2ENR
ORRS r0, r0, r2 // configure clock gating for port
STR r0, [r1, #0] // apply settings
#--- init pins
LDR r1, =GPIOA_MODER // load port A mode register address
MOVS r2, #0xFF // prepare mask
LDR r0, [r1, #0] // get current value of port A mode register
BICS r0, r0, r2 // delete bits
MOVS r2, #0x44 // load configuration mask
ORRS r0, r0, r2 // configure pins
STR r0, [r1, #0] // apply settings to port A mode register
#--- switch some LEDs on
LDR r1, =GPIOA_ODR // load port A data output register address
MOVS r2, #0x0A // load mask for blue and yellow LED
LDR r0, [r1, #0]
BICS r0, r0, r2
STR r0, [r1, #0] // switch LEDs on
B _ISR_NMI
#----------------------------------------------------------------------------------------#
.align 2
.syntax unified
.thumb
.type _ISR_HARDF, %function
_ISR_HARDF:
#--- enable clock
LDR r1, =RCC_AHB2ENR // load address of RCC_AHB2ENR
MOV r2, #0x01 // load mask
LDR r0, [r1, #0] // get current value of RCC_AHB2ENR
ORRS r0, r0, r2 // configure clock gating for port
STR r0, [r1, #0] // apply settings
#--- init pins
LDR r1, =GPIOA_MODER // load port A mode register address
MOVS r2, #0xFF // prepare mask
LDR r0, [r1, #0] // get current value of port A mode register
BICS r0, r0, r2 // delete bits
MOVS r2, #0x11 // load configuration mask
ORRS r0, r0, r2 // configure pins
STR r0, [r1, #0] // apply settings to port A mode register
#--- switch some LEDs on
LDR r1, =GPIOA_ODR // load port A data output register address
MOVS r2, #0x05 // load mask for red and green LED
LDR r0, [r1, #0]
BICS r0, r0, r2
STR r0, [r1, #0] // switch LEDs on
B _ISR_HARDF
#----------------------------------------------------------------------------------------#
.align 2
.syntax unified
.thumb
.type _ISR_S0, %function
_ISR_S0:
PUSH {lr} // save special content
#--- do the work
#--- clear interrupt flag
#--- leave ISR
POP {r1} // get special content back
BX r1 // go back to where we came from
#----------------------------------------------------------------------------------------#
.align 2
.syntax unified
.thumb
.type _ISR_S1, %function
_ISR_S1:
PUSH {lr} // save special content
#--- do the work
#--- clear interrupt flag
#--- leave ISR
POP {r1} // get special content back
BX r1 // go back to where we came from
#----------------------------------------------------------------------------------------#
.lp2: // this label is only to nicify the line up in the .lst file
.ltorg
#----------------------------------------------------------------------------------------#
.end
#************************************** E O F *******************************************#