// STM32H7 Solution
// Only newly added/modified parts of the code are below.

    // Vector table offset register definition
    // Importan for relocated Vector table when running from RAM
.equ    VTOR,0xE000ED08

// Start of data section

LEDSTAT: .word  0  // LED state
MSECCNT: .word  0  //MSecs counter for SysTick_Handler
MSECMAX: .word  500 //MSecs interval for SysTick_Handler

        bl INIT_IO
//        bl INIT_TC

// Relocate vector address - only if you run code from RAM !
ldr r1, =VTOR
ldr r0, =0x24000000
str r0, [r1]

        bl INIT_TC_PSP


        b  loop

__end: b __end

  push {r0, r1, lr}
ldr r1, =SCS_BASE

str r0, [r1, #SCS_SYST_RVR]

mov r0, #0
str r0, [r1, #SCS_SYST_CVR]

mov r0, #0b111 // TickINT Bit also set to 1
str r0, [r1, #SCS_SYST_CSR]

  pop {r0, r1, pc}

* @brief  This is the code that gets called when SysTick timer triggers interrupt
* @param  None
* @retval None

.global SysTick_Handler
.section  .text.SysTick_Handler,"ax",%progbits
.type  SysTick_Handler, %function

    push {r3, r4, r5, r6, lr}

ldr r3,=MSECMAX  // Load MAX value
ldr r5,[r3]
ldr r3,=MSECCNT  // Load MSecs Counter value
ldr r4,[r3]
add r4,r4,#1 // Increment (+1)
str r4,[r3]
cmp r4,r5        // End of interval ?
blo RET

// Reset counter state and check LED
mov r4,#0
str r4,[r3]

ldr r3,=LEDSTAT
    ldr r4,[r3]
    cmp r4,#0

beq LON

mov r5, #LEDs_OFF
mov r4,#0
    str r4,[r3]
//    mov r7,#0 // set LED status in r7


LON:  mov r5, #LEDs_ON
      mov r4,#0xff
      str r4,[r3]
//      mov r7,#0xff // set LED status in r7

// Set GPIOI Pins through BSRR register
ldr    r6, =GPIOI_BASE      // Load GPIOD BASE address to r6
str    r5, [r6,#GPIOx_BSRR] // Write to BSRR register

RET: pop {r3, r4, r5, r6, pc}

.size  SysTick_Handler, .-SysTick_Handler

마지막 수정됨: 목요일, 14 12월 2023, 1:07 PM