|
本帖最后由 jiangdou 于 2015-6-25 10:05 编辑
CB_A10裸奔代码,A10当单片机用大家都来瞧一瞧看一看,收益匪浅
此代码不需要内存可以运行
源码下载:
a, A10_私服下载地址:http://www.jiangdoudou.uni.me:8111/A10_luoben_LED
b, github链接:https://github.com/jiangdoudou/allwiner_A10_luoben_leds
视频展示:
used : 使用方法:
/*
* Platform for: allwiner A10
* author by jiangdou
* you have anything,plese to QQ:344283973
* time at: 2012-0801
*
*
*/
How to compile ....
make && make clean
use TF card to boot......
$ chmod +x mksunxiboot //此工具需要ubuntu-64bit !!!!!!(源码,重新编译,32位就可以运行,请参考本帖12楼)
$ ./mksunxiboot led.bin xx.bin //给执行文件加头部,目的让A10芯片上的BROM程序识别到TF的程序
$ dd if=xx.bin of=/dev/sdX bs=1024 seek=8
modify file 1st -> main.c- #include "clock.h"
- #include "uart.h"
- #include "lib.h"
- #define PB_CFG2 (*(volatile unsigned int *)0x01c2082c)
- #define PE_DAT (*(volatile unsigned int *)0x01c208A0)
- #define PE_CFG (*(volatile unsigned int *)0x01c20890)
- /*
- void delay(void)
- {
- puts("delay open for leds on and off\n\r");
- int i,a;
- for (i=1;i<1000;i++)
- for (a=1;a<1000;a++);
-
- }
- */
- /*内嵌,精准延时...........此处是亮点!!!!!!!!!*/
- static inline void delay(unsigned long loops)
- {
- puts("delay open for leds on and off\n\r");
- __asm__ volatile ("1:\n"
- "subs %0, %1, #1\n"
- "bne 1b":"=r" (loops):"0" (loops));
- }
- void gpio_init()
- {
- /*bit[30:28]:PB23_SELECT 010:UART0_RX
- *bit[26:24]:PB22_SELECT 010:UART0_TX
- */
- PB_CFG2 |= ((0x2<<24)|(0x2<<28));
- /**/
- PE_CFG |= ((0x1<<20)|(0x1<<24)|(0x1<<28));
- }
- int main(void)
- {
- char c;
- clock_init(); /* 初始化时钟 */
- gpio_init();
- uart_init(); /* 初始化UART0 */
- puts("\n\r#####################################\n\r");
- puts("The board:Inet_97F_REV03\n\r");
- puts("The NAND: 4096MB\n\r");
- puts("The SRAM:HY x4 512MB\n\r");
- puts("just bootloader led. date: 2012.10.20;by jiangdou\n\r");
- puts("#####################################\n");
- while (1)
- {
- PE_DAT = 0x80;
- puts("GPIO_PE LED 1\n\r");
- delay(80000000);
- PE_DAT = 0x00;
- delay(80000000);
- PE_DAT = (0x1<<5);
- puts("GPIO_PE LED 2\n\r");
- delay(80000000);
- PE_DAT = (0x5<<5);
- puts("GPIO_PE LED 3\n\r");
- delay(80000000);
- PE_DAT = (0x2<<5);
- puts("GPIO_PE LED 4\n\r");
- delay(80000000);
- PE_DAT = (0x6<<5);
- puts("GPIO_PE LED 5\n\r");
- delay(80000000);
- PE_DAT = (0x3<<5);
- puts("GPIO_PE LED 6\n\r");
- delay(80000000);
- PE_DAT = (0x7<<5);
- puts("GPIO_PE LED 7\n\r");
- delay(80000000);
- PE_DAT = (0x0<<5);
- puts("GPIO_PE LED 8\n\r");
- }
- return 0;
- }
复制代码 1.file 1 -> main.c- /*
- * Platform for: allwiner A10
- * author by jiangdou
- * time at: 2012-0801
- *
- *
- */
- /*****deleted****/
复制代码 2.file 2 -> start.S- /*
- * Platform for: allwiner A10
- * author by jiangdou
- * time at: 2012-0801
- *
- *
- */
- .global _start
- _start:
- ldr r0,=0x1c20890
- ldr r1,=0x1000000
- str r1,[r0]
-
- ldr r0,=0x1c208a0
- ldr r1,=0x40
- str r1,[r0]
- ldr sp, =0x00007f00 //条用C程序之前设置好堆栈
- b main
复制代码 3.file 3 -> uart.c- /*
- * Platform for: allwiner A10
- * author by jiangdou
- * time at: 2012-0801
- *
- *
- */
- #define UART0_LCR (*(volatile unsigned int *)0x01C2800C)
- #define UART0_DLH (*(volatile unsigned int *)0x01C28004)
- #define UART0_DLL (*(volatile unsigned int *)0x01C28000)
- #define UART0_LSR (*(volatile unsigned int *)0x01C28014)
- #define UART0_THR (*(volatile unsigned int *)0x01C28000)
- #define UART0_RBR (*(volatile unsigned int *)0x01C28000)
- void uart_init(void)
- {
- /*select dll dlh*/
- /*bit7:Divisor Latch Access Bit
- *0:Select RX Buffer Register(RBR)/TX Holding Register(THR)and Interrupt Enable register(IER)
- *1:Select Divisor Latch LS Register(DLL) and Divisor Latch MS Register(DLM)
- */
- UART0_LCR = 0x80;
- /*set baudrate*/
- UART0_DLH = 0x0;
- /*bit[7:0]:Divisor Latch Low
- *baud rate=(serial clock freq)/(16*divisor)
- *divisor=24M/16/115200=13.02083
- */
- UART0_DLL = 0xd;
- /*set line control*/
- /*bit3:Parity Enable 0:parity disable 1:parity enable
- *bit2:Number of stop bits
- *0:1 stop bit;1:1.5 stop bits when DLS(LCR[1:0]is zero,else 2 stop bits)
- *bit[1:0] Data Length Select 00:5bits;01:6bits;10:7bits;11:8bits
- */
- UART0_LCR = ((0<<3)|(0<<2)|0x3);
- }
- char getc(void)
- {
- char c;
- while (!(UART0_LSR & (1<<0)));
- c = UART0_RBR;
- return c;
- }
- void putc(char c)
- {
- while (!(UART0_LSR & (1<<6)));
- UART0_THR = c;
- return;
- }
- void puts(char *str)
- {
- int i = 0;
- while (str[i])
- {
- putc(str[i]);
- i++;
- }
- }
复制代码 4.file 4 -> clock.c- /*
- * Platform for: allwiner A10
- * author by jiangdou
- * time at: 2012-0801
- *
- *
- */
- #define CPU_AHB_APB0_CFG (*(volatile unsigned int *)0x01c20054)
- #define PLL1_CFG (*(volatile unsigned int *)0x01c20000)
- #define APB1_CLK_DIV_CFG (*(volatile unsigned int *)0x01c20058)
- #define APB1_GATE (*(volatile unsigned int *)0x01c2006C)
- void sdelay(unsigned long loops)
- {
- __asm__ volatile("1:\n" "subs %0, %1, #1\n"
- "bne 1b":"=r" (loops):"0"(loops));
- }
- void clock_init(void)
- {
- /*AXI_DIV_1[1:0] AXI_CLK_DIV_RATIO 00:/1 AXI Clock source is CPU clock
- *AHB_DIV_2[5:4] AHP_CLK_DIV_RATIO 01:/2 AHB Clock source is AXI CLOCK
- *APB0_DIV_1[9:8] APB0_CLK_RATIO 00:/2 APB0 clock source is AHB2 clock
- *CPU_CLK_SRC_OSC24M[17:16] CPU_CLK_SRC_SEL 01:OSC24M
- */
- CPU_AHB_APB0_CFG = ((0<<0)|(0x1<<4)|(0<<8)|(1<<16));
- /*bit31:PLL1_Enable 1:Enable
- *bit25:EXG_MODE 0x0:Exchange mode
- *bit[17:16]:PLL1_OUT_EXT_DIVP 0x0:P=1
- *bit[12:8]:PLL1_FACTOR_N 0x10:Factor=16,N=16
- *bit[5:4]:PLL1_FACTOR_K 0x0:K=1
- *bit3:SIG_DELT_PAT_IN 0x0
- *bit2:SIG_DELT_PAT_EN 0x0
- *bit[1:0]PLL1_FACTOR_M 0x0:M=1
- *The PLL1 output=(24M*N*K)/(M*P)=(24M*16*1)/(1*1)=384M is for the coreclk
- */
- PLL1_CFG = 0xa1005000;
- sdelay(200);
- CPU_AHB_APB0_CFG = ((0<<0)|(0x1<<4)|(0<<8)|(2<<16));//CPU_CLK_SRC_SEL 10:PLL1
- /*uart clock source is apb1,config apb1 clock*/
- /*bit[25:24]:APB1_CLK_SRC_SEL 00:OSC24M
- *bit[17:16]:CLK_RAT_N 0X0:1 The select clock source is pre-divided by 2^1
- *bit[4:0]:CLK_RAT_M 0x0:1 The pre-devided clock is divided by(m+1)
- */
- APB1_CLK_DIV_CFG = ((0<<5)|(0<<16)|(0<<24));
- /*open the clock for uart0*/
- /*bit16:UART0_APB_GATING 1:pass 0:mask*/
- APB1_GATE = (0x1<<16);
- }
复制代码 5.file 5 -> lib.c
- /*
- * Platform for: allwiner A10
- * author by jiangdou
- * time at: 2012-0801
- *
- *
- */
- int putchar(int c)
- {
- if (c == '\n')
- putc('\r');
- putc(c);
- return 0;
- }
复制代码 6.file 6 -> Makefile- #/*
- #* Platform for: allwiner A10
- #* author by jiangdou
- #* time at: 2012-0801
- #*
- #*
- #*/
- uart.bin:start.S main.c uart.c clock.c lib.c
- arm-linux-gnueabihf-gcc -nostdlib -c start.S -o start.o
- arm-linux-gnueabihf-gcc -nostdlib -c main.c -o main.o
- arm-linux-gnueabihf-gcc -nostdlib -c uart.c -o uart.o
- arm-linux-gnueabihf-gcc -nostdlib -c lib.c -o lib.o
- arm-linux-gnueabihf-gcc -nostdlib -c clock.c -o clock.o
- arm-linux-gnueabihf-ld -Ttext 0x00000020 start.o main.o uart.o lib.o clock.o -o uart_elf
- arm-linux-gnueabihf-objcopy -O binary -S uart_elf uart.bin
- clean:
- rm -rf *.o *.bin uart_elf *.dis
复制代码 反编译效果 $ arm-linux-gnueabihf-objdump -S uart_elf > uart_.S
反汇编led.bin,看看mksunxiboot 工具增加什么内容呢????
$$ arm-linux-gnueabihf-objdump -D -b binary -m arm led.bin > led.asm
....................
...
|
-
|