How to develop arm bare-metal programs under Ubuntu

Source: Internet
Author: User
Tags volatile linux

In this article, we use the assembly jump to C code, to achieve light led, which note that the SP's settings, the other is relatively simple.

The Bootsect code is as follows:

@****************************************************************************** @ file:bootsect.s @ function: @**********        . equ Watchdogcon, 0x7e004000. equ       
            Ledcon, 0x7f008800. equ leddat, 0x7f008808. Text. Global _start _start:      BL setup_peri_port bl disable_watch_dog bl setup_sp bl display_led BL main main_loop:b main_loop Disable_wat Ch_dog: @ To watchdog register write 0 can ldr R0,=watchdogcon mov r1, #0x0 str r1,[  
                                    R0] mov pc,lr setup_sp:ldr sp, =1024*8 @ set Stack, note: cannot be greater than 8k, because the available memory is now only 8K The code in NAND Flash is moved to internal RAM after the reset, and this RAM is only 8K mov pc,lr SETUP_PERI_PO Rt:ldr R0, =0x70000013 @base addres:0x70000000,size:256mb mcr p15,0,r0,c15,c2,4 mov pc,lr display _led:ldr R0,=ledcon @ R0 is set to Ledcon, or GPKCON0 registers.  
            This register @ is used to select the function of the port K pins: @ is output, input, or other  mov r1, #0x110000 str r1,[r0] @ set gpk4,5 as output port Ldr R0,=leddat @ The R0 is set to the Gpkdat register.  
            This register @ for read/write port b pins data mov r1, #0x00000000 @ This value is 0x000000, low level light LED STR R1,[R0] @ gpk4,5 output 0,led4,5 Light mov pc,lr

The

Main.c file is as follows:

 #define RGPKCON0 (* (Volatile unsigned *) (0x7f008800)) #define RGPKCON1 (* (Volatile unsigned *) (0x7f0 08804) #define RGPKDAT (* (Volatile unsigned *) (0x7f008808)) #define RGPKPUD (* (Volatile unsigned *) (0 x7f00880c)) void Port_init (void) {rGPKCON0 = (rGPKCON0 & ~ (0xffffu<<16)) | (  
    0X1111U<<16); Rgpkpud = (Rgpkpud & ~ (0xffU << 8)) |  
(0X00U<<8); } void Led_display (int data) {Rgpkdat = (Rgpkdat & ~ (0xf<<4)) |  
(Data & 0xf) <<4);  
        } static void Leddelay (void) {volatile unsigned int k;  
for (k = 0; k < 200000; k++);      
    int main () {port_init (); for (;;)  
        {Led_display (0x1);//Leddelay (); Led_display (0x2);  
    Leddelay (); Led_display (0x4);  
    Leddelay (); Led_display (0x8);  
    Leddelay ();  
return 0; }

Makefile files are as follows:

Led_on_c.bin:bootsect.s  main.c  
    arm-linux-gcc-g-c-o bootsect.o bootsect.s arm-linux-gcc-g-c-o main.o  
    ma IN.C  
    arm-linux-ld-ttext 0x0000000-g  bootsect.o main.o-o linux_kernel_elf arm-linux-objcopy-o binary-s  
    Linux_kernel_elf Linux_kernel.bin  
    arm-linux-objdump-d-B binary-m arm  linux_kernel.bin > Linux_kernel.dis Clean  
:  
    rm-f *.dis *.bin *elf *.o

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.