// 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
.data
.align

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



main:
        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

loop:

        b  loop

__end: b __end


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

ldr r0, =SYSTICK_RELOAD_1MS
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


SysTick_Handler:
    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

b CONT

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

CONT:
// 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


Zadnja sprememba: četrtek, 14. december 2023, 13.07