EmbDev.net

Forum: ARM programming with GCC/GNU tools problem with startup


von michael (Guest)


Rate this post
useful
not useful
Dear all
I am a beginner with ARM. I use mini2440 board with s3c2440 
microcontroller. My problem is that I can't find fitting startup for 
this ARM, which configure all devices.
I would like use timer with interrupt but it doesn't work.
I found somewhere this startup:
1
.global vectors
2
vectors:
3
    b   start
4
    b   undef_instr_handler
5
    b   software_int_handler
6
    b   prefetch_abort_handler
7
    b   data_abort_handler
8
    b   reserved_handler
9
    b   irq_handler
10
    b   fiq_handler
11
12
13
start:
14
    /* enter supervisor mode, disable IRQ */
15
        msr     cpsr, #0xd3
16
17
             /* Disable the watchdog */
18
        ldr     r2, =0x00000000
19
        mov     r1, #0x53000000
20
       str     r2, [r1]
21
22
    /* Mask all Interupts to be safe */
23
        ldr     r2, =0xFFFFFFFF
24
        mov     r1, #0x4A000000
25
        str     r2, [r1, #0x08]
26
27
       /* Set up stack for IRQ mode */
28
        msr     cpsr_c, #0xd2
29
        ldr     sp, =irq_stack
30
        
31
                /* Set up stack for FIQ mode */
32
       msr     cpsr_c, #0xd1
33
        ldr     sp, =fiq_stack
34
35
        /* Let abort and undefined modes use IRQ stack */
36
        msr     cpsr_c, #0xd7
37
        ldr     sp, =irq_stack
38
        msr     cpsr_c, #0xdb
39
        ldr     sp, =irq_stack
40
41
                /* Switch to supervisor mode */
42
                msr     cpsr_c, #0xd3
43
                ldr     sp, =stackend
44
45
    /* Start the main function */
46
    adr     lr, vectors
47
    ldr     pc, =main
48
49
50
undef_instr_handler:
51
    mov    r0, lr
52
    mov    r1, #0
53
    b      UIE
54
55
software_int_handler:
56
reserved_handler:
57
    movs   pc, lr
58
59
prefetch_abort_handler:
60
    sub    r0, lr, #4
61
    mov    r1, #1
62
    b      UIE
63
64
data_abort_handler:
65
    sub    r0, lr, #8
66
    mov    r1, #2
67
    b      UIE
68
69
irq_handler:
70
    bl UIE
71
72
fiq_handler:
73
    b UIE
74
75
UIE:
76
    b UIE
77
78
irq_stack:
79
.word  0x0badc0de
80
81
fiq_stack:
82
.word 0x0badc0de
83
end:

My C code:
1
/******************************************************************************
2
 * timer.c
3
 * chip: s3c2440
4
 * compiler: arm-none-eabi-gcc 4.3.3
5
 *
6
 *  Created on: 2010-02-04
7
 *      Author: michal grzybek
8
 *
9
 *      This code shows how use timers to count time with interrupts.
10
 *      There is used timer no. 2
11
 *      to count one second. After this time is enable binary counter on LED's
12
 ******************************************************************************/
13
14
15
#include "2440addr.h"
16
#include "Def.h"
17
18
void init_timer (void);
19
void binary_leds (void);
20
21
22
void timer_handler (void) __attribute__ ((interrupt("IRQ")));
23
void timer_handler (void)
24
{
25
26
  ClearPending(BIT_TIMER2);
27
  binary_leds();
28
29
}
30
31
32
U16 i=0,tmp=0;  /* temporary needed to binary counter*/
33
34
int main (void)
35
{
36
37
  init_timer();
38
39
while (1);
40
41
42
43
return 0;
44
}
45
46
void init_timer (void)
47
{
48
  pISR_TIMER2  = (unsigned)timer_handler;  /* address of interrupt service routine*/
49
  pISR_IRQ = (unsigned)timer_handler;
50
  ClearPending(BIT_TIMER2);  /* interrupt timer2 requested*/
51
  EnableIrq(BIT_TIMER2);  /* */
52
53
54
  rGPBCON &= 0xffffcc;  /* mask GPBCON and clear 5th and 4th bits and buzzer off*/
55
  rGPBCON |= 0x000020;  /* set 5th and  4th bits at 2 binary value,
56
              //it's mean that GPB2 is configured as TOUT2*/
57
58
  rGPBCON&=0xfc03ff; /*Port GPB is configured for leds (GPB5,GPB6,GPB7,GPB8-output)*/
59
  rGPBCON|=0x0015400;
60
61
  rGPBDAT|=0x1e0;    /*LEDs are cleared*/
62
63
  rTCFG0 |= 0x0ff00;    /* prescaler configured as 255 value*/
64
  rTCFG1 |= 0x00300;    /* divider configured as 16 value */
65
66
67
  /******************* timer on ***************************/
68
  rTCMPB2 = 0;    /* set comparator at 0*/
69
  rTCNTB2 = 65000;    /* set counter to count 1 sec */
70
  rTCON = 0x00a000;  /* Auto-reload is on, manual update bit is set*/
71
  rTCON = 0x009000;  /* manual update bit is cleared, start bit is set */
72
73
}
74
75
76
void binary_leds (void)
77
{
78
79
80
  tmp++;
81
      i=tmp;
82
      i = (~i)<<5;
83
84
      rGPBDAT|=0x1e0;
85
      rGPBDAT &= i;
86
}

von Clifford S. (clifford)


Rate this post
useful
not useful
Your start-up looks rather too minimal for an ARM9; you have no set-up 
for PLL, MMU, Cache, or SDRAM controller; or do you have a bootloader 
that is doing all that for you?

The http://www.friendlyarm.net/downloads page has a uCOS-II port 
download that includes start-up code that is probably closer to your 
requirements, even if you do not actually need the uCOS-II stuff.

von michael (Guest)


Rate this post
useful
not useful
Ok, I downloaded uCOS-II but there is startup for ADS. I use gcc and 
this file doesn't fit.
Any idea?

von Andreas (Guest)


Rate this post
useful
not useful
port the files to GCC or have a look at the RT-Thread project:
http://code.google.com/p/rt-thread/

von Clifford S. (clifford)


Rate this post
useful
not useful
This was discussed a while ago here: http://embdev.net/topic/146188

The Micrium site has generic ARM ports for GCC; they just don't make it 
too obvious where!  The thread I mentioned tells you how.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.