I want to debug the startup-code and wrote the code attached at the end of the post to enable the GIO and toggle some LEDs.
The code is at the very beginning in the startup-routine (reset-interrupt).
The following strange thing happens:
- When I load the program and start the code for the "first" time (or when I switch on the device), the LEDs are not blinking
- When press "pause" in the debugger and do a "CPU reset" and press "continue" everything is fine
Strange thing is: The code is executed in the first case too... But no LEDs are blinking.
Is this a startup-problem of the microcontroller or does the "Reset CPU" button some actions which initialize the processor more than I do?
Here is the code:
sys_startup.c
=======================================
void _c_int00(void)
{
/* USER CODE BEGIN (5) */
/* USER CODE END */
/* Initialize Core Registers to avoid CCM Error */
_coreInitRegisters_();
/* USER CODE BEGIN (6) */
/* USER CODE END */
/* Initialize Stack Pointers */
_coreInitStackPointer_();
/* USER CODE BEGIN (7) */
_errorled_init();
for (;;)
{
_errorled_blink(1);
}
/* USER CODE END */
errorled_asm
=======================================
;-------------------------------------------------------------------------------
; errorled.asm
;
.text
.arm
;-------------------------------------------------------------------------------
; Setup GPIO pin for Errorled
.def _errorled_init
.asmfunc
_errorled_init
; release peripheral reset by setting PENA bit in Clock Control Register 0xFFFFFFd0
ldr R0, CLKCNTL
mov R12, #(1<<8) ; bit PENA
str R12, [R0]
; enable clock to GIO through PCR (0xFFFF E000)
; bring GIO controller out of reset
ldr R0, GIOGCR0
mov R12, #1
str R12, [R0]
; clear all interrupt enables of GIOA
ldr R0, GIOENACLR
mov R12, #255
str R12, [R0]
; irqs are set as lowlevel
ldr R0, GIOLVLCLR
mov R12, #255
str R12, [R0]
; set direction of all three LEDs to output
ldr R0, GIODIRA
mov R12, #((1 << LED_RED) + (1 << LED_GRN) + (1 << LED_YEL))
str R12, [R0]
; set all three LEDs to ON
ldr R0, GIODOUTA
mov R12, #((1 << LED_RED) + (1 << LED_GRN) + (1 << LED_YEL))
str R12, [R0]
; return
bx lr
CLKCNTL .word 0xFFFFFFD0
GIOGCR0 .word 0xFFF7BC00
GIOENACLR .word 0xFFF7BC14
GIOLVLCLR .word 0xFFF7BC1C
GIODIRA .word 0xFFF7BC34
GIODOUTA .word 0xFFF7BC3C
LED_GRN .equ 0
LED_YEL .equ 1
LED_RED .equ 4
.endasmfunc
;-------------------------------------------------------------------------------
; Blink all then twice yellow
.def _errorled_blink
.asmfunc
_errorled_blink
mov r1, lr
ldr R0, GIODOUTA
mov R12, #((1 << LED_YEL) + (1 << LED_GRN) + (1 << LED_RED))
str R12, [R0]
bl _errorled_wait
mov R10, #5
_errorled_blinkcount
mov R12, #0
str R12, [R0]
bl _errorled_wait
mov R12, #(1 << LED_YEL)
str R12, [R0]
bl _errorled_wait
sub R10,R10,#1
cmp R10,#0
bne _errorled_blinkcount
mov lr, r1
; return
bx lr
.endasmfunc
;-------------------------------------------------------------------------------
; Waitloop
.def _errorled_wait
.asmfunc
_errorled_wait
mov R11, #100
_errorled_waitloop
nop
nop
nop
nop
nop
nop
nop
sub R11,R11,#1
cmp R11,#0
bne _errorled_waitloop
; return
bx lr
.endasmfunc