EmbDev.net

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


von michael (Guest)


Rate this post
0 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
start:
12
    /* enter supervisor mode, disable IRQ */
13
        msr     cpsr, #0xd3
14
15
             /* Disable the watchdog */
16
        ldr     r2, =0x00000000
17
        mov     r1, #0x53000000
18
       str     r2, [r1]
19
20
    /* Mask all Interupts to be safe */
21
        ldr     r2, =0xFFFFFFFF
22
        mov     r1, #0x4A000000
23
        str     r2, [r1, #0x08]
24
25
       /* Set up stack for IRQ mode */
26
        msr     cpsr_c, #0xd2
27
        ldr     sp, =irq_stack
28
        
29
                /* Set up stack for FIQ mode */
30
       msr     cpsr_c, #0xd1
31
        ldr     sp, =fiq_stack
32
33
        /* Let abort and undefined modes use IRQ stack */
34
        msr     cpsr_c, #0xd7
35
        ldr     sp, =irq_stack
36
        msr     cpsr_c, #0xdb
37
        ldr     sp, =irq_stack
38
39
                /* Switch to supervisor mode */
40
                msr     cpsr_c, #0xd3
41
                ldr     sp, =stackend
42
43
    /* Start the main function */
44
    adr     lr, vectors
45
    ldr     pc, =main
46
47
48
undef_instr_handler:
49
    mov    r0, lr
50
    mov    r1, #0
51
    b      UIE
52
53
software_int_handler:
54
reserved_handler:
55
    movs   pc, lr
56
57
prefetch_abort_handler:
58
    sub    r0, lr, #4
59
    mov    r1, #1
60
    b      UIE
61
62
data_abort_handler:
63
    sub    r0, lr, #8
64
    mov    r1, #2
65
    b      UIE
66
67
irq_handler:
68
    bl UIE
69
70
fiq_handler:
71
    b UIE
72
73
UIE:
74
    b UIE
75
76
irq_stack:
77
.word  0x0badc0de
78
79
fiq_stack:
80
.word 0x0badc0de
81
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
#include "2440addr.h"
14
#include "Def.h"
15
16
void init_timer (void);
17
void binary_leds (void);
18
19
20
void timer_handler (void) __attribute__ ((interrupt("IRQ")));
21
void timer_handler (void)
22
{
23
24
  ClearPending(BIT_TIMER2);
25
  binary_leds();
26
27
}
28
29
30
U16 i=0,tmp=0;  /* temporary needed to binary counter*/
31
32
int main (void)
33
{
34
35
  init_timer();
36
37
while (1);
38
39
40
41
return 0;
42
}
43
44
void init_timer (void)
45
{
46
  pISR_TIMER2  = (unsigned)timer_handler;  /* address of interrupt service routine*/
47
  pISR_IRQ = (unsigned)timer_handler;
48
  ClearPending(BIT_TIMER2);  /* interrupt timer2 requested*/
49
  EnableIrq(BIT_TIMER2);  /* */
50
51
52
  rGPBCON &= 0xffffcc;  /* mask GPBCON and clear 5th and 4th bits and buzzer off*/
53
  rGPBCON |= 0x000020;  /* set 5th and  4th bits at 2 binary value,
54
              //it's mean that GPB2 is configured as TOUT2*/
55
56
  rGPBCON&=0xfc03ff; /*Port GPB is configured for leds (GPB5,GPB6,GPB7,GPB8-output)*/
57
  rGPBCON|=0x0015400;
58
59
  rGPBDAT|=0x1e0;    /*LEDs are cleared*/
60
61
  rTCFG0 |= 0x0ff00;    /* prescaler configured as 255 value*/
62
  rTCFG1 |= 0x00300;    /* divider configured as 16 value */
63
64
65
  /******************* timer on ***************************/
66
  rTCMPB2 = 0;    /* set comparator at 0*/
67
  rTCNTB2 = 65000;    /* set counter to count 1 sec */
68
  rTCON = 0x00a000;  /* Auto-reload is on, manual update bit is set*/
69
  rTCON = 0x009000;  /* manual update bit is cleared, start bit is set */
70
71
}
72
73
74
void binary_leds (void)
75
{
76
77
78
  tmp++;
79
      i=tmp;
80
      i = (~i)<<5;
81
82
      rGPBDAT|=0x1e0;
83
      rGPBDAT &= i;
84
}

von Clifford S. (clifford)


Rate this post
0 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
0 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
0 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
0 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.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.