cancel
Showing results for 
Search instead for 
Did you mean: 

can't write to peripheral register

drobison
Associate II
Posted on August 06, 2013 at 21:14

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   

#peripheral-timer-memory-error
4 REPLIES 4
Posted on August 06, 2013 at 22:34

You must enable the AHBx and APBx clocks for the peripherals you wish to use.

ie APB2ENR and SYSCFG

LDR R0, =0x40023844 ; RCC_APB2ENR
LDR R1, =0x00004000 ; ENABLE SYSCFG CLOCK
STR R1, [R0, #0]

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 06, 2013 at 23:06

ldr r0, =0x40023800 ; RCC
ldr r1, =4 ; RCC_AHB1ENR_GPIOCEN
ldr r2, [r0, #0x30] ; RCC_AHB1ENR
orr r2, r1
str r2, [r0, #0x30]
ldr r1, =2 ; RCC_APB2ENR_TIM8EN
ldr r2, [r0, #0x44] ; RCC_APB2ENR
orr r2, r1
str r2, [r0, #0x44]
; OR
ldr r0, =0x40023800 ; RCC
ldr r1, [r0, #0x30] ; RCC_AHB1ENR
orr r1, r1, #4 ; RCC_AHB1ENR_GPIOCEN
str r1, [r0, #0x30]
ldr r1, [r0, #0x44] ; RCC_APB2ENR
orr r1, r1, #2 ; RCC_APB2ENR_TIM8EN
str r1, [r0, #0x44]

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
drobison
Associate II
Posted on August 06, 2013 at 23:19

Thanks for the reply.  I'll try it; however;  I am further confused.  When I look at your assignment for the RCC register, I get the impression you are setting bit 13, which is reserved.  I would expect you want to set bit 1 which is timer 8.  I expect 0x0002.

Is my concept of byte order wrong?

Posted on August 07, 2013 at 00:14

We're talking about the F4, right?

0690X0000060500QAA.png
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..