CB_A10裸奔代码,A10当单片机用,屌爆了有木有,收益.....
本帖最后由 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
视频展示:http://v.youku.com/v_show/id_XNjI5MjY2OTgw.html
used :使用方法:
/*
* Platformfor: allwinerA10
* authorby jiangdou
* youhave anything,plese to QQ:344283973
* timeat: 2012-0801
*
*
*/
How to compile ....
make&& make clean
use TF card to boot......
$ chmod +xmksunxiboot //此工具需要ubuntu-64bit !!!!!!(源码,重新编译,32位就可以运行,请参考本帖12楼)
$ ./mksunxiboot led.bin xx.bin //给执行文件加头部,目的让A10芯片上的BROM程序识别到TF的程序
$ dd if=xx.bin of=/dev/sdX bs=1024 seek=8
modifyfile 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:PB23_SELECT 010:UART0_RX
*bit: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/*
* Platformfor: allwinerA10
* authorby jiangdou
* timeat: 2012-0801
*
*
*/
/*****deleted****/
2.file 2 -> start.S/*
* Platformfor: allwinerA10
* authorby jiangdou
* timeat: 2012-0801
*
*
*/
.global _start
_start:
ldr r0,=0x1c20890
ldr r1,=0x1000000
str r1,
ldr r0,=0x1c208a0
ldr r1,=0x40
str r1,
ldr sp, =0x00007f00 //条用C程序之前设置好堆栈
b main3.file 3 -> uart.c/*
* Platformfor: allwinerA10
* authorby jiangdou
* timeat: 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: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(LCRis zero,else 2 stop bits)
*bit 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)
{
putc(str);
i++;
}
}4.file 4 ->clock.c/*
* Platformfor: allwinerA10
* authorby jiangdou
* timeat: 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_1AXI_CLK_DIV_RATIO 00:/1 AXI Clock source is CPU clock
*AHB_DIV_2AHP_CLK_DIV_RATIO 01:/2 AHB Clock source is AXI CLOCK
*APB0_DIV_1 APB0_CLK_RATIO 00:/2 APB0 clock source is AHB2 clock
*CPU_CLK_SRC_OSC24M 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:PLL1_OUT_EXT_DIVP 0x0:P=1
*bit:PLL1_FACTOR_N 0x10:Factor=16,N=16
*bit:PLL1_FACTOR_K 0x0:K=1
*bit3:SIG_DELT_PAT_IN 0x0
*bit2:SIG_DELT_PAT_EN 0x0
*bitPLL1_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:APB1_CLK_SRC_SEL 00:OSC24M
*bit:CLK_RAT_N 0X0:1 The select clock source is pre-divided by 2^1
*bit: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
/*
* Platformfor: allwinerA10
* authorby jiangdou
* timeat: 2012-0801
*
*
*/
int putchar(int c)
{
if (c == '\n')
putc('\r');
putc(c);
return 0;
}6.file 6 ->Makefile#/*
#* Platformfor: allwinerA10
#* authorby jiangdou
#* timeat: 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
....................
...
这个要怎么用呢?烧到SD卡上?还是在bootloader中调用?JTAG? :Q你的A10好惨,变单片机了:lol 使用方法:
/*
* Platformfor: allwinerA10
* authorby jiangdou
* youhave anything,plese to QQ:344283973
* timeat: 2012-0801
*
*
*/
How to compile ....
make&& make clean
use TF card to boot......
./mksunxiboot uart.bin xx.bin
dd if=xx.bin of=/dev/sdX bs=1024 seek=8 以前玩的s5pv210的时候也干过这事 有空玩下 有不需要内存的程序?? lknlfy 发表于 2014-8-15 08:22 static/image/common/back.gif
有不需要内存的程序??
你试试,真的不需要 lknlfy 发表于 2014-8-15 08:22 static/image/common/back.gif
有不需要内存的程序??
你的手表不错....................
那是因为把程序load到soc里面的sram上运行,所不需要,大程序就不行了...... ./mksunxiboot uart.bin usb_uart.bin
bash: ./mksunxiboot: 无法执行二进制文件
-rwxrwxr-x
页:
[1]
2