AnsweredAssumed Answered

can't write to peripheral register

Question asked by robison.don on Aug 6, 2013
Latest reply on Aug 7, 2013 by Clive One
I have begun programming the stm32f4.  I made a really simple program first.  It added one to r0 and stored the result in r0.  Then I used STM32 ST-LINK utility to confirm that r0 is increasing.  It was.  I though I was on my way ... until now

I made a program that still increments the registers, but I also setup timer8 for output compare to make a simple timer.  The output pin I used does not change state.  I used STM32 ST-LINK utility to look at the memory contentes around the boundary address of timer 8 and found all the memory in that area is zeros.  I tried to use the utility to change one of the timer 8 registers manually, and it told me "error occurred during memory writing."  The flash area of the memory displays correctly.

Am I just unable to interact with the peripheral memory with STM32 ST-LINK utility?

am I writing to the peripheral registers improperly?

perhaps the registers for timer 8 are written to but I set them up wrong to strobe an output pin?

my small code follows.

@@@ Directives
        .thumb                  @ (same as saying '.code 16')
        .syntax unified

@@@ Equates
        .equ STACKINIT,                   0x20005000
        .equ GPIOC_MODER,                  0x40020800
        .equ GPIOC_AFRL,                   0x40020820    
        .equ TIM8_ARR,                   0x4001042C
        .equ TIM8_CCER,                    0x40010420        
        .equ TIM8_CCMR2,                0x4001041C                
        .equ TIM8_CR1,                    0x40010400                
        
.section .text
        .org 0

@@@ Vectors
vectors:        
        .word STACKINIT         @ stack pointer value when stack is empty
        .word _start + 1        @ reset vector (manually adjust to odd for thumb)
        .word _nmi_handler + 1  @
        .word _hard_fault  + 1  @
        .word _memory_fault + 1 @
        .word _bus_fault + 1    @
        .word _usage_fault + 1  @

_start:
   
        ldr r0, = GPIOC_MODER    @ this sets the pin to alternate function
        ldr r1, = 0x00020000    @ this sets the pin to alternate function
        str r1, [r0]            @ this sets the pin to alternate function

        ldr r0, = GPIOC_AFRL    @ this sets the pin to alternate function
        ldr r1, = 0x00030000    @ this sets the pin to alternate function
        str r1, [r0]            @ this sets the pin to alternate function
        
        ldr r0, = TIM8_ARR        @ this sets maximum count in the timer
        ldr r1, = 0x02625A00    @ this sets maximum count in the timer
        str r1, [r0]            @ this sets maximum count in the timer
        
        ldr r0, = TIM8_CCER        @ this sets maximum count in the timer
        ldr r1, = 0x0100        @ this sets maximum count in the timer
        str r1, [r0]            @ this sets maximum count in the timer        

        ldr r0, = TIM8_CCMR2    @ this sets maximum count in the timer
        ldr r1, = 0x0100        @ this sets maximum count in the timer
        str r1, [r0]            @ this sets maximum count in the timer    

        ldr r0, = TIM8_CR1        @ this sets maximum count in the timer
        ldr r1, = 0x0001        @ this sets maximum count in the timer
        str r1, [r0]            @ this sets maximum count in the timer            
        
loop:

        add r0, 1
        add r1, 2
        add    r2, 3
        add r3, 4
        add    r4, 5

        b loop                 @ continue forever

_dummy:                        @ if any int gets triggered, just hang in a loop
_nmi_handler:
_hard_fault:
_memory_fault:
_bus_fault:
_usage_fault:
        add r0, 1
        add r1, 1
        b _dummy   

Outcomes