├── 01_Blinker ├── README.md ├── main.c ├── makefile ├── memmap.ld └── start.s ├── 02_GPIO ├── GPIO.c ├── GPIO.h ├── README.md ├── bin │ └── spl.boot ├── clock_module.c ├── clock_module.h ├── control_module.c ├── control_module.h ├── main.c ├── makefile ├── memmap.ld ├── pad.c ├── pad.h ├── start.h ├── start.s └── types.h ├── 03_LED ├── GPIO.c ├── GPIO.h ├── LED.c ├── LED.h ├── README.md ├── clock_module.c ├── clock_module.h ├── control_module.c ├── control_module.h ├── main.c ├── makefile ├── memmap.ld ├── pad.c ├── pad.h ├── start.h ├── start.s └── types.h ├── 04_UART ├── GPIO.c ├── GPIO.h ├── LED.c ├── LED.h ├── README.md ├── UART.c ├── UART.h ├── clock_module.c ├── clock_module.h ├── control_module.c ├── control_module.h ├── main.c ├── makefile ├── memmap.ld ├── pad.c ├── pad.h ├── start.h ├── start.s ├── types.h ├── wdt_control.c └── wdt_control.h ├── 05_low_level_init ├── README.md ├── board │ ├── LED.c │ ├── LED.h │ ├── board_init.c │ ├── makefile │ └── obj │ │ ├── LED.o │ │ └── board_init.o ├── core │ ├── core_handlers.s │ ├── core_init.c │ ├── llma.h │ ├── llma.s │ ├── makefile │ ├── obj │ │ ├── core_handlers.o │ │ ├── core_init.o │ │ ├── llma.o │ │ ├── startup.o1 │ │ └── startup_ARMCA8.o1 │ └── startup_ARMCA8.s ├── kernel │ ├── main.c │ ├── makefile │ └── obj │ │ └── main.o ├── makefile ├── memmap.ld ├── proc │ ├── GPIO.c │ ├── GPIO.h │ ├── UART.c │ ├── UART.h │ ├── clock_module.c │ ├── clock_module.h │ ├── control_module.c │ ├── control_module.h │ ├── makefile │ ├── obj │ │ ├── GPIO.o │ │ ├── UART.o │ │ ├── clock_module.o │ │ ├── control_module.o │ │ ├── pad.o │ │ ├── proc_Handlers.o │ │ └── proc_init.o │ ├── pad.c │ ├── pad.h │ ├── proc_handlers.c │ └── proc_init.c └── sys │ ├── makefile │ ├── obj │ └── types.o │ ├── types.c │ └── types.h ├── 06_stdlib ├── README.md ├── board │ ├── LED.c │ ├── LED.h │ ├── board_init.c │ ├── makefile │ └── obj │ │ ├── LED.o │ │ └── board_init.o ├── core │ ├── __aeabi.s │ ├── core_handlers.s │ ├── core_init.c │ ├── llma.h │ ├── llma.s │ ├── makefile │ ├── obj │ │ ├── __aeabi.o │ │ ├── core_handlers.o │ │ ├── core_init.o │ │ ├── llma.o │ │ ├── startup.o1 │ │ └── startup_ARMCA8.o1 │ └── startup_ARMCA8.s ├── kernel │ ├── main.c │ ├── makefile │ └── obj │ │ └── main.o ├── makefile ├── memmap.ld ├── proc │ ├── GPIO.c │ ├── GPIO.h │ ├── UART.c │ ├── UART.h │ ├── clock_module.c │ ├── clock_module.h │ ├── control_module.c │ ├── control_module.h │ ├── makefile │ ├── obj │ │ ├── GPIO.o │ │ ├── UART.o │ │ ├── clock_module.o │ │ ├── control_module.o │ │ ├── pad.o │ │ ├── proc_Handlers.o │ │ └── proc_init.o │ ├── pad.c │ ├── pad.h │ ├── proc_handlers.c │ └── proc_init.c └── sys │ ├── makefile │ ├── obj │ ├── syscalls.o │ └── types.o │ ├── syscalls.c │ ├── types.c │ └── types.h ├── 07_Bootloader ├── README.md ├── board │ ├── LED.c │ ├── LED.h │ ├── board_init.c │ └── makefile ├── core │ ├── __aeabi.s │ ├── core_handlers.s │ ├── core_init.c │ ├── llma.h │ ├── llma.s │ ├── makefile │ └── startup_ARMCA8.s ├── kernel │ ├── main.c │ └── makefile ├── makefile ├── memmap.ld ├── proc │ ├── DDR.c │ ├── DDR.h │ ├── EMIF.c │ ├── EMIF.h │ ├── GPIO.c │ ├── GPIO.h │ ├── PLL.c │ ├── PLL.h │ ├── UART.c │ ├── UART.h │ ├── clock_module.c │ ├── clock_module.h │ ├── control_module.c │ ├── control_module.h │ ├── makefile │ ├── pad.c │ ├── pad.h │ ├── proc_handlers.c │ └── proc_init.c └── sys │ ├── makefile │ ├── syscalls.c │ ├── types.c │ └── types.h ├── 08_test_CXX ├── README.md ├── bin │ └── spl.boot ├── board │ ├── LED.c │ ├── LED.h │ ├── board_init.c │ └── makefile ├── core │ ├── core_handlers.s │ ├── core_init.c │ ├── llma.h │ ├── llma.s │ ├── makefile │ └── startup_ARMCA8.s ├── kernel │ ├── main.cpp │ └── makefile ├── makefile ├── memmap.ld ├── proc │ ├── GPIO.c │ ├── GPIO.h │ ├── UART.c │ ├── UART.h │ ├── clock_module.c │ ├── clock_module.h │ ├── control_module.c │ ├── control_module.h │ ├── interrupt.h │ ├── makefile │ ├── pad.c │ ├── pad.h │ ├── proc_handlers.c │ └── proc_init.c └── sys │ ├── makefile │ ├── syscalls.c │ ├── types.c │ └── types.h ├── 09_USB_Bootloader ├── README.md ├── bin │ └── spl.boot ├── board │ ├── LED.c │ ├── LED.h │ ├── board_init.c │ └── makefile ├── core │ ├── __aeabi.s │ ├── core_handlers.s │ ├── core_init.c │ ├── llma.h │ ├── llma.s │ ├── makefile │ └── startup_ARMCA8.s ├── kernel │ ├── main.c │ └── makefile ├── makefile ├── memmap.ld ├── proc │ ├── DDR.c │ ├── DDR.h │ ├── EMIF.c │ ├── EMIF.h │ ├── GPIO.c │ ├── GPIO.h │ ├── PLL.c │ ├── PLL.h │ ├── UART.c │ ├── UART.h │ ├── USB.c │ ├── USB.h │ ├── clock_module.c │ ├── clock_module.h │ ├── control_module.c │ ├── control_module.h │ ├── interrupt.h │ ├── makefile │ ├── pad.c │ ├── pad.h │ ├── proc_handlers.c │ └── proc_init.c └── sys │ ├── DFU.c │ ├── DFU.h │ ├── makefile │ ├── syscalls.c │ ├── types.c │ └── types.h ├── 10_I2C ├── README.md ├── board │ ├── EEPROM.cpp │ ├── EEPROM.h │ ├── LED.c │ ├── LED.h │ ├── board_init.c │ └── makefile ├── core │ ├── core_handlers.s │ ├── core_init.c │ ├── llma.h │ ├── llma.s │ ├── makefile │ └── startup_ARMCA8.s ├── kernel │ ├── main.cpp │ └── makefile ├── makefile ├── memmap.ld ├── proc │ ├── GPIO.c │ ├── GPIO.h │ ├── I2C.cpp │ ├── I2C.h │ ├── UART.c │ ├── UART.h │ ├── clock_module.c │ ├── clock_module.h │ ├── control_module.c │ ├── control_module.h │ ├── interrupt.h │ ├── makefile │ ├── pad.c │ ├── pad.h │ ├── proc_handlers.c │ └── proc_init.c └── sys │ ├── makefile │ ├── syscalls.c │ ├── types.c │ └── types.h ├── LICENSE ├── README.md └── Uboot ├── MLO ├── u-boot.img └── uEnv.txt /01_Blinker/README.md: -------------------------------------------------------------------------------- 1 | 01_Blinker 2 | ==================== 3 | 4 | This example was the first one, to see if my boot procedure was working. I just wanted to blink the onboard leds without any fuss. it is inspired by Ali Utku Selen (https://github.com/auselen under GNU GPL) in the down-to-the-bone repository. 5 | 6 | ==================== 7 | A few important points here: 8 | * the *_start* symbol **must** be the entrypoint 9 | * for the simplest peripheral access, i used assembly (namely *PUT32* and *GET32*) 10 | * the *memmap.ld* isn't complete in this example, as the origin is set to *0x0* 11 | * the copy target in the makefile is only specific to my boot setup (dnsmasq loading spl.boot) -------------------------------------------------------------------------------- /01_Blinker/main.c: -------------------------------------------------------------------------------- 1 | extern void PUT32 (unsigned int address, unsigned int value); 2 | extern unsigned int GET32 (unsigned int address); 3 | 4 | #define GPIO1_BASE 0x4804C000 5 | #define GPIO_SYSCONFIG 0x10 6 | #define GPIO_SYSSTATUS 0x114 7 | #define GPIO_OE 0x134 8 | #define GPIO_CLRDATAOUT 0x190 9 | #define GPIO_SETDATAOUT 0x194 10 | 11 | #define CM_PER_BASE 0x44e00000 12 | #define CM_PER_GPIO1 0xAC 13 | 14 | #define TIME 500000 15 | void _main (void) 16 | { 17 | volatile unsigned int ra; 18 | PUT32(CM_PER_BASE+CM_PER_GPIO1, 1<<18 | 2); 19 | ra = GET32(GPIO1_BASE+GPIO_OE); 20 | ra &= ~(15<<21); 21 | PUT32(GPIO1_BASE+GPIO_OE,ra); 22 | for(;;) 23 | { 24 | PUT32(GPIO1_BASE+GPIO_SETDATAOUT, (15<<21)); 25 | for(ra = 0; ra < TIME; ra ++); 26 | PUT32(GPIO1_BASE+GPIO_CLRDATAOUT,15<<21); 27 | for(ra = 0; ra < TIME; ra ++); 28 | } 29 | return; 30 | } 31 | 32 | /* 33 | The MIT License (MIT) 34 | 35 | Copyright (c) 2015 Alexis Marquet 36 | 37 | Permission is hereby granted, free of charge, to any person obtaining a copy 38 | of this software and associated documentation files (the "Software"), to deal 39 | in the Software without restriction, including without limitation the rights 40 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 41 | copies of the Software, and to permit persons to whom the Software is 42 | furnished to do so, subject to the following conditions: 43 | 44 | The above copyright notice and this permission notice shall be included in 45 | all copies or substantial portions of the Software. 46 | 47 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 48 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 49 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 50 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 51 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 52 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 53 | THE SOFTWARE. 54 | */ 55 | -------------------------------------------------------------------------------- /01_Blinker/makefile: -------------------------------------------------------------------------------- 1 | CHAIN=arm-none-eabi 2 | 3 | 4 | all: start.s main.c 5 | $(CHAIN)-as start.s -o start.o 6 | $(CHAIN)-gcc -c main.c -o main.o 7 | $(CHAIN)-ld start.o main.o -T memmap.ld -o main.elf 8 | $(CHAIN)-objcopy main.elf spl.boot -O binary 9 | copy: 10 | cp spl.boot ../boot 11 | 12 | clean: 13 | rm -rf *.o 14 | rm -rf *.elf 15 | rm -rf *.boot 16 | rm -rf ../boot/*.boot -------------------------------------------------------------------------------- /01_Blinker/memmap.ld: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | ram : ORIGIN = 0x0, LENGTH = 0x1B400 4 | } 5 | 6 | SECTIONS 7 | { 8 | .text : { *(.text*) } > ram 9 | .bss : { *(.bss*) } > ram 10 | } 11 | -------------------------------------------------------------------------------- /01_Blinker/start.s: -------------------------------------------------------------------------------- 1 | .equ CM_PER_GPIO1_CLKCTRL, 0x44e000AC 2 | .equ GPIO1_OE, 0x4804C134 3 | .equ GPIO1_SETDATAOUT, 0x4804C194 4 | 5 | _start: 6 | mrs r0, cpsr 7 | bic r0, r0, #0x1F @ clear mode bits 8 | orr r0, r0, #0x13 @ set SVC mode 9 | orr r0, r0, #0xC0 @ disable FIQ and IRQ 10 | msr cpsr, r0 11 | 12 | @sub sp,sp,#0x1800 @6kB public stack 13 | 14 | bl _main 15 | 16 | 17 | .loop: b .loop 18 | 19 | 20 | .globl PUT32 21 | PUT32: 22 | str r1,[r0] 23 | bx lr 24 | 25 | .globl GET32 26 | GET32: 27 | ldr r0,[r0] 28 | bx lr 29 | 30 | /* 31 | The MIT License (MIT) 32 | 33 | Copyright (c) Alexis Marquet 34 | 35 | Permission is hereby granted, free of charge, to any person obtaining a copy 36 | of this software and associated documentation files (the "Software"), to deal 37 | in the Software without restriction, including without limitation the rights 38 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | copies of the Software, and to permit persons to whom the Software is 40 | furnished to do so, subject to the following conditions: 41 | 42 | The above copyright notice and this permission notice shall be included in 43 | all copies or substantial portions of the Software. 44 | 45 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 | THE SOFTWARE. 52 | */ -------------------------------------------------------------------------------- /02_GPIO/README.md: -------------------------------------------------------------------------------- 1 | 02_GPIO 2 | ================= 3 | 4 | This example implements GPIO functions. it actually does the same as the 01_blinker example, although it is vary modular and generic. 5 | It is also documented using doxygen-style comments. 6 | 7 | ================= 8 | 9 | First thing first, the **memmap.ld** is modified to use global & constant variables in the programm, by setting the ram origin to the right value (0x402f0400), doccumented in the "Initialisation sequence" in the *TRM*. 10 | 11 | the first thing to do (after startup) is to initialise the GPIO port. 12 | **GPIO_initPort()** does that. It enable the **CKM_MODULE_REG** for the port wanted. 13 | 14 | Then you need to initialise the pin you want 15 | **GPIO_initPin()** sets the pad related to the "GPIO" function using the **PAD_setMode()** func. 16 | 17 | the last step of the GPIO initialisation is the direction. this example blinks the led, so you need to set it as output 18 | **GPIO_setDirection()** only sets the GPIO Output Enable or not. 19 | 20 | Then you can change the state of the GPIO using **GPIO_setPin()** & **GPIO_clrPin()** -------------------------------------------------------------------------------- /02_GPIO/bin/spl.boot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/02_GPIO/bin/spl.boot -------------------------------------------------------------------------------- /02_GPIO/clock_module.c: -------------------------------------------------------------------------------- 1 | // 2 | // clock_module.c 3 | // 4 | // Created by Alexis Marquet on 03/12/14. 5 | // 6 | // 7 | 8 | #include "clock_module.h" 9 | #include "start.h" 10 | #include "types.h" 11 | 12 | 13 | #define CKM_PER_BASE 0x44E00000 // clock module power enable register base, TMR 2.1 14 | static bool CKM_checkValidModule(CKM_MODULE_REG module) 15 | { 16 | if((module >CKM_PER_CLK_24MHZ_CLKSTCTRL)) 17 | { 18 | // TODO: raise error (CKM_MODULE_REG too big: /module) 19 | return false; 20 | } 21 | return true; 22 | } 23 | void CKM_setCLKModuleRegister(CKM_MODULE_REG module, unsigned int value) 24 | { 25 | if(CKM_checkValidModule(module)) 26 | { 27 | unsigned int addr_temp = CKM_PER_BASE + module; // clock module base + module offset, TRM 2.1 & 8.1.12.1 28 | PUT32(addr_temp, value); 29 | } 30 | } 31 | unsigned int CKM_getCLKModuleRegister(CKM_MODULE_REG module) 32 | { 33 | if(CKM_checkValidModule(module)) 34 | { 35 | unsigned int addr_temp = CKM_PER_BASE + module; // clock module base + module offset, TRM 2.1 & 8.1.12.1 36 | return GET32(addr_temp); 37 | } 38 | return 0; 39 | } 40 | 41 | 42 | /* 43 | The MIT License (MIT) 44 | 45 | Copyright (c) 2015 Alexis Marquet 46 | 47 | Permission is hereby granted, free of charge, to any person obtaining a copy 48 | of this software and associated documentation files (the "Software"), to deal 49 | in the Software without restriction, including without limitation the rights 50 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 51 | copies of the Software, and to permit persons to whom the Software is 52 | furnished to do so, subject to the following conditions: 53 | 54 | The above copyright notice and this permission notice shall be included in 55 | all copies or substantial portions of the Software. 56 | 57 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 58 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 59 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 60 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 61 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 62 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 63 | THE SOFTWARE. 64 | */ -------------------------------------------------------------------------------- /02_GPIO/control_module.c: -------------------------------------------------------------------------------- 1 | // 2 | // control_module.c 3 | // 4 | // Created by Alexis Marquet on 03/12/14. 5 | // 6 | // 7 | 8 | #include "control_module.h" 9 | #include "start.h" 10 | 11 | #define CM_MODULE_REGISTER_BASE 0x44E10000 12 | 13 | 14 | void CM_setCtrlModule(CONTROL_MODULE module, unsigned int value) 15 | { 16 | PUT32(CM_MODULE_REGISTER_BASE + module, value); 17 | } 18 | 19 | unsigned int CM_getCtrlModule(CONTROL_MODULE module) 20 | { 21 | return GET32(CM_MODULE_REGISTER_BASE + module); 22 | } 23 | 24 | 25 | 26 | 27 | 28 | /* 29 | The MIT License (MIT) 30 | 31 | Copyright (c) 2015 Alexis Marquet 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy 34 | of this software and associated documentation files (the "Software"), to deal 35 | in the Software without restriction, including without limitation the rights 36 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 37 | copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in 41 | all copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 48 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 49 | THE SOFTWARE. 50 | */ -------------------------------------------------------------------------------- /02_GPIO/main.c: -------------------------------------------------------------------------------- 1 | //#include "start.h" 2 | 3 | #include "GPIO.h" 4 | 5 | 6 | #define TIME 500000 7 | void _main (void) 8 | { 9 | volatile unsigned int ra; 10 | GPIO_initPort(GPIO1); 11 | GPIO_initPin(GPIO1,21); 12 | GPIO_initPin(GPIO1,22); 13 | GPIO_initPin(GPIO1,23); 14 | GPIO_initPin(GPIO1,24); 15 | GPIO_setDirection(GPIO1,21,OUTPUT); 16 | GPIO_setDirection(GPIO1,22,OUTPUT); 17 | GPIO_setDirection(GPIO1,23,OUTPUT); 18 | GPIO_setDirection(GPIO1,24,OUTPUT); 19 | 20 | 21 | 22 | for(;;) 23 | { 24 | GPIO_setPin(GPIO1,21); 25 | GPIO_setPin(GPIO1,22); 26 | GPIO_setPin(GPIO1,23); 27 | GPIO_setPin(GPIO1,24); 28 | for(ra = 0; ra < TIME; ra ++); 29 | GPIO_clrPin(GPIO1,21); 30 | GPIO_clrPin(GPIO1,22); 31 | GPIO_clrPin(GPIO1,23); 32 | GPIO_clrPin(GPIO1,24); 33 | for(ra = 0; ra < TIME; ra ++); 34 | } 35 | return; 36 | } 37 | 38 | 39 | 40 | /* 41 | The MIT License (MIT) 42 | 43 | Copyright (c) 2015 Alexis Marquet 44 | 45 | Permission is hereby granted, free of charge, to any person obtaining a copy 46 | of this software and associated documentation files (the "Software"), to deal 47 | in the Software without restriction, including without limitation the rights 48 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 49 | copies of the Software, and to permit persons to whom the Software is 50 | furnished to do so, subject to the following conditions: 51 | 52 | The above copyright notice and this permission notice shall be included in 53 | all copies or substantial portions of the Software. 54 | 55 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 56 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 57 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 58 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 59 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 60 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 61 | THE SOFTWARE. 62 | */ -------------------------------------------------------------------------------- /02_GPIO/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi 3 | CFLAGS=-std=c99 -Wall 4 | OBJ=obj/ 5 | BIN=bin/ 6 | 7 | all: start.o main.o GPIO.o pad.o control_module.o clock_module.o 8 | $(CHAIN)-ld $(OBJ)start.o $(OBJ)main.o $(OBJ)GPIO.o $(OBJ)pad.o $(OBJ)control_module.o $(OBJ)clock_module.o -T memmap.ld -o $(OBJ)main.elf 9 | $(CHAIN)-objcopy $(OBJ)main.elf $(BIN)spl.boot -O binary 10 | cp $(BIN)spl.boot ../boot 11 | 12 | start.o: start.s 13 | $(CHAIN)-as start.s -o $(OBJ)start.o 14 | 15 | main.o: main.c 16 | $(CHAIN)-gcc $(CFLAGS) -c main.c -o $(OBJ)main.o 17 | 18 | GPIO.o: GPIO.c 19 | $(CHAIN)-gcc $(CFLAGS) -c GPIO.c -o $(OBJ)GPIO.o 20 | 21 | pad.o: pad.c 22 | $(CHAIN)-gcc $(CFLAGS) -c pad.c -o $(OBJ)pad.o 23 | 24 | control_module.o: control_module.c 25 | $(CHAIN)-gcc $(CFLAGS) -c control_module.c -o $(OBJ)control_module.o 26 | 27 | clock_module.o: clock_module.c 28 | $(CHAIN)-gcc $(CFLAGS) -c clock_module.c -o $(OBJ)clock_module.o 29 | 30 | copy: 31 | cp $(BIN)spl.boot ../boot 32 | 33 | clean: 34 | rm -rf $(OBJ)*.o 35 | rm -rf $(OBJ)*.elf 36 | rm -rf $(BIN)*.boot 37 | rm -rf ../boot/*.boot 38 | 39 | 40 | dump: 41 | $(CHAIN)-objdump -D $(OBJ)main.elf -------------------------------------------------------------------------------- /02_GPIO/memmap.ld: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | ram : ORIGIN = 0x402f0400, LENGTH = 0x1B400 4 | } 5 | 6 | SECTIONS 7 | { 8 | .text : { *(.text*) } > ram 9 | .data : { *(.data*) } > ram 10 | .bss : { *(.bss*) } > ram 11 | } 12 | -------------------------------------------------------------------------------- /02_GPIO/pad.c: -------------------------------------------------------------------------------- 1 | // 2 | // pad.c 3 | // 4 | // Created by Alexis Marquet on 03/12/14. 5 | // 6 | // 7 | 8 | #include "pad.h" 9 | #include "control_module.h" 10 | 11 | 12 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 13 | { 14 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 15 | { 16 | unsigned int temp = CM_getCtrlModule(module); 17 | temp &= ~(0b111); 18 | temp |= mode; 19 | CM_setCtrlModule(module, temp); 20 | } 21 | else 22 | { 23 | // TODO: raise error (control module isnt a "conf " register) 24 | return; 25 | } 26 | } 27 | pinmode_t PAD_getMode(CONTROL_MODULE module) 28 | { 29 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 30 | { 31 | unsigned int temp = CM_getCtrlModule(module); 32 | temp &= ~(0b111); 33 | return (pinmode_t) temp; 34 | } 35 | else 36 | { 37 | // TODO: raise error (control module isnt a "conf " register) 38 | return -1; 39 | } 40 | } 41 | 42 | 43 | /* 44 | The MIT License (MIT) 45 | 46 | Copyright (c) 2015 Alexis Marquet 47 | 48 | Permission is hereby granted, free of charge, to any person obtaining a copy 49 | of this software and associated documentation files (the "Software"), to deal 50 | in the Software without restriction, including without limitation the rights 51 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 52 | copies of the Software, and to permit persons to whom the Software is 53 | furnished to do so, subject to the following conditions: 54 | 55 | The above copyright notice and this permission notice shall be included in 56 | all copies or substantial portions of the Software. 57 | 58 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 59 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 60 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 61 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 62 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 63 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 64 | THE SOFTWARE. 65 | */ -------------------------------------------------------------------------------- /02_GPIO/pad.h: -------------------------------------------------------------------------------- 1 | // 2 | // pad.h 3 | // 4 | // Created by Alexis Marquet on 03/12/14. 5 | // 6 | // 7 | /** 8 | * @file pad.h 9 | * @author Alexis Marquet 10 | * @date 03 Dec 2014 11 | * @brief File containing types & function prototypes concerning pad usage: TRM 9.2.2.1, Datasheet 4 12 | **/ 13 | #ifndef __pad_H 14 | #define __pad_H 15 | #include "control_module.h" 16 | 17 | 18 | typedef enum 19 | { 20 | MODE_0 = 0, 21 | MODE_1 = 1, 22 | MODE_2 = 2, 23 | MODE_3 = 3, 24 | MODE_4 = 4, 25 | MODE_5 = 5, 26 | MODE_6 = 6, 27 | MODE_7 = 7 28 | 29 | }pinmode_t; 30 | 31 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode); 32 | pinmode_t PAD_getMode(CONTROL_MODULE module); 33 | 34 | #endif /* defined(__pad_H) */ 35 | 36 | 37 | 38 | /* 39 | The MIT License (MIT) 40 | 41 | Copyright (c) 2015 Alexis Marquet 42 | 43 | Permission is hereby granted, free of charge, to any person obtaining a copy 44 | of this software and associated documentation files (the "Software"), to deal 45 | in the Software without restriction, including without limitation the rights 46 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 47 | copies of the Software, and to permit persons to whom the Software is 48 | furnished to do so, subject to the following conditions: 49 | 50 | The above copyright notice and this permission notice shall be included in 51 | all copies or substantial portions of the Software. 52 | 53 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 54 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 55 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 56 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 57 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 58 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 59 | THE SOFTWARE. 60 | */ -------------------------------------------------------------------------------- /02_GPIO/start.h: -------------------------------------------------------------------------------- 1 | // 2 | // start.h 3 | // 4 | // Created by Alexis Marquet on 03/12/14. 5 | // 6 | // 7 | 8 | #ifndef __start_H 9 | #define __start_H 10 | 11 | void PUT32(unsigned int address, unsigned int value); 12 | unsigned int GET32 (unsigned int address); 13 | #endif 14 | 15 | 16 | 17 | /* 18 | The MIT License (MIT) 19 | 20 | Copyright (c) 2015 Alexis Marquet 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy 23 | of this software and associated documentation files (the "Software"), to deal 24 | in the Software without restriction, including without limitation the rights 25 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 26 | copies of the Software, and to permit persons to whom the Software is 27 | furnished to do so, subject to the following conditions: 28 | 29 | The above copyright notice and this permission notice shall be included in 30 | all copies or substantial portions of the Software. 31 | 32 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 33 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 34 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 35 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 36 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 37 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 38 | THE SOFTWARE. 39 | */ -------------------------------------------------------------------------------- /02_GPIO/start.s: -------------------------------------------------------------------------------- 1 | 2 | _start: 3 | mrs r0, cpsr 4 | bic r0, r0, #0x1F @ clear mode bits 5 | orr r0, r0, #0x13 @ set SVC mode 6 | orr r0, r0, #0xC0 @ disable FIQ and IRQ 7 | msr cpsr, r0 8 | 9 | ldr sp, =0x4030CDFC @6kB public stack TMR 26.1.3.2 10 | 11 | bl _main 12 | 13 | 14 | .loop: b .loop 15 | 16 | 17 | .globl PUT32 18 | PUT32: 19 | str r1,[r0] 20 | bx lr 21 | 22 | .globl GET32 23 | GET32: 24 | ldr r0,[r0] 25 | bx lr 26 | 27 | 28 | 29 | 30 | /* 31 | The MIT License (MIT) 32 | 33 | Copyright (c) 2015 Alexis Marquet 34 | 35 | Permission is hereby granted, free of charge, to any person obtaining a copy 36 | of this software and associated documentation files (the "Software"), to deal 37 | in the Software without restriction, including without limitation the rights 38 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | copies of the Software, and to permit persons to whom the Software is 40 | furnished to do so, subject to the following conditions: 41 | 42 | The above copyright notice and this permission notice shall be included in 43 | all copies or substantial portions of the Software. 44 | 45 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 | THE SOFTWARE. 52 | */ -------------------------------------------------------------------------------- /02_GPIO/types.h: -------------------------------------------------------------------------------- 1 | // 2 | // types.h 3 | // 4 | // Created by Alexis Marquet on 03/12/14. 5 | // 6 | // 7 | 8 | #ifndef __types_H 9 | #define __types_H 10 | 11 | typedef enum 12 | { 13 | true = 1, 14 | false = 0 15 | }bool; 16 | 17 | #endif 18 | 19 | 20 | 21 | /* 22 | The MIT License (MIT) 23 | 24 | Copyright (c) 2015 Alexis Marquet 25 | 26 | Permission is hereby granted, free of charge, to any person obtaining a copy 27 | of this software and associated documentation files (the "Software"), to deal 28 | in the Software without restriction, including without limitation the rights 29 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 30 | copies of the Software, and to permit persons to whom the Software is 31 | furnished to do so, subject to the following conditions: 32 | 33 | The above copyright notice and this permission notice shall be included in 34 | all copies or substantial portions of the Software. 35 | 36 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 37 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 38 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 39 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 40 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 41 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 42 | THE SOFTWARE. 43 | */ -------------------------------------------------------------------------------- /03_LED/README.md: -------------------------------------------------------------------------------- 1 | 03_LED 2 | ================ 3 | 4 | This example counts binarely on the Leds. Everything needed to use the User Leds has been put nicely in **LED.c** & **LED.h** 5 | 6 | **LED_init()** inits the GPIO port and the Pin, both for GPIO function & Direction. 7 | 8 | And then use the set,clear, invert, and set_value functions... -------------------------------------------------------------------------------- /03_LED/clock_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file clock_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning clock module usage: TRM 8 6 | **/ 7 | 8 | #include "clock_module.h" 9 | #include "start.h" 10 | #include "types.h" 11 | 12 | 13 | #define CKM_PER_BASE 0x44E00000 // clock module power enable register base, TMR 2.1 14 | static bool CKM_checkValidModule(CKM_MODULE_REG module) 15 | { 16 | if((module >CKM_PER_CLK_24MHZ_CLKSTCTRL)) 17 | { 18 | // TODO: raise error (CKM_MODULE_REG too big: /module) 19 | return false; 20 | } 21 | return true; 22 | } 23 | void CKM_setCLKModuleRegister(CKM_MODULE_REG module, unsigned int value) 24 | { 25 | if(CKM_checkValidModule(module)) 26 | { 27 | unsigned int addr_temp = CKM_PER_BASE + module; // clock module base + module offset, TRM 2.1 & 8.1.12.1 28 | PUT32(addr_temp, value); 29 | } 30 | } 31 | unsigned int CKM_getCLKModuleRegister(CKM_MODULE_REG module) 32 | { 33 | if(CKM_checkValidModule(module)) 34 | { 35 | unsigned int addr_temp = CKM_PER_BASE + module; // clock module base + module offset, TRM 2.1 & 8.1.12.1 36 | return GET32(addr_temp); 37 | } 38 | return 0; 39 | } 40 | 41 | 42 | /* 43 | The MIT License (MIT) 44 | 45 | Copyright (c) 2015 Alexis Marquet 46 | 47 | Permission is hereby granted, free of charge, to any person obtaining a copy 48 | of this software and associated documentation files (the "Software"), to deal 49 | in the Software without restriction, including without limitation the rights 50 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 51 | copies of the Software, and to permit persons to whom the Software is 52 | furnished to do so, subject to the following conditions: 53 | 54 | The above copyright notice and this permission notice shall be included in 55 | all copies or substantial portions of the Software. 56 | 57 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 58 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 59 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 60 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 61 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 62 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 63 | THE SOFTWARE. 64 | */ -------------------------------------------------------------------------------- /03_LED/control_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file control_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning control module usage: TRM 9, TRM 9.3 6 | **/ 7 | 8 | #include "control_module.h" 9 | #include "start.h" 10 | 11 | #define CM_MODULE_REGISTER_BASE 0x44E10000 12 | 13 | 14 | void CM_setCtrlModule(CONTROL_MODULE module, unsigned int value) 15 | { 16 | PUT32(CM_MODULE_REGISTER_BASE + module, value); 17 | } 18 | 19 | unsigned int CM_getCtrlModule(CONTROL_MODULE module) 20 | { 21 | return GET32(CM_MODULE_REGISTER_BASE + module); 22 | } 23 | 24 | /* 25 | The MIT License (MIT) 26 | 27 | Copyright (c) 2015 Alexis Marquet 28 | 29 | Permission is hereby granted, free of charge, to any person obtaining a copy 30 | of this software and associated documentation files (the "Software"), to deal 31 | in the Software without restriction, including without limitation the rights 32 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 33 | copies of the Software, and to permit persons to whom the Software is 34 | furnished to do so, subject to the following conditions: 35 | 36 | The above copyright notice and this permission notice shall be included in 37 | all copies or substantial portions of the Software. 38 | 39 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 40 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 41 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 42 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 43 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 44 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 45 | THE SOFTWARE. 46 | */ -------------------------------------------------------------------------------- /03_LED/main.c: -------------------------------------------------------------------------------- 1 | //#include "start.h" 2 | 3 | #include "GPIO.h" 4 | #include "LED.h" 5 | 6 | #define TIME 500000 7 | 8 | 9 | /** 10 | * @mainpage 11 | * 03_LED: uses the previous GPIO functions specifically for the USER leds. 12 | * this should count in binary on the USER leds, from 0 to 15 13 | **/ 14 | void _main (void) 15 | { 16 | volatile unsigned int ra; 17 | LED_init(); 18 | 19 | unsigned char c = 0; 20 | for(;;) 21 | { 22 | LED_setValue(c++); 23 | for(ra = 0; ra < TIME; ra ++); 24 | } 25 | return; 26 | } 27 | 28 | 29 | 30 | /* 31 | The MIT License (MIT) 32 | 33 | Copyright (c) 2015 Alexis Marquet 34 | 35 | Permission is hereby granted, free of charge, to any person obtaining a copy 36 | of this software and associated documentation files (the "Software"), to deal 37 | in the Software without restriction, including without limitation the rights 38 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | copies of the Software, and to permit persons to whom the Software is 40 | furnished to do so, subject to the following conditions: 41 | 42 | The above copyright notice and this permission notice shall be included in 43 | all copies or substantial portions of the Software. 44 | 45 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 | THE SOFTWARE. 52 | */ -------------------------------------------------------------------------------- /03_LED/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi 3 | CFLAGS=-std=c99 -Wall 4 | OBJ=obj/ 5 | BIN=bin/ 6 | 7 | all: start.objstart main.o GPIO.o pad.o control_module.o clock_module.o LED.o 8 | $(CHAIN)-ld $(OBJ)start.objstart $(OBJ)*.o -T memmap.ld -o $(OBJ)main.elf 9 | $(CHAIN)-objcopy $(OBJ)main.elf $(BIN)spl.boot -O binary 10 | 11 | start.objstart: start.s 12 | $(CHAIN)-as start.s -o $(OBJ)start.objstart 13 | 14 | main.o: main.c 15 | $(CHAIN)-gcc $(CFLAGS) -c main.c -o $(OBJ)main.o 16 | 17 | GPIO.o: GPIO.c 18 | $(CHAIN)-gcc $(CFLAGS) -c GPIO.c -o $(OBJ)GPIO.o 19 | 20 | pad.o: pad.c 21 | $(CHAIN)-gcc $(CFLAGS) -c pad.c -o $(OBJ)pad.o 22 | 23 | control_module.o: control_module.c 24 | $(CHAIN)-gcc $(CFLAGS) -c control_module.c -o $(OBJ)control_module.o 25 | 26 | clock_module.o: clock_module.c 27 | $(CHAIN)-gcc $(CFLAGS) -c clock_module.c -o $(OBJ)clock_module.o 28 | 29 | LED.o: LED.c 30 | $(CHAIN)-gcc $(CFLAGS) -c LED.c -o $(OBJ)LED.o 31 | 32 | copy: 33 | cp $(BIN)spl.boot ../boot 34 | 35 | clean: 36 | rm -rf $(OBJ)*.o 37 | rm -rf $(OBJ)*.objstart 38 | rm -rf $(OBJ)*.elf 39 | rm -rf $(BIN)*.boot 40 | rm -rf ../boot/*.boot 41 | 42 | 43 | dump: 44 | $(CHAIN)-objdump -D $(OBJ)main.elf -------------------------------------------------------------------------------- /03_LED/memmap.ld: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | ram : ORIGIN = 0x402f0400, LENGTH = 0x1B400 4 | } 5 | 6 | SECTIONS 7 | { 8 | .text : { *(.text*) } > ram 9 | .data : { *(.data*) } > ram 10 | .bss : { *(.bss*) } > ram 11 | } 12 | -------------------------------------------------------------------------------- /03_LED/pad.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pad.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation of the pad control functions: TRM 9.3.51, TRM 9.2.2.1 & Datasheet 4 6 | **/ 7 | 8 | #include "pad.h" 9 | #include "control_module.h" 10 | 11 | 12 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 13 | { 14 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 15 | { 16 | unsigned int temp = CM_getCtrlModule(module); 17 | temp &= ~(0b111); // turn down MUXMODE 18 | temp |= mode; // set new MUXMODE 19 | CM_setCtrlModule(module, temp); 20 | } 21 | else 22 | { 23 | // TODO: raise error (control module isnt a "conf " register) 24 | return; 25 | } 26 | } 27 | pinmode_t PAD_getMode(CONTROL_MODULE module) 28 | { 29 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 30 | { 31 | unsigned int temp = CM_getCtrlModule(module); 32 | temp &= ~(0b111); 33 | return (pinmode_t) temp; 34 | } 35 | else 36 | { 37 | // TODO: raise error (control module isnt a "conf " register) 38 | return -1; 39 | } 40 | } 41 | 42 | 43 | 44 | /* 45 | The MIT License (MIT) 46 | 47 | Copyright (c) 2015 Alexis Marquet 48 | 49 | Permission is hereby granted, free of charge, to any person obtaining a copy 50 | of this software and associated documentation files (the "Software"), to deal 51 | in the Software without restriction, including without limitation the rights 52 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 53 | copies of the Software, and to permit persons to whom the Software is 54 | furnished to do so, subject to the following conditions: 55 | 56 | The above copyright notice and this permission notice shall be included in 57 | all copies or substantial portions of the Software. 58 | 59 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 60 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 61 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 62 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 63 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 64 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 65 | THE SOFTWARE. 66 | */ -------------------------------------------------------------------------------- /03_LED/pad.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pad.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Types & prototypes of the pad control functions: TRM 9.3.51, TRM 9.2.2.1 & Datasheet 4 6 | **/ 7 | #ifndef __pad_H 8 | #define __pad_H 9 | #include "control_module.h" 10 | 11 | /** 12 | * @brief MUXMODES for pin pads 13 | **/ 14 | typedef enum 15 | { 16 | MODE_0 = 0, 17 | MODE_1 = 1, 18 | MODE_2 = 2, 19 | MODE_3 = 3, 20 | MODE_4 = 4, 21 | MODE_5 = 5, 22 | MODE_6 = 6, 23 | MODE_7 = 7 24 | 25 | }pinmode_t; 26 | 27 | 28 | /** 29 | * @fn void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 30 | * @brief Set a mode to a control module. 31 | * @param[in] module Module to set the mode to. 32 | * @param[in] mode Mode to set the module to. 33 | * @return void 34 | **/ 35 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode); 36 | 37 | 38 | /** 39 | * @fn pinmode_t PAD_getMode(CONTROL_MODULE module) 40 | * @brief Get the mode of a module. 41 | * @param[in] module Module to get the mode from; 42 | * @return mode of this control module 43 | **/ 44 | pinmode_t PAD_getMode(CONTROL_MODULE module); 45 | 46 | #endif /* defined(__pad_H) */ 47 | 48 | 49 | 50 | 51 | /* 52 | The MIT License (MIT) 53 | 54 | Copyright (c) 2015 Alexis Marquet 55 | 56 | Permission is hereby granted, free of charge, to any person obtaining a copy 57 | of this software and associated documentation files (the "Software"), to deal 58 | in the Software without restriction, including without limitation the rights 59 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 60 | copies of the Software, and to permit persons to whom the Software is 61 | furnished to do so, subject to the following conditions: 62 | 63 | The above copyright notice and this permission notice shall be included in 64 | all copies or substantial portions of the Software. 65 | 66 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 67 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 68 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 69 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 70 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 71 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 72 | THE SOFTWARE. 73 | */ -------------------------------------------------------------------------------- /03_LED/start.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file start.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Prototypes for low level function 6 | **/ 7 | 8 | #ifndef __start_H 9 | #define __start_H 10 | 11 | /** 12 | * @fn void PUT32(unsigned int address, unsigned int value) 13 | * @brief Put a 32bit word at an address. 14 | * @param[in] address Address to put the word to. 15 | * @param[in] value 32bit word to write at the address. 16 | * @return void (always succeed) 17 | **/ 18 | void PUT32(unsigned int address, unsigned int value); 19 | 20 | 21 | /** 22 | * @fn unsigned int GET32 (unsigned int address) 23 | * @brief Get a 32bit word at an address. 24 | * @param[in] address Address to get the word from. 25 | * @return the value read at said address. 26 | **/ 27 | unsigned int GET32 (unsigned int address); 28 | #endif 29 | 30 | 31 | 32 | /* 33 | The MIT License (MIT) 34 | 35 | Copyright (c) 2015 Alexis Marquet 36 | 37 | Permission is hereby granted, free of charge, to any person obtaining a copy 38 | of this software and associated documentation files (the "Software"), to deal 39 | in the Software without restriction, including without limitation the rights 40 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 41 | copies of the Software, and to permit persons to whom the Software is 42 | furnished to do so, subject to the following conditions: 43 | 44 | The above copyright notice and this permission notice shall be included in 45 | all copies or substantial portions of the Software. 46 | 47 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 48 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 49 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 50 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 51 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 52 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 53 | THE SOFTWARE. 54 | */ -------------------------------------------------------------------------------- /03_LED/start.s: -------------------------------------------------------------------------------- 1 | 2 | _start: 3 | mrs r0, cpsr 4 | bic r0, r0, #0x1F @ clear mode bits 5 | orr r0, r0, #0x13 @ set SVC mode 6 | orr r0, r0, #0xC0 @ disable FIQ and IRQ 7 | msr cpsr, r0 8 | 9 | ldr sp, =0x4030CDFC @6kB public stack TMR 26.1.3.2 10 | 11 | bl _main 12 | 13 | 14 | .loop: b .loop 15 | 16 | 17 | .globl PUT32 18 | PUT32: 19 | str r1,[r0] 20 | bx lr 21 | 22 | .globl GET32 23 | GET32: 24 | ldr r0,[r0] 25 | bx lr 26 | 27 | 28 | 29 | 30 | 31 | /* 32 | The MIT License (MIT) 33 | 34 | Copyright (c) 2015 Alexis Marquet 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a copy 37 | of this software and associated documentation files (the "Software"), to deal 38 | in the Software without restriction, including without limitation the rights 39 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 40 | copies of the Software, and to permit persons to whom the Software is 41 | furnished to do so, subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included in 44 | all copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 49 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 52 | THE SOFTWARE. 53 | */ -------------------------------------------------------------------------------- /03_LED/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file types.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Standard types declaration 6 | **/ 7 | 8 | #ifndef __types_H 9 | #define __types_H 10 | 11 | /** 12 | @brief boolean (true/false) 13 | **/ 14 | typedef enum 15 | { 16 | true = 1, 17 | false = 0 18 | }bool; 19 | 20 | #endif 21 | 22 | 23 | 24 | 25 | /* 26 | The MIT License (MIT) 27 | 28 | Copyright (c) 2015 Alexis Marquet 29 | 30 | Permission is hereby granted, free of charge, to any person obtaining a copy 31 | of this software and associated documentation files (the "Software"), to deal 32 | in the Software without restriction, including without limitation the rights 33 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 34 | copies of the Software, and to permit persons to whom the Software is 35 | furnished to do so, subject to the following conditions: 36 | 37 | The above copyright notice and this permission notice shall be included in 38 | all copies or substantial portions of the Software. 39 | 40 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 41 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 42 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 43 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 44 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 45 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 46 | THE SOFTWARE. 47 | */ -------------------------------------------------------------------------------- /04_UART/README.md: -------------------------------------------------------------------------------- 1 | 04_UART 2 | =================== 3 | 4 | This example implements the UART. Thes code structure is setup for easy implementation for all UARTs, 0 trough 5, but this example implements only the UART0 peripheral, wich is the one on J1 connector. The UART will be used for log & debuging purposes. One new thing in this example is that the VFP & NEON coprocessor are enabled (sources from https://github.com/auselen under GNU GPL). See **UART.h** for function prototypes. 5 | This example first prints something and then echoes what it sent to the UART. -------------------------------------------------------------------------------- /04_UART/clock_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file clock_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning clock module usage: TRM 8 6 | **/ 7 | 8 | #include "clock_module.h" 9 | #include "start.h" 10 | #include "types.h" 11 | 12 | 13 | // TODO: implement module/reg validity check 14 | 15 | void CKM_setCLKModuleRegister(CLK_MODULE_t module, CKM_MODULE_REG reg, unsigned int value) 16 | { 17 | unsigned int addr_temp = module + reg; // clock module base + module offset, TRM 2.1 & 8.1.12.1 18 | PUT32(addr_temp, value); 19 | } 20 | unsigned int CKM_getCLKModuleRegister(CLK_MODULE_t module, CKM_MODULE_REG reg) 21 | { 22 | 23 | unsigned int addr_temp = module + reg; // clock module base + module offset, TRM 2.1 & 8.1.12.1 24 | return GET32(addr_temp); 25 | 26 | } 27 | 28 | 29 | 30 | /* 31 | The MIT License (MIT) 32 | 33 | Copyright (c) 2015 Alexis Marquet 34 | 35 | Permission is hereby granted, free of charge, to any person obtaining a copy 36 | of this software and associated documentation files (the "Software"), to deal 37 | in the Software without restriction, including without limitation the rights 38 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | copies of the Software, and to permit persons to whom the Software is 40 | furnished to do so, subject to the following conditions: 41 | 42 | The above copyright notice and this permission notice shall be included in 43 | all copies or substantial portions of the Software. 44 | 45 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 | THE SOFTWARE. 52 | */ 53 | -------------------------------------------------------------------------------- /04_UART/control_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file control_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning control module usage: TRM 9, TRM 9.3 6 | **/ 7 | 8 | #include "control_module.h" 9 | #include "start.h" 10 | 11 | #define CM_MODULE_REGISTER_BASE 0x44E10000 12 | 13 | 14 | void CM_setCtrlModule(CONTROL_MODULE module, unsigned int value) 15 | { 16 | PUT32(CM_MODULE_REGISTER_BASE + module, value); 17 | } 18 | 19 | unsigned int CM_getCtrlModule(CONTROL_MODULE module) 20 | { 21 | return GET32(CM_MODULE_REGISTER_BASE + module); 22 | } 23 | 24 | 25 | 26 | 27 | 28 | /* 29 | The MIT License (MIT) 30 | 31 | Copyright (c) 2015 Alexis Marquet 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy 34 | of this software and associated documentation files (the "Software"), to deal 35 | in the Software without restriction, including without limitation the rights 36 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 37 | copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in 41 | all copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 48 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 49 | THE SOFTWARE. 50 | */ 51 | -------------------------------------------------------------------------------- /04_UART/main.c: -------------------------------------------------------------------------------- 1 | //#include "start.h" 2 | 3 | #include "GPIO.h" 4 | #include "LED.h" 5 | #include "UART.h" 6 | #include "wdt_control.h" 7 | 8 | #define TIME 500000 9 | 10 | 11 | /** 12 | * @mainpage 13 | * 04_UART: implements the UART0 at 115200N8. This example writes "UART0 Initialized..." , 14 | * and the proceeds to repeat everything received. this is polling-only, no interrupt. 15 | **/ 16 | void _main (void) 17 | { 18 | LED_init(); 19 | disable_watchdog_timer(); 20 | 21 | UART_initUART(UART0,115200,STOP1,PARITY_NONE,FLOW_OFF); 22 | UART_putString(UART0,"UART0 Initialized...\n\r",22); 23 | while(1) 24 | { 25 | UART_putC(UART0,UART_getC(UART0)); 26 | } 27 | return; 28 | } 29 | 30 | 31 | 32 | 33 | /* 34 | The MIT License (MIT) 35 | 36 | Copyright (c) 2015 Alexis Marquet 37 | 38 | Permission is hereby granted, free of charge, to any person obtaining a copy 39 | of this software and associated documentation files (the "Software"), to deal 40 | in the Software without restriction, including without limitation the rights 41 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 42 | copies of the Software, and to permit persons to whom the Software is 43 | furnished to do so, subject to the following conditions: 44 | 45 | The above copyright notice and this permission notice shall be included in 46 | all copies or substantial portions of the Software. 47 | 48 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 49 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 50 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 51 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 52 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 53 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 54 | THE SOFTWARE. 55 | */ 56 | -------------------------------------------------------------------------------- /04_UART/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | BIN=bin/ 7 | 8 | all: start.o1 main.o GPIO.o pad.o control_module.o clock_module.o LED.o UART.o wdt_control.o 9 | $(CHAIN)-ld -T memmap.ld $(OBJ)start.o1 $(OBJ)*.o -o $(OBJ)main.elf 10 | $(CHAIN)-objcopy $(OBJ)main.elf $(BIN)spl.boot -O binary 11 | 12 | start.o1: start.s 13 | $(CHAIN)-as $(AFLAGS) start.s -o $(OBJ)start.o1 14 | 15 | main.o: main.c 16 | $(CHAIN)-gcc $(CFLAGS) -c main.c -o $(OBJ)main.o 17 | 18 | GPIO.o: GPIO.c 19 | $(CHAIN)-gcc $(CFLAGS) -c GPIO.c -o $(OBJ)GPIO.o 20 | 21 | pad.o: pad.c 22 | $(CHAIN)-gcc $(CFLAGS) -c pad.c -o $(OBJ)pad.o 23 | 24 | control_module.o: control_module.c 25 | $(CHAIN)-gcc $(CFLAGS) -c control_module.c -o $(OBJ)control_module.o 26 | 27 | clock_module.o: clock_module.c 28 | $(CHAIN)-gcc $(CFLAGS) -c clock_module.c -o $(OBJ)clock_module.o 29 | 30 | LED.o: LED.c 31 | $(CHAIN)-gcc $(CFLAGS) -c LED.c -o $(OBJ)LED.o 32 | 33 | UART.o:UART.c 34 | $(CHAIN)-gcc $(CFLAGS) -c UART.c -o $(OBJ)UART.o 35 | 36 | wdt_control.o:wdt_control.c 37 | $(CHAIN)-gcc $(CFLAGS) -c wdt_control.c -o $(OBJ)wdt_control.o 38 | 39 | copy: 40 | cp $(BIN)spl.boot ../boot 41 | 42 | clean: 43 | rm -rf $(OBJ)*.o 44 | rm -rf $(OBJ)*.objstart 45 | rm -rf $(OBJ)*.elf 46 | rm -rf $(BIN)*.boot 47 | rm -rf ../boot/*.boot 48 | 49 | 50 | dump: 51 | $(CHAIN)-objdump -D $(OBJ)main.elf -------------------------------------------------------------------------------- /04_UART/memmap.ld: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | ram : ORIGIN = 0x402f0400, LENGTH = 0x1B400 4 | } 5 | 6 | SECTIONS 7 | { 8 | .text : { *(.text*) } > ram 9 | .data : { *(.data*) } > ram 10 | .bss : { *(.bss*) } > ram 11 | } 12 | -------------------------------------------------------------------------------- /04_UART/pad.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pad.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation of the pad control functions: TRM 9.3.51, TRM 9.2.2.1 & Datasheet 4 6 | **/ 7 | 8 | #include "pad.h" 9 | #include "control_module.h" 10 | 11 | 12 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 13 | { 14 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 15 | { 16 | unsigned int temp = CM_getCtrlModule(module); 17 | temp &= ~(0b111); // turn down MUXMODE 18 | temp |= mode; // set new MUXMODE 19 | CM_setCtrlModule(module, temp); 20 | } 21 | else 22 | { 23 | // TODO: raise error (control module isnt a "conf " register) 24 | return; 25 | } 26 | } 27 | pinmode_t PAD_getMode(CONTROL_MODULE module) 28 | { 29 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 30 | { 31 | unsigned int temp = CM_getCtrlModule(module); 32 | temp &= ~(0b111); 33 | return (pinmode_t) temp; 34 | } 35 | else 36 | { 37 | // TODO: raise error (control module isnt a "conf " register) 38 | return -1; 39 | } 40 | } 41 | 42 | 43 | 44 | /* 45 | The MIT License (MIT) 46 | 47 | Copyright (c) 2015 Alexis Marquet 48 | 49 | Permission is hereby granted, free of charge, to any person obtaining a copy 50 | of this software and associated documentation files (the "Software"), to deal 51 | in the Software without restriction, including without limitation the rights 52 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 53 | copies of the Software, and to permit persons to whom the Software is 54 | furnished to do so, subject to the following conditions: 55 | 56 | The above copyright notice and this permission notice shall be included in 57 | all copies or substantial portions of the Software. 58 | 59 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 60 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 61 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 62 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 63 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 64 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 65 | THE SOFTWARE. 66 | */ 67 | -------------------------------------------------------------------------------- /04_UART/pad.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pad.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Types & prototypes of the pad control functions: TRM 9.3.51, TRM 9.2.2.1 & Datasheet 4 6 | **/ 7 | #ifndef __pad_H 8 | #define __pad_H 9 | #include "control_module.h" 10 | 11 | /** 12 | * @brief MUXMODES for pin pads 13 | **/ 14 | typedef enum 15 | { 16 | MODE_0 = 0, 17 | MODE_1 = 1, 18 | MODE_2 = 2, 19 | MODE_3 = 3, 20 | MODE_4 = 4, 21 | MODE_5 = 5, 22 | MODE_6 = 6, 23 | MODE_7 = 7 24 | 25 | }pinmode_t; 26 | 27 | 28 | /** 29 | * @fn void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 30 | * @brief Set a mode to a control module. 31 | * @param[in] module Module to set the mode to. 32 | * @param[in] mode Mode to set the module to. 33 | * @return void 34 | **/ 35 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode); 36 | 37 | 38 | /** 39 | * @fn pinmode_t PAD_getMode(CONTROL_MODULE module) 40 | * @brief Get the mode of a module. 41 | * @param[in] module Module to get the mode from; 42 | * @return mode of this control module 43 | **/ 44 | pinmode_t PAD_getMode(CONTROL_MODULE module); 45 | 46 | #endif /* defined(__pad_H) */ 47 | 48 | 49 | 50 | 51 | /* 52 | The MIT License (MIT) 53 | 54 | Copyright (c) 2015 Alexis Marquet 55 | 56 | Permission is hereby granted, free of charge, to any person obtaining a copy 57 | of this software and associated documentation files (the "Software"), to deal 58 | in the Software without restriction, including without limitation the rights 59 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 60 | copies of the Software, and to permit persons to whom the Software is 61 | furnished to do so, subject to the following conditions: 62 | 63 | The above copyright notice and this permission notice shall be included in 64 | all copies or substantial portions of the Software. 65 | 66 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 67 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 68 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 69 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 70 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 71 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 72 | THE SOFTWARE. 73 | */ 74 | -------------------------------------------------------------------------------- /04_UART/start.s: -------------------------------------------------------------------------------- 1 | 2 | .globl _start 3 | _start: 4 | mrs r0, cpsr 5 | bic r0, r0, #0x1F ;@ clear mode bits 6 | orr r0, r0, #0x13 ;@ set SVC mode 7 | orr r0, r0, #0xC0 ;@ disable FIQ and IRQ 8 | msr cpsr, r0 9 | 10 | mrc p15,0,r0,c1,c0,2 ;@ read cp access register 11 | orr r0,r0,#0x00F00000 ;@ enable full access to neon/vfp (coproc 10&11) 12 | mcr p15,0,r0,c1,c0,2 ;@ write cp access register 13 | isb ;@ instruction synchronization barrier 14 | mov r0,#0x40000000 ;@ switch on vfp & neon 15 | vmsr fpexc,r0 ;@ set EN bit in fpexc 16 | 17 | ldr sp, =0x4030CDFC ;@6kB public stack TRM 26.1.3.2 18 | 19 | bl _main 20 | 21 | 22 | .loop: b .loop 23 | 24 | 25 | .globl PUT32 26 | PUT32: 27 | str r1,[r0] 28 | bx lr 29 | 30 | .globl GET32 31 | GET32: 32 | ldr r0,[r0] 33 | bx lr 34 | 35 | .globl PUT16 36 | PUT16: 37 | strh r1,[r0] 38 | bx lr 39 | 40 | .globl GET16 41 | GET16: 42 | ldrh r0,[r0] 43 | bx lr 44 | 45 | .globl PUT8 46 | PUT8: 47 | strb r1,[r0] 48 | bx lr 49 | 50 | .globl GET8 51 | GET8: 52 | ldrb r0,[r0] 53 | bx lr 54 | 55 | 56 | 57 | /* 58 | The MIT License (MIT) 59 | 60 | Copyright (c) 2015 Alexis Marquet 61 | 62 | Permission is hereby granted, free of charge, to any person obtaining a copy 63 | of this software and associated documentation files (the "Software"), to deal 64 | in the Software without restriction, including without limitation the rights 65 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 66 | copies of the Software, and to permit persons to whom the Software is 67 | furnished to do so, subject to the following conditions: 68 | 69 | The above copyright notice and this permission notice shall be included in 70 | all copies or substantial portions of the Software. 71 | 72 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 73 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 74 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 75 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 76 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 77 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 78 | THE SOFTWARE. 79 | */ 80 | -------------------------------------------------------------------------------- /04_UART/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file types.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Standard types declaration 6 | **/ 7 | 8 | #ifndef __types_H 9 | #define __types_H 10 | 11 | /** 12 | @brief boolean (true/false) 13 | **/ 14 | typedef enum 15 | { 16 | true = 1, 17 | false = 0 18 | }bool; 19 | 20 | #endif 21 | 22 | 23 | 24 | /* 25 | The MIT License (MIT) 26 | 27 | Copyright (c) 2015 Alexis Marquet 28 | 29 | Permission is hereby granted, free of charge, to any person obtaining a copy 30 | of this software and associated documentation files (the "Software"), to deal 31 | in the Software without restriction, including without limitation the rights 32 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 33 | copies of the Software, and to permit persons to whom the Software is 34 | furnished to do so, subject to the following conditions: 35 | 36 | The above copyright notice and this permission notice shall be included in 37 | all copies or substantial portions of the Software. 38 | 39 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 40 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 41 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 42 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 43 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 44 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 45 | THE SOFTWARE. 46 | */ 47 | -------------------------------------------------------------------------------- /04_UART/wdt_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wdt_control.c - Watchdog Timer control in a baremetal application for BeagleBone Black 3 | * 4 | * Description: 5 | * This program demonstrates how to access and control the Watchdog Timer (WDT) in a baremetal 6 | * application for the BeagleBone Black. It provides a function to clear the WDT_WTGR (Watchdog Timer 7 | * Global Register), preventing the watchdog from resetting the system. 8 | * 9 | * License: 10 | * MIT License 11 | * 12 | * Copyright (c) 2024 Jesus Humberto Ontiveros Mayorquin 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in all 22 | * copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 | * SOFTWARE. 31 | */ 32 | #include 33 | 34 | // Watchdog Timer Global Register (WDT_WTGR) address for BeagleBone Black 35 | #define WDT_WTGR_REG_ADDR 0x44E35030 36 | #define WDT_WSPR_ADDR 0x44E35048 37 | #define WDT_WWPS_ADDR 0x44E35034 38 | 39 | #define XXXX_AAAA 0x0000AAAA 40 | #define XXXX_5555 0x00005555 41 | #define XXXX_BBBB 0x0000BBBB 42 | #define XXXX_4444 0x00004444 43 | #define W_PEND_WSPR 0X00000010// Bit 4 in WDT_WWPS register 44 | 45 | //Funtion to disable the Watchdog Timer 46 | void disable_watchdog_timer(); 47 | 48 | //Funtion to enable the Watchdog Timer 49 | void enable_watchdog_timer(); -------------------------------------------------------------------------------- /05_low_level_init/README.md: -------------------------------------------------------------------------------- 1 | 05_low_level_init 2 | =================== 3 | 4 | This example has a completely different structure than the previous. I separated what is core specific, what is SoC specific (the peripherals), what is board specific, ans so on... this way i was able to make things modular and tidy (kind of). this example sets the interrupt vector table (still in on chip ram), clears the .bss, inits the core, inits the UART, NVIC, Leds, and finaly in the main() it launches the RTC to have an interupt every second. 5 | 6 | each time an interrupt is asserted, PC goes into the ROM vector table (0x20000 something), jump to the vector table at 0x4030CE00, which then send it to IRQ_Handler. there, the context is saved, and the active irq number is passed as first argument to procIrqHandler, which in turn, choses the right interrupt service routine. note: do not forget to clear the pending flag in the INTC register. 7 | 8 | 9 | I don't think interrupt priority works yet. -------------------------------------------------------------------------------- /05_low_level_init/board/board_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file /board/board_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief board initialisation. every component that is NOT the SoC but is on the board must be init here. 6 | **/ 7 | 8 | #include "LED.h" 9 | 10 | void boardInit() 11 | { 12 | LED_init(); 13 | } 14 | 15 | /* 16 | The MIT License (MIT) 17 | 18 | Copyright (c) 2015 Alexis Marquet 19 | 20 | Permission is hereby granted, free of charge, to any person obtaining a copy 21 | of this software and associated documentation files (the "Software"), to deal 22 | in the Software without restriction, including without limitation the rights 23 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | copies of the Software, and to permit persons to whom the Software is 25 | furnished to do so, subject to the following conditions: 26 | 27 | The above copyright notice and this permission notice shall be included in 28 | all copies or substantial portions of the Software. 29 | 30 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 36 | THE SOFTWARE. 37 | */ 38 | -------------------------------------------------------------------------------- /05_low_level_init/board/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=@/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi- 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 -O0 -ggdb 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | PARENTOBJ=../obj/ 7 | 8 | all: dir $(OBJ)board_init.o $(OBJ)LED.o 9 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)board.o 10 | 11 | dir: 12 | @mkdir -p $(OBJ) 13 | 14 | $(OBJ)LED.o: LED.c 15 | $(CHAIN)gcc $(CFLAGS) -c LED.c -o $(OBJ)LED.o 16 | 17 | $(OBJ)board_init.o: board_init.c 18 | $(CHAIN)gcc $(CFLAGS) -c board_init.c -o $(OBJ)board_init.o 19 | 20 | clean: 21 | rm -rf $(OBJ)*.o 22 | -------------------------------------------------------------------------------- /05_low_level_init/board/obj/LED.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/board/obj/LED.o -------------------------------------------------------------------------------- /05_low_level_init/board/obj/board_init.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/board/obj/board_init.o -------------------------------------------------------------------------------- /05_low_level_init/core/core_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file core_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief this function is the core init function. its the first function do be called from the startup. 6 | * 7 | * @note the bss is already initialized at this point. 8 | **/ 9 | #include "llma.h" 10 | 11 | 12 | void coreInit() 13 | { 14 | CPU_irqD(); // disable interrupt 15 | } 16 | 17 | 18 | 19 | 20 | /* 21 | The MIT License (MIT) 22 | 23 | Copyright (c) 2015 Alexis Marquet 24 | 25 | Permission is hereby granted, free of charge, to any person obtaining a copy 26 | of this software and associated documentation files (the "Software"), to deal 27 | in the Software without restriction, including without limitation the rights 28 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 29 | copies of the Software, and to permit persons to whom the Software is 30 | furnished to do so, subject to the following conditions: 31 | 32 | The above copyright notice and this permission notice shall be included in 33 | all copies or substantial portions of the Software. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 38 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 40 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 41 | THE SOFTWARE. 42 | */ 43 | -------------------------------------------------------------------------------- /05_low_level_init/core/llma.s: -------------------------------------------------------------------------------- 1 | /** 2 | * @file llma.s 3 | * @author Alexis Marquet 4 | * @date 27 Feb 2015 5 | * @brief contains Low Level Memory Access functions 6 | **/ 7 | 8 | 9 | .globl PUT32 10 | PUT32: 11 | str r1,[r0] 12 | bx lr 13 | 14 | .globl GET32 15 | GET32: 16 | ldr r0,[r0] 17 | bx lr 18 | 19 | .globl PUT16 20 | PUT16: 21 | strh r1,[r0] 22 | bx lr 23 | 24 | .globl GET16 25 | GET16: 26 | ldrh r0,[r0] 27 | bx lr 28 | 29 | .globl PUT8 30 | PUT8: 31 | strb r1,[r0] 32 | bx lr 33 | 34 | .globl GET8 35 | GET8: 36 | ldrb r0,[r0] 37 | bx lr 38 | 39 | 40 | .globl CPU_irqE 41 | CPU_irqE: 42 | dsb 43 | mrs r0, cpsr 44 | bic r0, r0, #0x80 45 | msr cpsr_c, r0 46 | DSB 47 | ISB 48 | bx lr 49 | 50 | .globl CPU_irqD 51 | CPU_irqD: 52 | dsb 53 | mrs r0, cpsr 54 | orr r0, r0, #0x80 55 | msr cpsr_c, r0 56 | DSB 57 | ISB 58 | bx lr 59 | 60 | /* 61 | The MIT License (MIT) 62 | 63 | Copyright (c) 2015 Alexis Marquet 64 | 65 | Permission is hereby granted, free of charge, to any person obtaining a copy 66 | of this software and associated documentation files (the "Software"), to deal 67 | in the Software without restriction, including without limitation the rights 68 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 69 | copies of the Software, and to permit persons to whom the Software is 70 | furnished to do so, subject to the following conditions: 71 | 72 | The above copyright notice and this permission notice shall be included in 73 | all copies or substantial portions of the Software. 74 | 75 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 76 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 77 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 78 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 79 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 80 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 81 | THE SOFTWARE. 82 | */ 83 | -------------------------------------------------------------------------------- /05_low_level_init/core/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=@/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi- 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 -O0 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | PARENTOBJ=../obj/ 7 | 8 | all: dir $(OBJ)startup_ARMCA8.o1 $(OBJ)core_handlers.o $(OBJ)llma.o $(OBJ)core_init.o 9 | $(CHAIN)ld -r $(OBJ)startup_ARMCA8.o1 $(OBJ)*.o -o $(PARENTOBJ)core.o 10 | 11 | 12 | 13 | dir: 14 | @mkdir -p $(OBJ) 15 | 16 | $(OBJ)startup_ARMCA8.o1: startup_ARMCA8.s 17 | $(CHAIN)as $(AFLAGS) -c startup_ARMCA8.s -o $(OBJ)startup_ARMCA8.o1 18 | 19 | $(OBJ)core_init.o: core_init.c 20 | $(CHAIN)gcc $(CFLAGS) -c core_init.c -o $(OBJ)core_init.o 21 | 22 | $(OBJ)core_handlers.o: core_handlers.s 23 | $(CHAIN)as $(AFLAGS) -c core_handlers.s -o $(OBJ)core_handlers.o 24 | 25 | $(OBJ)llma.o: llma.s 26 | $(CHAIN)as $(AFLAGS) -c llma.s -o $(OBJ)llma.o 27 | 28 | 29 | 30 | clean: 31 | rm -rf $(OBJ)*.o 32 | 33 | -------------------------------------------------------------------------------- /05_low_level_init/core/obj/core_handlers.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/core/obj/core_handlers.o -------------------------------------------------------------------------------- /05_low_level_init/core/obj/core_init.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/core/obj/core_init.o -------------------------------------------------------------------------------- /05_low_level_init/core/obj/llma.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/core/obj/llma.o -------------------------------------------------------------------------------- /05_low_level_init/core/obj/startup.o1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/core/obj/startup.o1 -------------------------------------------------------------------------------- /05_low_level_init/core/obj/startup_ARMCA8.o1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/core/obj/startup_ARMCA8.o1 -------------------------------------------------------------------------------- /05_low_level_init/kernel/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=@/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi- 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 -O0 -ggdb 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | PARENTOBJ=../obj/ 7 | 8 | all: dir $(OBJ)main.o 9 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)kernel.o 10 | 11 | dir: 12 | @mkdir -p $(OBJ) 13 | 14 | $(OBJ)main.o: main.c 15 | $(CHAIN)gcc $(CFLAGS) -c main.c -o $(OBJ)main.o 16 | 17 | clean: 18 | rm -rf $(OBJ)*.o 19 | -------------------------------------------------------------------------------- /05_low_level_init/kernel/obj/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/kernel/obj/main.o -------------------------------------------------------------------------------- /05_low_level_init/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=@/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi- 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 -O0 -ggdb 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | BIN=bin/ 7 | 8 | 9 | 10 | all: dir $(OBJ)core.o $(OBJ)proc.o $(OBJ)board.o $(OBJ)sys.o $(OBJ)kernel.o 11 | @echo "assembling output file..." 12 | $(CHAIN)ld -T memmap.ld $(OBJ)core.o $(OBJ)proc.o $(OBJ)board.o $(OBJ)sys.o $(OBJ)kernel.o -o $(OBJ)main.elf 13 | $(CHAIN)objcopy $(OBJ)main.elf $(BIN)spl.boot -O binary 14 | @echo "done!" 15 | 16 | dir: 17 | @mkdir -p $(OBJ) $(BIN) 18 | 19 | $(OBJ)core.o: force_look 20 | @echo "building core/" 21 | @cd core/ ; $(MAKE) $(MFLAGS) 22 | 23 | $(OBJ)proc.o: force_look 24 | @echo "building proc/" 25 | @cd proc/ ; $(MAKE) $(MFLAGS) 26 | 27 | $(OBJ)board.o: force_look 28 | @echo "building board/" 29 | @cd board/ ; $(MAKE) $(MFLAGS) 30 | 31 | $(OBJ)sys.o: force_look 32 | @echo "building sys/" 33 | @cd sys/ ; $(MAKE) $(MFLAGS) 34 | 35 | $(OBJ)kernel.o: force_look 36 | @echo "building kernel/" 37 | @cd kernel/ ; $(MAKE) $(MFLAGS) 38 | 39 | force_look: 40 | @true 41 | 42 | copy: 43 | @echo "copying boot file..." 44 | @cp $(BIN)spl.boot ../boot 45 | @echo "done" 46 | 47 | clean: 48 | @echo "cleaning up..." 49 | @rm -rf $(OBJ)*.o 50 | @rm -rf $(OBJ)*.elf 51 | @rm -rf $(BIN)*.boot 52 | @rm -rf ../boot/*.boot 53 | @rm -rf core/obj/*.o 54 | @rm -rf proc/obj/*.o 55 | @rm -rf board/obj/*.o 56 | @rm -rf sys/obj/*.o 57 | @rm -rf kernel/obj/*.o 58 | @echo "done!" 59 | 60 | dump: 61 | $(CHAIN)objdump -D $(OBJ)main.elf -------------------------------------------------------------------------------- /05_low_level_init/proc/clock_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file clock_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning clock module usage: TRM 8 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "../sys/types.h" 10 | #include "clock_module.h" 11 | 12 | 13 | // TODO: implement module/reg validity check 14 | 15 | void CKM_setCLKModuleRegister(CLK_MODULE_t module, CKM_MODULE_REG reg, unsigned int value) 16 | { 17 | unsigned int addr_temp = module + reg; // clock module base + module offset, TRM 2.1 & 8.1.12.1 18 | PUT32(addr_temp, value); 19 | } 20 | unsigned int CKM_getCLKModuleRegister(CLK_MODULE_t module, CKM_MODULE_REG reg) 21 | { 22 | 23 | unsigned int addr_temp = module + reg; // clock module base + module offset, TRM 2.1 & 8.1.12.1 24 | return GET32(addr_temp); 25 | 26 | } 27 | 28 | 29 | 30 | /* 31 | The MIT License (MIT) 32 | 33 | Copyright (c) 2015 Alexis Marquet 34 | 35 | Permission is hereby granted, free of charge, to any person obtaining a copy 36 | of this software and associated documentation files (the "Software"), to deal 37 | in the Software without restriction, including without limitation the rights 38 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | copies of the Software, and to permit persons to whom the Software is 40 | furnished to do so, subject to the following conditions: 41 | 42 | The above copyright notice and this permission notice shall be included in 43 | all copies or substantial portions of the Software. 44 | 45 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 | THE SOFTWARE. 52 | */ 53 | -------------------------------------------------------------------------------- /05_low_level_init/proc/control_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file control_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning control module usage: TRM 9, TRM 9.3 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "control_module.h" 10 | 11 | #define CM_MODULE_REGISTER_BASE 0x44E10000 12 | 13 | 14 | void CM_setCtrlModule(CONTROL_MODULE module, unsigned int value) 15 | { 16 | PUT32(CM_MODULE_REGISTER_BASE + module, value); 17 | } 18 | 19 | unsigned int CM_getCtrlModule(CONTROL_MODULE module) 20 | { 21 | return GET32(CM_MODULE_REGISTER_BASE + module); 22 | } 23 | 24 | 25 | 26 | 27 | 28 | /* 29 | The MIT License (MIT) 30 | 31 | Copyright (c) 2015 Alexis Marquet 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy 34 | of this software and associated documentation files (the "Software"), to deal 35 | in the Software without restriction, including without limitation the rights 36 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 37 | copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in 41 | all copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 48 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 49 | THE SOFTWARE. 50 | */ 51 | -------------------------------------------------------------------------------- /05_low_level_init/proc/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=@/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi- 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 -O0 -ggdb 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | PARENTOBJ=../obj/ 7 | 8 | all: dir $(OBJ)proc_init.o $(OBJ)UART.o $(OBJ)GPIO.o $(OBJ)control_module.o $(OBJ)clock_module.o $(OBJ)pad.o $(OBJ)proc_Handlers.o 9 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)proc.o 10 | 11 | dir: 12 | @mkdir -p $(OBJ) 13 | 14 | $(OBJ)proc_init.o: proc_init.c 15 | $(CHAIN)gcc $(CFLAGS) -c proc_init.c -o $(OBJ)proc_init.o 16 | 17 | $(OBJ)proc_Handlers.o: proc_Handlers.c 18 | $(CHAIN)gcc $(CFLAGS) -c proc_Handlers.c -o $(OBJ)proc_Handlers.o 19 | 20 | $(OBJ)GPIO.o: GPIO.c 21 | $(CHAIN)gcc $(CFLAGS) -c GPIO.c -o $(OBJ)GPIO.o 22 | 23 | $(OBJ)pad.o: pad.c 24 | $(CHAIN)gcc $(CFLAGS) -c pad.c -o $(OBJ)pad.o 25 | 26 | $(OBJ)control_module.o: control_module.c 27 | $(CHAIN)gcc $(CFLAGS) -c control_module.c -o $(OBJ)control_module.o 28 | 29 | $(OBJ)clock_module.o: clock_module.c 30 | $(CHAIN)gcc $(CFLAGS) -c clock_module.c -o $(OBJ)clock_module.o 31 | 32 | $(OBJ)UART.o:UART.c 33 | $(CHAIN)gcc $(CFLAGS) -c UART.c -o $(OBJ)UART.o 34 | 35 | clean: 36 | rm -rf $(OBJ)*.o 37 | -------------------------------------------------------------------------------- /05_low_level_init/proc/obj/GPIO.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/proc/obj/GPIO.o -------------------------------------------------------------------------------- /05_low_level_init/proc/obj/UART.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/proc/obj/UART.o -------------------------------------------------------------------------------- /05_low_level_init/proc/obj/clock_module.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/proc/obj/clock_module.o -------------------------------------------------------------------------------- /05_low_level_init/proc/obj/control_module.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/proc/obj/control_module.o -------------------------------------------------------------------------------- /05_low_level_init/proc/obj/pad.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/proc/obj/pad.o -------------------------------------------------------------------------------- /05_low_level_init/proc/obj/proc_Handlers.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/proc/obj/proc_Handlers.o -------------------------------------------------------------------------------- /05_low_level_init/proc/obj/proc_init.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/proc/obj/proc_init.o -------------------------------------------------------------------------------- /05_low_level_init/proc/pad.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pad.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation of the pad control functions: TRM 9.3.51, TRM 9.2.2.1 & Datasheet 4 6 | **/ 7 | 8 | #include "pad.h" 9 | #include "control_module.h" 10 | 11 | 12 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 13 | { 14 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 15 | { 16 | unsigned int temp = CM_getCtrlModule(module); 17 | temp &= ~(0b111); // turn down MUXMODE 18 | temp |= mode; // set new MUXMODE 19 | CM_setCtrlModule(module, temp); 20 | } 21 | else 22 | { 23 | // TODO: raise error (control module isnt a "conf " register) 24 | return; 25 | } 26 | } 27 | pinmode_t PAD_getMode(CONTROL_MODULE module) 28 | { 29 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 30 | { 31 | unsigned int temp = CM_getCtrlModule(module); 32 | temp &= ~(0b111); 33 | return (pinmode_t) temp; 34 | } 35 | else 36 | { 37 | // TODO: raise error (control module isnt a "conf " register) 38 | return -1; 39 | } 40 | } 41 | 42 | 43 | 44 | /* 45 | The MIT License (MIT) 46 | 47 | Copyright (c) 2015 Alexis Marquet 48 | 49 | Permission is hereby granted, free of charge, to any person obtaining a copy 50 | of this software and associated documentation files (the "Software"), to deal 51 | in the Software without restriction, including without limitation the rights 52 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 53 | copies of the Software, and to permit persons to whom the Software is 54 | furnished to do so, subject to the following conditions: 55 | 56 | The above copyright notice and this permission notice shall be included in 57 | all copies or substantial portions of the Software. 58 | 59 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 60 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 61 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 62 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 63 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 64 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 65 | THE SOFTWARE. 66 | */ 67 | -------------------------------------------------------------------------------- /05_low_level_init/proc/pad.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pad.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Types & prototypes of the pad control functions: TRM 9.3.51, TRM 9.2.2.1 & Datasheet 4 6 | **/ 7 | #ifndef __pad_H 8 | #define __pad_H 9 | #include "control_module.h" 10 | 11 | /** 12 | * @brief MUXMODES for pin pads 13 | **/ 14 | typedef enum 15 | { 16 | MODE_0 = 0, 17 | MODE_1 = 1, 18 | MODE_2 = 2, 19 | MODE_3 = 3, 20 | MODE_4 = 4, 21 | MODE_5 = 5, 22 | MODE_6 = 6, 23 | MODE_7 = 7 24 | 25 | }pinmode_t; 26 | 27 | 28 | /** 29 | * @fn void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 30 | * @brief Set a mode to a control module. 31 | * @param[in] module Module to set the mode to. 32 | * @param[in] mode Mode to set the module to. 33 | * @return void 34 | **/ 35 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode); 36 | 37 | 38 | /** 39 | * @fn pinmode_t PAD_getMode(CONTROL_MODULE module) 40 | * @brief Get the mode of a module. 41 | * @param[in] module Module to get the mode from; 42 | * @return mode of this control module 43 | **/ 44 | pinmode_t PAD_getMode(CONTROL_MODULE module); 45 | 46 | #endif /* defined(__pad_H) */ 47 | 48 | 49 | 50 | 51 | /* 52 | The MIT License (MIT) 53 | 54 | Copyright (c) 2015 Alexis Marquet 55 | 56 | Permission is hereby granted, free of charge, to any person obtaining a copy 57 | of this software and associated documentation files (the "Software"), to deal 58 | in the Software without restriction, including without limitation the rights 59 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 60 | copies of the Software, and to permit persons to whom the Software is 61 | furnished to do so, subject to the following conditions: 62 | 63 | The above copyright notice and this permission notice shall be included in 64 | all copies or substantial portions of the Software. 65 | 66 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 67 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 68 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 69 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 70 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 71 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 72 | THE SOFTWARE. 73 | */ 74 | -------------------------------------------------------------------------------- /05_low_level_init/proc/proc_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file proc_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief Initialize the processor and its needed peripherals 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "../proc/UART.h" 10 | 11 | #define NVIC 0x48200000 12 | #define CM_WKUP 0x44E00400 13 | void procInit() 14 | { 15 | 16 | /* peripherals */ 17 | PUT32(0x47400000+0x10,1); // reset USB controller to get the internet connection back 18 | 19 | PUT32(NVIC+0x10,1); // reset INTC controller 20 | while((GET32(NVIC+0x14)&0x1)==0); // wait until reset is done 21 | 22 | PUT32(NVIC+0x68,0xFF); // disable interrupt threshold 23 | PUT32(NVIC+0x50,1); // enable functional clock 24 | 25 | PUT32(NVIC+0x94,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 26 | PUT32(NVIC+0xB4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 27 | PUT32(NVIC+0xD4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 28 | PUT32(NVIC+0xF4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 29 | 30 | CPU_irqE(); 31 | 32 | UART_initUART(UART0,115200,STOP1,PARITY_NONE,FLOW_OFF); 33 | 34 | UART_putString(UART0,"UART0 Initialized... compiled at " __TIME__ "\n",42); 35 | 36 | 37 | } -------------------------------------------------------------------------------- /05_low_level_init/sys/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=@/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi- 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 -O0 -ggdb 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | PARENTOBJ=../obj/ 7 | 8 | all: dir $(OBJ)types.o 9 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)sys.o 10 | 11 | dir: 12 | @mkdir -p $(OBJ) 13 | 14 | $(OBJ)types.o: types.c 15 | $(CHAIN)gcc $(CFLAGS) -c types.c -o $(OBJ)types.o 16 | 17 | clean: 18 | rm -rf $(OBJ)*.o 19 | -------------------------------------------------------------------------------- /05_low_level_init/sys/obj/types.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/05_low_level_init/sys/obj/types.o -------------------------------------------------------------------------------- /05_low_level_init/sys/types.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file types.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief Dummy file for consistency with hierarchy 6 | **/ 7 | 8 | void types (void) 9 | { 10 | 11 | } -------------------------------------------------------------------------------- /05_low_level_init/sys/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file types.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Standard types declaration 6 | **/ 7 | 8 | #ifndef __types_H 9 | #define __types_H 10 | 11 | /** 12 | @brief boolean (true/false) 13 | **/ 14 | typedef enum 15 | { 16 | true = 1, 17 | false = 0 18 | }bool; 19 | 20 | #endif 21 | 22 | 23 | 24 | /* 25 | The MIT License (MIT) 26 | 27 | Copyright (c) 2015 Alexis Marquet 28 | 29 | Permission is hereby granted, free of charge, to any person obtaining a copy 30 | of this software and associated documentation files (the "Software"), to deal 31 | in the Software without restriction, including without limitation the rights 32 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 33 | copies of the Software, and to permit persons to whom the Software is 34 | furnished to do so, subject to the following conditions: 35 | 36 | The above copyright notice and this permission notice shall be included in 37 | all copies or substantial portions of the Software. 38 | 39 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 40 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 41 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 42 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 43 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 44 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 45 | THE SOFTWARE. 46 | */ 47 | -------------------------------------------------------------------------------- /06_stdlib/README.md: -------------------------------------------------------------------------------- 1 | 06_stdlib 2 | =============== 3 | 4 | This example links with stdlib. it prints a few value with their string representation to check if everithing works, and then launches the RTC for 15 interrupts 5 | -------------------------------------------------------------------------------- /06_stdlib/board/board_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file /board/board_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief board initialisation. every component that is NOT the SoC but is on the board must be init here. 6 | **/ 7 | 8 | #include "LED.h" 9 | 10 | void boardInit() 11 | { 12 | LED_init(); 13 | } 14 | 15 | /* 16 | The MIT License (MIT) 17 | 18 | Copyright (c) 2015 Alexis Marquet 19 | 20 | Permission is hereby granted, free of charge, to any person obtaining a copy 21 | of this software and associated documentation files (the "Software"), to deal 22 | in the Software without restriction, including without limitation the rights 23 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | copies of the Software, and to permit persons to whom the Software is 25 | furnished to do so, subject to the following conditions: 26 | 27 | The above copyright notice and this permission notice shall be included in 28 | all copies or substantial portions of the Software. 29 | 30 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 36 | THE SOFTWARE. 37 | */ 38 | -------------------------------------------------------------------------------- /06_stdlib/board/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=@/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi- 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 -O0 -ggdb 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | PARENTOBJ=../obj/ 7 | 8 | all: dir $(OBJ)board_init.o $(OBJ)LED.o 9 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)board.o 10 | 11 | dir: 12 | @mkdir -p $(OBJ) 13 | 14 | $(OBJ)LED.o: LED.c 15 | $(CHAIN)gcc $(CFLAGS) -c LED.c -o $(OBJ)LED.o 16 | 17 | $(OBJ)board_init.o: board_init.c 18 | $(CHAIN)gcc $(CFLAGS) -c board_init.c -o $(OBJ)board_init.o 19 | 20 | clean: 21 | rm -rf $(OBJ)*.o 22 | -------------------------------------------------------------------------------- /06_stdlib/board/obj/LED.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/board/obj/LED.o -------------------------------------------------------------------------------- /06_stdlib/board/obj/board_init.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/board/obj/board_init.o -------------------------------------------------------------------------------- /06_stdlib/core/core_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file core_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief this function is the core init function. its the first function do be called from the startup. 6 | * 7 | * @note the bss is already initialized at this point. 8 | **/ 9 | #include "llma.h" 10 | 11 | 12 | void coreInit() 13 | { 14 | CPU_irqD(); // disable interrupt 15 | } 16 | 17 | 18 | 19 | 20 | /* 21 | The MIT License (MIT) 22 | 23 | Copyright (c) 2015 Alexis Marquet 24 | 25 | Permission is hereby granted, free of charge, to any person obtaining a copy 26 | of this software and associated documentation files (the "Software"), to deal 27 | in the Software without restriction, including without limitation the rights 28 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 29 | copies of the Software, and to permit persons to whom the Software is 30 | furnished to do so, subject to the following conditions: 31 | 32 | The above copyright notice and this permission notice shall be included in 33 | all copies or substantial portions of the Software. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 38 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 40 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 41 | THE SOFTWARE. 42 | */ 43 | -------------------------------------------------------------------------------- /06_stdlib/core/llma.s: -------------------------------------------------------------------------------- 1 | /** 2 | * @file llma.s 3 | * @author Alexis Marquet 4 | * @date 27 Feb 2015 5 | * @brief contains Low Level Memory Access functions 6 | **/ 7 | 8 | 9 | .globl PUT32 10 | PUT32: 11 | str r1,[r0] 12 | bx lr 13 | 14 | .globl GET32 15 | GET32: 16 | ldr r0,[r0] 17 | bx lr 18 | 19 | .globl PUT16 20 | PUT16: 21 | strh r1,[r0] 22 | bx lr 23 | 24 | .globl GET16 25 | GET16: 26 | ldrh r0,[r0] 27 | bx lr 28 | 29 | .globl PUT8 30 | PUT8: 31 | strb r1,[r0] 32 | bx lr 33 | 34 | .globl GET8 35 | GET8: 36 | ldrb r0,[r0] 37 | bx lr 38 | 39 | 40 | .globl CPU_irqE 41 | CPU_irqE: 42 | dsb 43 | mrs r0, cpsr 44 | bic r0, r0, #0x80 45 | msr cpsr_c, r0 46 | DSB 47 | ISB 48 | bx lr 49 | 50 | .globl CPU_irqD 51 | CPU_irqD: 52 | dsb 53 | mrs r0, cpsr 54 | orr r0, r0, #0x80 55 | msr cpsr_c, r0 56 | DSB 57 | ISB 58 | bx lr 59 | 60 | /* 61 | The MIT License (MIT) 62 | 63 | Copyright (c) 2015 Alexis Marquet 64 | 65 | Permission is hereby granted, free of charge, to any person obtaining a copy 66 | of this software and associated documentation files (the "Software"), to deal 67 | in the Software without restriction, including without limitation the rights 68 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 69 | copies of the Software, and to permit persons to whom the Software is 70 | furnished to do so, subject to the following conditions: 71 | 72 | The above copyright notice and this permission notice shall be included in 73 | all copies or substantial portions of the Software. 74 | 75 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 76 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 77 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 78 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 79 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 80 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 81 | THE SOFTWARE. 82 | */ 83 | -------------------------------------------------------------------------------- /06_stdlib/core/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=@/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi- 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 -O0 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | PARENTOBJ=../obj/ 7 | 8 | all: dir $(OBJ)startup_ARMCA8.o1 $(OBJ)core_handlers.o $(OBJ)llma.o $(OBJ)core_init.o $(OBJ)__aeabi.o 9 | $(CHAIN)ld -r $(OBJ)startup_ARMCA8.o1 $(OBJ)*.o -o $(PARENTOBJ)core.o 10 | 11 | 12 | 13 | dir: 14 | @mkdir -p $(OBJ) 15 | 16 | $(OBJ)startup_ARMCA8.o1: startup_ARMCA8.s 17 | $(CHAIN)as $(AFLAGS) -c startup_ARMCA8.s -o $(OBJ)startup_ARMCA8.o1 18 | 19 | $(OBJ)core_init.o: core_init.c 20 | $(CHAIN)gcc $(CFLAGS) -c core_init.c -o $(OBJ)core_init.o 21 | 22 | $(OBJ)core_handlers.o: core_handlers.s 23 | $(CHAIN)as $(AFLAGS) -c core_handlers.s -o $(OBJ)core_handlers.o 24 | 25 | $(OBJ)llma.o: llma.s 26 | $(CHAIN)as $(AFLAGS) -c llma.s -o $(OBJ)llma.o 27 | 28 | $(OBJ)__aeabi.o: __aeabi.s 29 | $(CHAIN)as $(AFLAGS) -c __aeabi.s -o $(OBJ)__aeabi.o 30 | 31 | 32 | 33 | 34 | clean: 35 | rm -rf $(OBJ)*.o 36 | 37 | -------------------------------------------------------------------------------- /06_stdlib/core/obj/__aeabi.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/core/obj/__aeabi.o -------------------------------------------------------------------------------- /06_stdlib/core/obj/core_handlers.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/core/obj/core_handlers.o -------------------------------------------------------------------------------- /06_stdlib/core/obj/core_init.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/core/obj/core_init.o -------------------------------------------------------------------------------- /06_stdlib/core/obj/llma.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/core/obj/llma.o -------------------------------------------------------------------------------- /06_stdlib/core/obj/startup.o1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/core/obj/startup.o1 -------------------------------------------------------------------------------- /06_stdlib/core/obj/startup_ARMCA8.o1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/core/obj/startup_ARMCA8.o1 -------------------------------------------------------------------------------- /06_stdlib/kernel/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=@/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi- 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 -O0 -ggdb 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | PARENTOBJ=../obj/ 7 | 8 | all: dir $(OBJ)main.o 9 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)kernel.o 10 | 11 | dir: 12 | @mkdir -p $(OBJ) 13 | 14 | $(OBJ)main.o: main.c 15 | $(CHAIN)gcc $(CFLAGS) -c main.c -o $(OBJ)main.o 16 | 17 | clean: 18 | rm -rf $(OBJ)*.o 19 | -------------------------------------------------------------------------------- /06_stdlib/kernel/obj/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/kernel/obj/main.o -------------------------------------------------------------------------------- /06_stdlib/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi- 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 -O0 -ggdb 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | BIN=bin/ 7 | LIBPATH=/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/arm-none-eabi/lib/fpu/ 8 | 9 | 10 | all: dir $(OBJ)core.o $(OBJ)proc.o $(OBJ)board.o $(OBJ)sys.o $(OBJ)kernel.o 11 | @echo "assembling output file..." 12 | $(CHAIN)ld -T memmap.ld $(OBJ)core.o $(OBJ)proc.o $(OBJ)board.o $(OBJ)sys.o $(OBJ)kernel.o -L $(LIBPATH) -l"c" -l"m" -o $(OBJ)main.elf 13 | $(CHAIN)objcopy $(OBJ)main.elf $(BIN)spl.boot -O binary 14 | @echo "done!" 15 | 16 | dir: 17 | @mkdir -p $(OBJ) $(BIN) 18 | 19 | $(OBJ)core.o: force_look 20 | @echo "building core/" 21 | @cd core/ ; $(MAKE) $(MFLAGS) 22 | 23 | $(OBJ)proc.o: force_look 24 | @echo "building proc/" 25 | @cd proc/ ; $(MAKE) $(MFLAGS) 26 | 27 | $(OBJ)board.o: force_look 28 | @echo "building board/" 29 | @cd board/ ; $(MAKE) $(MFLAGS) 30 | 31 | $(OBJ)sys.o: force_look 32 | @echo "building sys/" 33 | @cd sys/ ; $(MAKE) $(MFLAGS) 34 | 35 | $(OBJ)kernel.o: force_look 36 | @echo "building kernel/" 37 | @cd kernel/ ; $(MAKE) $(MFLAGS) 38 | 39 | force_look: 40 | @true 41 | 42 | copy: 43 | @echo "copying boot file..." 44 | @cp $(BIN)spl.boot ../boot 45 | @echo "done" 46 | 47 | clean: 48 | @echo "cleaning up..." 49 | @rm -rf $(OBJ)*.o 50 | @rm -rf $(OBJ)*.elf 51 | @rm -rf $(BIN)*.boot 52 | @rm -rf ../boot/*.boot 53 | @rm -rf core/obj/*.o 54 | @rm -rf proc/obj/*.o 55 | @rm -rf board/obj/*.o 56 | @rm -rf sys/obj/*.o 57 | @rm -rf kernel/obj/*.o 58 | @echo "done!" 59 | 60 | dump: 61 | $(CHAIN)objdump -D $(OBJ)main.elf -------------------------------------------------------------------------------- /06_stdlib/proc/clock_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file clock_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning clock module usage: TRM 8 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "../sys/types.h" 10 | #include "clock_module.h" 11 | 12 | 13 | // TODO: implement module/reg validity check 14 | 15 | void CKM_setCLKModuleRegister(CLK_MODULE_t module, CKM_MODULE_REG reg, unsigned int value) 16 | { 17 | unsigned int addr_temp = module + reg; // clock module base + module offset, TRM 2.1 & 8.1.12.1 18 | PUT32(addr_temp, value); 19 | } 20 | unsigned int CKM_getCLKModuleRegister(CLK_MODULE_t module, CKM_MODULE_REG reg) 21 | { 22 | 23 | unsigned int addr_temp = module + reg; // clock module base + module offset, TRM 2.1 & 8.1.12.1 24 | return GET32(addr_temp); 25 | 26 | } 27 | 28 | 29 | 30 | /* 31 | The MIT License (MIT) 32 | 33 | Copyright (c) 2015 Alexis Marquet 34 | 35 | Permission is hereby granted, free of charge, to any person obtaining a copy 36 | of this software and associated documentation files (the "Software"), to deal 37 | in the Software without restriction, including without limitation the rights 38 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | copies of the Software, and to permit persons to whom the Software is 40 | furnished to do so, subject to the following conditions: 41 | 42 | The above copyright notice and this permission notice shall be included in 43 | all copies or substantial portions of the Software. 44 | 45 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 | THE SOFTWARE. 52 | */ 53 | -------------------------------------------------------------------------------- /06_stdlib/proc/control_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file control_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning control module usage: TRM 9, TRM 9.3 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "control_module.h" 10 | 11 | #define CM_MODULE_REGISTER_BASE 0x44E10000 12 | 13 | 14 | void CM_setCtrlModule(CONTROL_MODULE module, unsigned int value) 15 | { 16 | PUT32(CM_MODULE_REGISTER_BASE + module, value); 17 | } 18 | 19 | unsigned int CM_getCtrlModule(CONTROL_MODULE module) 20 | { 21 | return GET32(CM_MODULE_REGISTER_BASE + module); 22 | } 23 | 24 | 25 | 26 | 27 | 28 | /* 29 | The MIT License (MIT) 30 | 31 | Copyright (c) 2015 Alexis Marquet 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy 34 | of this software and associated documentation files (the "Software"), to deal 35 | in the Software without restriction, including without limitation the rights 36 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 37 | copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in 41 | all copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 48 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 49 | THE SOFTWARE. 50 | */ 51 | -------------------------------------------------------------------------------- /06_stdlib/proc/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=@/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi- 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 -O0 -ggdb 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | PARENTOBJ=../obj/ 7 | 8 | all: dir $(OBJ)proc_init.o $(OBJ)UART.o $(OBJ)GPIO.o $(OBJ)control_module.o $(OBJ)clock_module.o $(OBJ)pad.o $(OBJ)proc_Handlers.o 9 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)proc.o 10 | 11 | dir: 12 | @mkdir -p $(OBJ) 13 | 14 | $(OBJ)proc_init.o: proc_init.c 15 | $(CHAIN)gcc $(CFLAGS) -c proc_init.c -o $(OBJ)proc_init.o 16 | 17 | $(OBJ)proc_Handlers.o: proc_Handlers.c 18 | $(CHAIN)gcc $(CFLAGS) -c proc_Handlers.c -o $(OBJ)proc_Handlers.o 19 | 20 | $(OBJ)GPIO.o: GPIO.c 21 | $(CHAIN)gcc $(CFLAGS) -c GPIO.c -o $(OBJ)GPIO.o 22 | 23 | $(OBJ)pad.o: pad.c 24 | $(CHAIN)gcc $(CFLAGS) -c pad.c -o $(OBJ)pad.o 25 | 26 | $(OBJ)control_module.o: control_module.c 27 | $(CHAIN)gcc $(CFLAGS) -c control_module.c -o $(OBJ)control_module.o 28 | 29 | $(OBJ)clock_module.o: clock_module.c 30 | $(CHAIN)gcc $(CFLAGS) -c clock_module.c -o $(OBJ)clock_module.o 31 | 32 | $(OBJ)UART.o:UART.c 33 | $(CHAIN)gcc $(CFLAGS) -c UART.c -o $(OBJ)UART.o 34 | 35 | clean: 36 | rm -rf $(OBJ)*.o 37 | -------------------------------------------------------------------------------- /06_stdlib/proc/obj/GPIO.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/proc/obj/GPIO.o -------------------------------------------------------------------------------- /06_stdlib/proc/obj/UART.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/proc/obj/UART.o -------------------------------------------------------------------------------- /06_stdlib/proc/obj/clock_module.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/proc/obj/clock_module.o -------------------------------------------------------------------------------- /06_stdlib/proc/obj/control_module.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/proc/obj/control_module.o -------------------------------------------------------------------------------- /06_stdlib/proc/obj/pad.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/proc/obj/pad.o -------------------------------------------------------------------------------- /06_stdlib/proc/obj/proc_Handlers.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/proc/obj/proc_Handlers.o -------------------------------------------------------------------------------- /06_stdlib/proc/obj/proc_init.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/proc/obj/proc_init.o -------------------------------------------------------------------------------- /06_stdlib/proc/pad.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pad.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation of the pad control functions: TRM 9.3.51, TRM 9.2.2.1 & Datasheet 4 6 | **/ 7 | 8 | #include "pad.h" 9 | #include "control_module.h" 10 | 11 | 12 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 13 | { 14 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 15 | { 16 | unsigned int temp = CM_getCtrlModule(module); 17 | temp &= ~(0b111); // turn down MUXMODE 18 | temp |= mode; // set new MUXMODE 19 | CM_setCtrlModule(module, temp); 20 | } 21 | else 22 | { 23 | // TODO: raise error (control module isnt a "conf " register) 24 | return; 25 | } 26 | } 27 | pinmode_t PAD_getMode(CONTROL_MODULE module) 28 | { 29 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 30 | { 31 | unsigned int temp = CM_getCtrlModule(module); 32 | temp &= ~(0b111); 33 | return (pinmode_t) temp; 34 | } 35 | else 36 | { 37 | // TODO: raise error (control module isnt a "conf " register) 38 | return -1; 39 | } 40 | } 41 | 42 | 43 | 44 | /* 45 | The MIT License (MIT) 46 | 47 | Copyright (c) 2015 Alexis Marquet 48 | 49 | Permission is hereby granted, free of charge, to any person obtaining a copy 50 | of this software and associated documentation files (the "Software"), to deal 51 | in the Software without restriction, including without limitation the rights 52 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 53 | copies of the Software, and to permit persons to whom the Software is 54 | furnished to do so, subject to the following conditions: 55 | 56 | The above copyright notice and this permission notice shall be included in 57 | all copies or substantial portions of the Software. 58 | 59 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 60 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 61 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 62 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 63 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 64 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 65 | THE SOFTWARE. 66 | */ 67 | -------------------------------------------------------------------------------- /06_stdlib/proc/pad.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pad.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Types & prototypes of the pad control functions: TRM 9.3.51, TRM 9.2.2.1 & Datasheet 4 6 | **/ 7 | #ifndef __pad_H 8 | #define __pad_H 9 | #include "control_module.h" 10 | 11 | /** 12 | * @brief MUXMODES for pin pads 13 | **/ 14 | typedef enum 15 | { 16 | MODE_0 = 0, 17 | MODE_1 = 1, 18 | MODE_2 = 2, 19 | MODE_3 = 3, 20 | MODE_4 = 4, 21 | MODE_5 = 5, 22 | MODE_6 = 6, 23 | MODE_7 = 7 24 | 25 | }pinmode_t; 26 | 27 | 28 | /** 29 | * @fn void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 30 | * @brief Set a mode to a control module. 31 | * @param[in] module Module to set the mode to. 32 | * @param[in] mode Mode to set the module to. 33 | * @return void 34 | **/ 35 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode); 36 | 37 | 38 | /** 39 | * @fn pinmode_t PAD_getMode(CONTROL_MODULE module) 40 | * @brief Get the mode of a module. 41 | * @param[in] module Module to get the mode from; 42 | * @return mode of this control module 43 | **/ 44 | pinmode_t PAD_getMode(CONTROL_MODULE module); 45 | 46 | #endif /* defined(__pad_H) */ 47 | 48 | 49 | 50 | 51 | /* 52 | The MIT License (MIT) 53 | 54 | Copyright (c) 2015 Alexis Marquet 55 | 56 | Permission is hereby granted, free of charge, to any person obtaining a copy 57 | of this software and associated documentation files (the "Software"), to deal 58 | in the Software without restriction, including without limitation the rights 59 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 60 | copies of the Software, and to permit persons to whom the Software is 61 | furnished to do so, subject to the following conditions: 62 | 63 | The above copyright notice and this permission notice shall be included in 64 | all copies or substantial portions of the Software. 65 | 66 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 67 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 68 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 69 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 70 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 71 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 72 | THE SOFTWARE. 73 | */ 74 | -------------------------------------------------------------------------------- /06_stdlib/proc/proc_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file proc_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief Initialize the processor and its needed peripherals 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "../proc/UART.h" 10 | 11 | #define NVIC 0x48200000 12 | #define CM_WKUP 0x44E00400 13 | void procInit() 14 | { 15 | 16 | /* peripherals */ 17 | PUT32(0x47400000+0x10,1); // reset USB controller to get the internet connection back 18 | 19 | PUT32(NVIC+0x10,1); // reset INTC controller 20 | while((GET32(NVIC+0x14)&0x1)==0); // wait until reset is done 21 | 22 | PUT32(NVIC+0x68,0xFF); // disable interrupt threshold 23 | PUT32(NVIC+0x50,1); // enable functional clock 24 | 25 | PUT32(NVIC+0x94,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 26 | PUT32(NVIC+0xB4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 27 | PUT32(NVIC+0xD4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 28 | PUT32(NVIC+0xF4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 29 | 30 | CPU_irqE(); 31 | 32 | UART_initUART(UART0,115200,STOP1,PARITY_NONE,FLOW_OFF); 33 | 34 | UART_putString(UART0,"$UART0 Initialized... compiled at " __TIME__ "\n",43); 35 | 36 | 37 | } -------------------------------------------------------------------------------- /06_stdlib/sys/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=@/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi- 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 -O0 -ggdb 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | PARENTOBJ=../obj/ 7 | 8 | all: dir $(OBJ)types.o $(OBJ)syscalls.o 9 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)sys.o 10 | 11 | dir: 12 | @mkdir -p $(OBJ) 13 | 14 | $(OBJ)types.o: types.c 15 | $(CHAIN)gcc $(CFLAGS) -c types.c -o $(OBJ)types.o 16 | 17 | $(OBJ)syscalls.o: syscalls.c 18 | $(CHAIN)gcc $(CFLAGS) -c syscalls.c -o $(OBJ)syscalls.o 19 | 20 | clean: 21 | rm -rf $(OBJ)*.o 22 | -------------------------------------------------------------------------------- /06_stdlib/sys/obj/syscalls.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/sys/obj/syscalls.o -------------------------------------------------------------------------------- /06_stdlib/sys/obj/types.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/06_stdlib/sys/obj/types.o -------------------------------------------------------------------------------- /06_stdlib/sys/types.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file types.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief Dummy file for consistency with hierarchy 6 | **/ 7 | 8 | void types (void) 9 | { 10 | 11 | } -------------------------------------------------------------------------------- /06_stdlib/sys/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file types.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Standard types declaration 6 | **/ 7 | 8 | #ifndef __types_H 9 | #define __types_H 10 | 11 | /** 12 | @brief boolean (true/false) 13 | **/ 14 | typedef enum 15 | { 16 | true = 1, 17 | false = 0 18 | }bool; 19 | 20 | #endif 21 | 22 | 23 | 24 | /* 25 | The MIT License (MIT) 26 | 27 | Copyright (c) 2015 Alexis Marquet 28 | 29 | Permission is hereby granted, free of charge, to any person obtaining a copy 30 | of this software and associated documentation files (the "Software"), to deal 31 | in the Software without restriction, including without limitation the rights 32 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 33 | copies of the Software, and to permit persons to whom the Software is 34 | furnished to do so, subject to the following conditions: 35 | 36 | The above copyright notice and this permission notice shall be included in 37 | all copies or substantial portions of the Software. 38 | 39 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 40 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 41 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 42 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 43 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 44 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 45 | THE SOFTWARE. 46 | */ 47 | -------------------------------------------------------------------------------- /07_Bootloader/README.md: -------------------------------------------------------------------------------- 1 | 07_Bootloader 2 | 3 | =============== 4 | 5 | This sample implements a bootloader. after initializing the board, including the DDR chip. 6 | it it then prints the code destination (0x80000000) and waits for a file to be sent. 7 | The structure of the executable is as follows: 8 | | 4 bytes | variable | 8 bytes | 9 | | length | data | checksum| 10 | The checksum is just a sum on the complete file, byte by byte. not the best integrity check, but good enough. 11 | after the file is recieved, the bootloader compares both checksums (the one received, and the one computed) 12 | and if they match, it branches to the entry point. 13 | The \005 character is because i programmed my terminal to automatically send the file when this character 14 | is encountered. 15 | If you want to send the file via xmodem, there's plenty of information on the web, including example, on 16 | how to implement that. 17 | 18 | 19 | The DDR init is from https://github.com/auselen/down-to-the-bone/tree/master/baremetal_runtime, cheers to him. 20 | 21 | -------------------------------------------------------------------------------- /07_Bootloader/board/board_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file /board/board_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief board initialisation. every component that is NOT the SoC but is on the board must be init here. 6 | **/ 7 | 8 | #include "LED.h" 9 | 10 | void boardInit() 11 | { 12 | LED_init(); 13 | } 14 | 15 | /* 16 | The MIT License (MIT) 17 | 18 | Copyright (c) 2015 Alexis Marquet 19 | 20 | Permission is hereby granted, free of charge, to any person obtaining a copy 21 | of this software and associated documentation files (the "Software"), to deal 22 | in the Software without restriction, including without limitation the rights 23 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | copies of the Software, and to permit persons to whom the Software is 25 | furnished to do so, subject to the following conditions: 26 | 27 | The above copyright notice and this permission notice shall be included in 28 | all copies or substantial portions of the Software. 29 | 30 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 36 | THE SOFTWARE. 37 | */ 38 | -------------------------------------------------------------------------------- /07_Bootloader/board/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)board_init.o $(OBJ)LED.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)board.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)LED.o: LED.c 11 | $(CHAIN)gcc $(CFLAGS) -c LED.c -o $(OBJ)LED.o 12 | 13 | $(OBJ)board_init.o: board_init.c 14 | $(CHAIN)gcc $(CFLAGS) -c board_init.c -o $(OBJ)board_init.o 15 | 16 | clean: 17 | rm -rf $(OBJ)*.o 18 | -------------------------------------------------------------------------------- /07_Bootloader/core/core_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file core_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief this function is the core init function. its the first function do be called from the startup. 6 | * 7 | * @note the bss is already initialized at this point. 8 | **/ 9 | #include "llma.h" 10 | 11 | 12 | void coreInit() 13 | { 14 | CPU_irqD(); // disable interrupt 15 | } 16 | 17 | 18 | 19 | 20 | /* 21 | The MIT License (MIT) 22 | 23 | Copyright (c) 2015 Alexis Marquet 24 | 25 | Permission is hereby granted, free of charge, to any person obtaining a copy 26 | of this software and associated documentation files (the "Software"), to deal 27 | in the Software without restriction, including without limitation the rights 28 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 29 | copies of the Software, and to permit persons to whom the Software is 30 | furnished to do so, subject to the following conditions: 31 | 32 | The above copyright notice and this permission notice shall be included in 33 | all copies or substantial portions of the Software. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 38 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 40 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 41 | THE SOFTWARE. 42 | */ 43 | -------------------------------------------------------------------------------- /07_Bootloader/core/llma.s: -------------------------------------------------------------------------------- 1 | /** 2 | * @file llma.s 3 | * @author Alexis Marquet 4 | * @date 27 Feb 2015 5 | * @brief contains Low Level Memory Access functions 6 | **/ 7 | 8 | 9 | .globl PUT32 10 | PUT32: 11 | str r1,[r0] 12 | bx lr 13 | 14 | .globl GET32 15 | GET32: 16 | ldr r0,[r0] 17 | bx lr 18 | 19 | .globl PUT16 20 | PUT16: 21 | strh r1,[r0] 22 | bx lr 23 | 24 | .globl GET16 25 | GET16: 26 | ldrh r0,[r0] 27 | bx lr 28 | 29 | .globl PUT8 30 | PUT8: 31 | strb r1,[r0] 32 | bx lr 33 | 34 | .globl GET8 35 | GET8: 36 | ldrb r0,[r0] 37 | bx lr 38 | 39 | .globl BRANCHTO 40 | BRANCHTO: 41 | mov pc, r0 42 | bx lr //never happens 43 | 44 | 45 | .globl CPU_irqE 46 | CPU_irqE: 47 | dsb 48 | mrs r0, cpsr 49 | bic r0, r0, #0x80 50 | msr cpsr_c, r0 51 | DSB 52 | ISB 53 | bx lr 54 | 55 | .globl CPU_irqD 56 | CPU_irqD: 57 | dsb 58 | mrs r0, cpsr 59 | orr r0, r0, #0x80 60 | msr cpsr_c, r0 61 | DSB 62 | ISB 63 | bx lr 64 | 65 | /* 66 | The MIT License (MIT) 67 | 68 | Copyright (c) 2015 Alexis Marquet 69 | 70 | Permission is hereby granted, free of charge, to any person obtaining a copy 71 | of this software and associated documentation files (the "Software"), to deal 72 | in the Software without restriction, including without limitation the rights 73 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 74 | copies of the Software, and to permit persons to whom the Software is 75 | furnished to do so, subject to the following conditions: 76 | 77 | The above copyright notice and this permission notice shall be included in 78 | all copies or substantial portions of the Software. 79 | 80 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 81 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 82 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 83 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 84 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 85 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 86 | THE SOFTWARE. 87 | */ 88 | -------------------------------------------------------------------------------- /07_Bootloader/core/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)startup_ARMCA8.o1 $(OBJ)core_handlers.o $(OBJ)llma.o $(OBJ)core_init.o $(OBJ)__aeabi.o 5 | $(CHAIN)ld -r $(OBJ)startup_ARMCA8.o1 $(OBJ)*.o -o $(PARENTOBJ)core.o 6 | 7 | 8 | 9 | dir: 10 | @mkdir -p $(OBJ) 11 | 12 | $(OBJ)startup_ARMCA8.o1: startup_ARMCA8.s 13 | $(CHAIN)as $(AFLAGS) -c startup_ARMCA8.s -o $(OBJ)startup_ARMCA8.o1 14 | 15 | $(OBJ)core_init.o: core_init.c 16 | $(CHAIN)gcc $(CFLAGS) -c core_init.c -o $(OBJ)core_init.o 17 | 18 | $(OBJ)core_handlers.o: core_handlers.s 19 | $(CHAIN)as $(AFLAGS) -c core_handlers.s -o $(OBJ)core_handlers.o 20 | 21 | $(OBJ)llma.o: llma.s 22 | $(CHAIN)as $(AFLAGS) -c llma.s -o $(OBJ)llma.o 23 | 24 | $(OBJ)__aeabi.o: __aeabi.s 25 | $(CHAIN)as $(AFLAGS) -c __aeabi.s -o $(OBJ)__aeabi.o 26 | 27 | 28 | 29 | 30 | clean: 31 | rm -rf $(OBJ)*.o 32 | 33 | -------------------------------------------------------------------------------- /07_Bootloader/kernel/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)main.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)kernel.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)main.o: main.c 11 | $(CHAIN)gcc $(CFLAGS) -c main.c -o $(OBJ)main.o 12 | 13 | clean: 14 | rm -rf $(OBJ)*.o 15 | -------------------------------------------------------------------------------- /07_Bootloader/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=@/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi- 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 -O0 -fstack-usage 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | BIN=bin/ 7 | LIBPATH=/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/arm-none-eabi/lib/fpu/ 8 | 9 | COPYARG=CHAIN="$(CHAIN)" CFLAGS="$(CFLAGS)" AFLAGS="$(AFLAGS)" 10 | 11 | all: dir $(OBJ)core.o $(OBJ)proc.o $(OBJ)board.o $(OBJ)sys.o $(OBJ)kernel.o 12 | @rm -rf $(BIN)*.boot 13 | @echo "assembling output file..." 14 | $(CHAIN)ld -T memmap.ld $(OBJ)core.o $(OBJ)proc.o $(OBJ)board.o $(OBJ)sys.o $(OBJ)kernel.o -L $(LIBPATH) -l"c" -l"m" -o $(OBJ)main.elf 15 | $(CHAIN)objcopy $(OBJ)main.elf $(BIN)spl.boot -O binary 16 | @echo "done!" 17 | 18 | dir: 19 | @mkdir -p $(OBJ) $(BIN) 20 | 21 | $(OBJ)core.o: force_look 22 | @echo "building core/" 23 | @cd core/ ; $(MAKE) $(MFLAGS) $(COPYARG) 24 | 25 | $(OBJ)proc.o: force_look 26 | @echo "building proc/" 27 | @cd proc/ ; $(MAKE) $(MFLAGS) $(COPYARG) 28 | 29 | $(OBJ)board.o: force_look 30 | @echo "building board/" 31 | @cd board/ ; $(MAKE) $(MFLAGS) $(COPYARG) 32 | 33 | $(OBJ)sys.o: force_look 34 | @echo "building sys/" 35 | @cd sys/ ; $(MAKE) $(MFLAGS) $(COPYARG) 36 | 37 | $(OBJ)kernel.o: force_look 38 | @echo "building kernel/" 39 | @cd kernel/ ; $(MAKE) $(MFLAGS) $(COPYARG) 40 | 41 | force_look: 42 | @true 43 | 44 | copy: 45 | @echo "copying boot file..." 46 | @cp $(BIN)spl.boot ../boot 47 | @echo "done" 48 | 49 | clean: 50 | @echo "cleaning up..." 51 | @rm -rf $(OBJ)*.o 52 | @rm -rf $(OBJ)*.elf 53 | @rm -rf $(BIN)*.boot 54 | @rm -rf ../boot/*.boot 55 | @rm -rf core/obj/* 56 | @rm -rf proc/obj/* 57 | @rm -rf board/obj/* 58 | @rm -rf sys/obj/* 59 | @rm -rf kernel/obj/* 60 | @echo "done!" 61 | 62 | dump: 63 | $(CHAIN)objdump -D $(OBJ)main.elf -------------------------------------------------------------------------------- /07_Bootloader/proc/DDR.h: -------------------------------------------------------------------------------- 1 | // 2 | // DDR.h 3 | // 4 | // 5 | // Created by Alexis Marquet on 29/04/15. 6 | // 7 | // 8 | 9 | #ifndef ____DDR__ 10 | #define ____DDR__ 11 | 12 | #include 13 | 14 | 15 | void config_ddr_x(void); 16 | 17 | #endif /* defined(____DDR__) */ 18 | -------------------------------------------------------------------------------- /07_Bootloader/proc/EMIF.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef ____EMIF__ 4 | #define ____EMIF__ 5 | 6 | void DDR3_EMIF_Config(); 7 | 8 | 9 | #endif /* defined(____EMIF__) */ 10 | -------------------------------------------------------------------------------- /07_Bootloader/proc/PLL.h: -------------------------------------------------------------------------------- 1 | // 2 | // PLL.h 3 | // 4 | // 5 | // Created by Alexis Marquet on 28/04/15. 6 | // 7 | // 8 | 9 | #ifndef ____PLL__ 10 | #define ____PLL__ 11 | 12 | #include 13 | 14 | uint32_t GetInputClockFrequency(); 15 | 16 | void MPU_PLL_Config(uint32_t clkin, uint32_t n, uint32_t m, uint32_t m2); 17 | 18 | void CORE_PLL_Config(uint32_t clkin, uint32_t n, uint32_t m, uint32_t m4, uint32_t m5, uint32_t m6); 19 | 20 | void DDR_PLL_Config(uint32_t clkin, uint32_t n, uint32_t m, uint32_t m2); 21 | 22 | void PER_PLL_Config(uint32_t clkin, uint32_t n, uint32_t m, uint32_t m2); 23 | 24 | void DISP_PLL_Config(uint32_t clkin, uint32_t n, uint32_t m, uint32_t m2); 25 | 26 | #endif /* defined(____PLL__) */ 27 | -------------------------------------------------------------------------------- /07_Bootloader/proc/clock_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file clock_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning clock module usage: TRM 8 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "../sys/types.h" 10 | #include "clock_module.h" 11 | 12 | 13 | // TODO: implement module/reg validity check 14 | 15 | void CKM_setCLKModuleRegister(CLK_MODULE_t module, CKM_MODULE_REG reg, unsigned int value) 16 | { 17 | unsigned int addr_temp = module + reg; // clock module base + module offset, TRM 2.1 & 8.1.12.1 18 | PUT32(addr_temp, value); 19 | } 20 | unsigned int CKM_getCLKModuleRegister(CLK_MODULE_t module, CKM_MODULE_REG reg) 21 | { 22 | 23 | unsigned int addr_temp = module + reg; // clock module base + module offset, TRM 2.1 & 8.1.12.1 24 | return GET32(addr_temp); 25 | 26 | } 27 | 28 | 29 | 30 | /* 31 | The MIT License (MIT) 32 | 33 | Copyright (c) 2015 Alexis Marquet 34 | 35 | Permission is hereby granted, free of charge, to any person obtaining a copy 36 | of this software and associated documentation files (the "Software"), to deal 37 | in the Software without restriction, including without limitation the rights 38 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | copies of the Software, and to permit persons to whom the Software is 40 | furnished to do so, subject to the following conditions: 41 | 42 | The above copyright notice and this permission notice shall be included in 43 | all copies or substantial portions of the Software. 44 | 45 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 | THE SOFTWARE. 52 | */ 53 | -------------------------------------------------------------------------------- /07_Bootloader/proc/control_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file control_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning control module usage: TRM 9, TRM 9.3 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "control_module.h" 10 | 11 | #define CM_MODULE_REGISTER_BASE 0x44E10000 12 | 13 | 14 | void CM_setCtrlModule(CONTROL_MODULE module, unsigned int value) 15 | { 16 | PUT32(CM_MODULE_REGISTER_BASE + module, value); 17 | } 18 | 19 | unsigned int CM_getCtrlModule(CONTROL_MODULE module) 20 | { 21 | return GET32(CM_MODULE_REGISTER_BASE + module); 22 | } 23 | 24 | 25 | 26 | 27 | 28 | /* 29 | The MIT License (MIT) 30 | 31 | Copyright (c) 2015 Alexis Marquet 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy 34 | of this software and associated documentation files (the "Software"), to deal 35 | in the Software without restriction, including without limitation the rights 36 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 37 | copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in 41 | all copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 48 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 49 | THE SOFTWARE. 50 | */ 51 | -------------------------------------------------------------------------------- /07_Bootloader/proc/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)proc_init.o $(OBJ)UART.o $(OBJ)GPIO.o $(OBJ)control_module.o $(OBJ)clock_module.o $(OBJ)pad.o $(OBJ)proc_Handlers.o $(OBJ)PLL.o $(OBJ)EMIF.o $(OBJ)DDR.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)proc.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)proc_init.o: proc_init.c 11 | $(CHAIN)gcc $(CFLAGS) -c proc_init.c -o $(OBJ)proc_init.o 12 | 13 | $(OBJ)proc_Handlers.o: proc_Handlers.c 14 | $(CHAIN)gcc $(CFLAGS) -c proc_Handlers.c -o $(OBJ)proc_Handlers.o 15 | 16 | $(OBJ)GPIO.o: GPIO.c 17 | $(CHAIN)gcc $(CFLAGS) -c GPIO.c -o $(OBJ)GPIO.o 18 | 19 | $(OBJ)pad.o: pad.c 20 | $(CHAIN)gcc $(CFLAGS) -c pad.c -o $(OBJ)pad.o 21 | 22 | $(OBJ)control_module.o: control_module.c 23 | $(CHAIN)gcc $(CFLAGS) -c control_module.c -o $(OBJ)control_module.o 24 | 25 | $(OBJ)clock_module.o: clock_module.c 26 | $(CHAIN)gcc $(CFLAGS) -c clock_module.c -o $(OBJ)clock_module.o 27 | 28 | $(OBJ)UART.o: UART.c 29 | $(CHAIN)gcc $(CFLAGS) -c UART.c -o $(OBJ)UART.o 30 | 31 | $(OBJ)PLL.o: PLL.c 32 | $(CHAIN)gcc $(CFLAGS) -c PLL.c -o $(OBJ)PLL.o 33 | 34 | $(OBJ)EMIF.o: EMIF.c 35 | $(CHAIN)gcc $(CFLAGS) -c EMIF.c -o $(OBJ)EMIF.o 36 | 37 | $(OBJ)DDR.o: DDR.c 38 | $(CHAIN)gcc $(CFLAGS) -c DDR.c -o $(OBJ)DDR.o 39 | 40 | clean: 41 | rm -rf $(OBJ)*.o 42 | -------------------------------------------------------------------------------- /07_Bootloader/proc/pad.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pad.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation of the pad control functions: TRM 9.3.51, TRM 9.2.2.1 & Datasheet 4 6 | **/ 7 | 8 | #include "pad.h" 9 | #include "control_module.h" 10 | 11 | 12 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 13 | { 14 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 15 | { 16 | unsigned int temp = CM_getCtrlModule(module); 17 | temp &= ~(0b111); // turn down MUXMODE 18 | temp |= mode; // set new MUXMODE 19 | CM_setCtrlModule(module, temp); 20 | } 21 | else 22 | { 23 | // TODO: raise error (control module isnt a "conf " register) 24 | return; 25 | } 26 | } 27 | pinmode_t PAD_getMode(CONTROL_MODULE module) 28 | { 29 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 30 | { 31 | unsigned int temp = CM_getCtrlModule(module); 32 | temp &= ~(0b111); 33 | return (pinmode_t) temp; 34 | } 35 | else 36 | { 37 | // TODO: raise error (control module isnt a "conf " register) 38 | return -1; 39 | } 40 | } 41 | 42 | 43 | 44 | /* 45 | The MIT License (MIT) 46 | 47 | Copyright (c) 2015 Alexis Marquet 48 | 49 | Permission is hereby granted, free of charge, to any person obtaining a copy 50 | of this software and associated documentation files (the "Software"), to deal 51 | in the Software without restriction, including without limitation the rights 52 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 53 | copies of the Software, and to permit persons to whom the Software is 54 | furnished to do so, subject to the following conditions: 55 | 56 | The above copyright notice and this permission notice shall be included in 57 | all copies or substantial portions of the Software. 58 | 59 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 60 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 61 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 62 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 63 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 64 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 65 | THE SOFTWARE. 66 | */ 67 | -------------------------------------------------------------------------------- /07_Bootloader/proc/pad.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pad.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Types & prototypes of the pad control functions: TRM 9.3.51, TRM 9.2.2.1 & Datasheet 4 6 | **/ 7 | #ifndef __pad_H 8 | #define __pad_H 9 | #include "control_module.h" 10 | 11 | /** 12 | * @brief MUXMODES for pin pads 13 | **/ 14 | typedef enum 15 | { 16 | MODE_0 = 0, 17 | MODE_1 = 1, 18 | MODE_2 = 2, 19 | MODE_3 = 3, 20 | MODE_4 = 4, 21 | MODE_5 = 5, 22 | MODE_6 = 6, 23 | MODE_7 = 7 24 | 25 | }pinmode_t; 26 | 27 | 28 | /** 29 | * @fn void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 30 | * @brief Set a mode to a control module. 31 | * @param[in] module Module to set the mode to. 32 | * @param[in] mode Mode to set the module to. 33 | * @return void 34 | **/ 35 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode); 36 | 37 | 38 | /** 39 | * @fn pinmode_t PAD_getMode(CONTROL_MODULE module) 40 | * @brief Get the mode of a module. 41 | * @param[in] module Module to get the mode from; 42 | * @return mode of this control module 43 | **/ 44 | pinmode_t PAD_getMode(CONTROL_MODULE module); 45 | 46 | #endif /* defined(__pad_H) */ 47 | 48 | 49 | 50 | 51 | /* 52 | The MIT License (MIT) 53 | 54 | Copyright (c) 2015 Alexis Marquet 55 | 56 | Permission is hereby granted, free of charge, to any person obtaining a copy 57 | of this software and associated documentation files (the "Software"), to deal 58 | in the Software without restriction, including without limitation the rights 59 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 60 | copies of the Software, and to permit persons to whom the Software is 61 | furnished to do so, subject to the following conditions: 62 | 63 | The above copyright notice and this permission notice shall be included in 64 | all copies or substantial portions of the Software. 65 | 66 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 67 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 68 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 69 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 70 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 71 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 72 | THE SOFTWARE. 73 | */ 74 | -------------------------------------------------------------------------------- /07_Bootloader/proc/proc_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file proc_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief Initialize the processor and its needed peripherals 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "UART.h" 10 | #include "PLL.h" 11 | #include "EMIF.h" 12 | #include "DDR.h" 13 | #include 14 | 15 | #define NVIC 0x48200000 16 | #define CM_WKUP 0x44E00400 17 | 18 | void procInit() 19 | { 20 | 21 | 22 | 23 | /* peripherals */ 24 | PUT32(0x47400000+0x10,1); // reset USB controller to get the internet connection back 25 | 26 | PUT32(NVIC+0x10,1); // reset INTC controller 27 | while((GET32(NVIC+0x14)&0x1)==0); // wait until reset is done 28 | 29 | PUT32(NVIC+0x68,0xFF); // disable interrupt threshold 30 | PUT32(NVIC+0x50,1); // enable functional clock 31 | 32 | PUT32(NVIC+0x94,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 33 | PUT32(NVIC+0xB4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 34 | PUT32(NVIC+0xD4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 35 | PUT32(NVIC+0xF4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 36 | 37 | CPU_irqE(); 38 | 39 | UART_initUART(UART0,115200,STOP1,PARITY_NONE,FLOW_OFF); 40 | 41 | UART_putString(UART0,"$UART0 Initialized... compiled at " __TIME__ "\n",43); 42 | 43 | 44 | uint32_t clkin = GetInputClockFrequency(); 45 | if(clkin==24) 46 | { 47 | MPU_PLL_Config (clkin, 23, 500, 1); 48 | CORE_PLL_Config(clkin, 23, 1000, 10, 8, 4); 49 | DDR_PLL_Config (clkin, 23, 400, 1); 50 | PER_PLL_Config (clkin, 23, 960, 5); 51 | DISP_PLL_Config(clkin, 23, 48, 1); 52 | } 53 | else 54 | { 55 | printf("error, clkin invalid\n"); 56 | while(1); 57 | } 58 | //RAM 59 | DDR3_EMIF_Config(); 60 | config_ddr_x();// this works 61 | } -------------------------------------------------------------------------------- /07_Bootloader/sys/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)types.o $(OBJ)syscalls.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)sys.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)types.o: types.c 11 | $(CHAIN)gcc $(CFLAGS) -c types.c -o $(OBJ)types.o 12 | 13 | $(OBJ)syscalls.o: syscalls.c 14 | $(CHAIN)gcc $(CFLAGS) -c syscalls.c -o $(OBJ)syscalls.o 15 | 16 | clean: 17 | rm -rf $(OBJ)*.o 18 | -------------------------------------------------------------------------------- /07_Bootloader/sys/types.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file types.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief Dummy file for consistency with hierarchy 6 | **/ 7 | 8 | void types (void) 9 | { 10 | 11 | } -------------------------------------------------------------------------------- /07_Bootloader/sys/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file types.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Standard types declaration 6 | **/ 7 | 8 | #ifndef __types_H 9 | #define __types_H 10 | 11 | /** 12 | @brief boolean (true/false) 13 | **/ 14 | typedef enum 15 | { 16 | true = 1, 17 | false = 0 18 | }bool; 19 | 20 | #endif 21 | 22 | 23 | 24 | /* 25 | The MIT License (MIT) 26 | 27 | Copyright (c) 2015 Alexis Marquet 28 | 29 | Permission is hereby granted, free of charge, to any person obtaining a copy 30 | of this software and associated documentation files (the "Software"), to deal 31 | in the Software without restriction, including without limitation the rights 32 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 33 | copies of the Software, and to permit persons to whom the Software is 34 | furnished to do so, subject to the following conditions: 35 | 36 | The above copyright notice and this permission notice shall be included in 37 | all copies or substantial portions of the Software. 38 | 39 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 40 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 41 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 42 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 43 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 44 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 45 | THE SOFTWARE. 46 | */ 47 | -------------------------------------------------------------------------------- /08_test_CXX/README.md: -------------------------------------------------------------------------------- 1 | 08_test_CXX 2 | =============== 3 | 4 | in this one, I tried to get cxx linkage to work. proof with vector, string, and ostream. 5 | first you should see the cout << output, then the led_class ctor, and the value "seconds" from the RTC should print. and after 16 seconds, the dtor, and ctor again. 6 | the executable size of this example is huge, i dont know why it is THAT huge. 7 | 8 | note that this is the first example to have a very different linker script: first of all, we boot from 0x80000000, as this code is loaded by 07_Bootloader. secondly, there is a lot of subtilities regarding the static/global ctor/dtor for c++, and the lib is waiting for some symbols. -------------------------------------------------------------------------------- /08_test_CXX/bin/spl.boot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/08_test_CXX/bin/spl.boot -------------------------------------------------------------------------------- /08_test_CXX/board/board_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file /board/board_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief board initialisation. every component that is NOT the SoC but is on the board must be init here. 6 | **/ 7 | 8 | #include "LED.h" 9 | 10 | void boardInit() 11 | { 12 | LED_init(); 13 | } 14 | 15 | /* 16 | The MIT License (MIT) 17 | 18 | Copyright (c) 2015 Alexis Marquet 19 | 20 | Permission is hereby granted, free of charge, to any person obtaining a copy 21 | of this software and associated documentation files (the "Software"), to deal 22 | in the Software without restriction, including without limitation the rights 23 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | copies of the Software, and to permit persons to whom the Software is 25 | furnished to do so, subject to the following conditions: 26 | 27 | The above copyright notice and this permission notice shall be included in 28 | all copies or substantial portions of the Software. 29 | 30 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 36 | THE SOFTWARE. 37 | */ 38 | -------------------------------------------------------------------------------- /08_test_CXX/board/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)board_init.o $(OBJ)LED.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)board.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)LED.o: LED.c 11 | $(CHAIN)gcc $(CFLAGS) -c LED.c -o $(OBJ)LED.o 12 | 13 | $(OBJ)board_init.o: board_init.c 14 | $(CHAIN)gcc $(CFLAGS) -c board_init.c -o $(OBJ)board_init.o 15 | 16 | clean: 17 | rm -rf $(OBJ)*.o 18 | -------------------------------------------------------------------------------- /08_test_CXX/core/core_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file core_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief this function is the core init function. its the first function do be called from the startup. 6 | * 7 | * @note the bss is already initialized at this point. 8 | **/ 9 | #include "llma.h" 10 | 11 | 12 | void coreInit() 13 | { 14 | CPU_irqD(); // disable interrupt 15 | } 16 | 17 | 18 | 19 | 20 | /* 21 | The MIT License (MIT) 22 | 23 | Copyright (c) 2015 Alexis Marquet 24 | 25 | Permission is hereby granted, free of charge, to any person obtaining a copy 26 | of this software and associated documentation files (the "Software"), to deal 27 | in the Software without restriction, including without limitation the rights 28 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 29 | copies of the Software, and to permit persons to whom the Software is 30 | furnished to do so, subject to the following conditions: 31 | 32 | The above copyright notice and this permission notice shall be included in 33 | all copies or substantial portions of the Software. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 38 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 40 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 41 | THE SOFTWARE. 42 | */ 43 | -------------------------------------------------------------------------------- /08_test_CXX/core/llma.s: -------------------------------------------------------------------------------- 1 | /** 2 | * @file llma.s 3 | * @author Alexis Marquet 4 | * @date 27 Feb 2015 5 | * @brief contains Low Level Memory Access functions 6 | **/ 7 | 8 | 9 | .globl PUT32 10 | PUT32: 11 | str r1,[r0] 12 | bx lr 13 | 14 | .globl GET32 15 | GET32: 16 | ldr r0,[r0] 17 | bx lr 18 | 19 | .globl PUT16 20 | PUT16: 21 | strh r1,[r0] 22 | bx lr 23 | 24 | .globl GET16 25 | GET16: 26 | ldrh r0,[r0] 27 | bx lr 28 | 29 | .globl PUT8 30 | PUT8: 31 | strb r1,[r0] 32 | bx lr 33 | 34 | .globl GET8 35 | GET8: 36 | ldrb r0,[r0] 37 | bx lr 38 | 39 | .globl BRANCHTO 40 | BRANCHTO: 41 | mov pc, r0 42 | bx lr //never happens 43 | 44 | 45 | .globl CPU_irqE 46 | CPU_irqE: 47 | dsb 48 | mrs r0, cpsr 49 | bic r0, r0, #0x80 50 | msr cpsr_c, r0 51 | DSB 52 | ISB 53 | bx lr 54 | 55 | .globl CPU_irqD 56 | CPU_irqD: 57 | dsb 58 | mrs r0, cpsr 59 | orr r0, r0, #0x80 60 | msr cpsr_c, r0 61 | DSB 62 | ISB 63 | bx lr 64 | 65 | /* 66 | The MIT License (MIT) 67 | 68 | Copyright (c) 2015 Alexis Marquet 69 | 70 | Permission is hereby granted, free of charge, to any person obtaining a copy 71 | of this software and associated documentation files (the "Software"), to deal 72 | in the Software without restriction, including without limitation the rights 73 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 74 | copies of the Software, and to permit persons to whom the Software is 75 | furnished to do so, subject to the following conditions: 76 | 77 | The above copyright notice and this permission notice shall be included in 78 | all copies or substantial portions of the Software. 79 | 80 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 81 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 82 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 83 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 84 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 85 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 86 | THE SOFTWARE. 87 | */ 88 | -------------------------------------------------------------------------------- /08_test_CXX/core/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)startup_ARMCA8.o1 $(OBJ)core_handlers.o $(OBJ)llma.o $(OBJ)core_init.o 5 | $(CHAIN)ld -r $(OBJ)startup_ARMCA8.o1 $(OBJ)*.o -o $(PARENTOBJ)core.o 6 | 7 | 8 | 9 | dir: 10 | @mkdir -p $(OBJ) 11 | 12 | $(OBJ)startup_ARMCA8.o1: startup_ARMCA8.s 13 | $(CHAIN)as $(AFLAGS) -c startup_ARMCA8.s -o $(OBJ)startup_ARMCA8.o1 14 | 15 | $(OBJ)core_init.o: core_init.c 16 | $(CHAIN)gcc $(CFLAGS) -c core_init.c -o $(OBJ)core_init.o 17 | 18 | $(OBJ)core_handlers.o: core_handlers.s 19 | $(CHAIN)as $(AFLAGS) -c core_handlers.s -o $(OBJ)core_handlers.o 20 | 21 | $(OBJ)llma.o: llma.s 22 | $(CHAIN)as $(AFLAGS) -c llma.s -o $(OBJ)llma.o 23 | 24 | 25 | 26 | 27 | clean: 28 | rm -rf $(OBJ)*.o 29 | 30 | -------------------------------------------------------------------------------- /08_test_CXX/kernel/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)main.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)kernel.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)main.o: main.cpp 11 | $(CHAIN)g++ $(CPPFLAGS) -c main.cpp -o $(OBJ)main.o 12 | 13 | clean: 14 | rm -rf $(OBJ)*.o 15 | -------------------------------------------------------------------------------- /08_test_CXX/makefile: -------------------------------------------------------------------------------- 1 | # makefile 2 | # Alexis Marquet 3 | 4 | 5 | #CHAINPATH specifies the path to your toolchain/bin/ directory 6 | CHAINPATH=@/usr/local/gcc_arm/gcc-arm-none-eabi-4_9-2014q4/bin/ 7 | #CHAIN specifies the name of your toolchain (arm-elf-linux, arm-none-eabi, etc...) 8 | CHAIN=$(CHAINPATH)arm-none-eabi- 9 | 10 | #Warning flags: 11 | WFLAGS= -Wall 12 | 13 | #MCPU is the core we are building for 14 | MCPU=-mcpu=cortex-a8 15 | 16 | #CFLAGS are the flags passed to gcc 17 | CFLAGS= $(WFLAGS) -std=gnu99 -mfpu=neon -mfloat-abi=softfp $(MCPU) -O2 18 | 19 | #CPP FLAGS are the flags passed to g++ 20 | CPPFLAGS= $(WFLAGS) -std=c++11 -fno-exceptions -fno-unwind-tables -fno-rtti -mfpu=neon $(MCPU) -O2 -mfloat-abi=softfp 21 | 22 | #Asm Flags are the flags passed to as 23 | AFLAGS=-mfpu=neon 24 | 25 | #build directories 26 | OBJ=obj/ 27 | BIN=bin/ 28 | 29 | 30 | LIBPATH=/usr/local/gcc_arm/gcc-arm-none-eabi-4_9-2014q4/arm-none-eabi/lib/ 31 | LIBS= 32 | MMAP= memmap.ld 33 | OBJLIST= $(OBJ)core.o $(OBJ)proc.o $(OBJ)board.o $(OBJ)sys.o $(OBJ)kernel.o 34 | 35 | COPYARG=CHAIN="$(CHAIN)" CFLAGS="$(CFLAGS)" AFLAGS="$(AFLAGS)" CPPFLAGS="$(CPPFLAGS)" 36 | 37 | all: dir $(OBJ)core.o $(OBJ)proc.o $(OBJ)board.o $(OBJ)sys.o $(OBJ)kernel.o 38 | @rm -rf $(BIN)*.boot 39 | @echo "assembling output file..." 40 | $(CHAIN)g++ -L $(LIBPATH) -T $(MMAP) $(OBJLIST) $(LIBS) -o $(OBJ)main.elf 41 | $(CHAIN)objcopy $(OBJ)main.elf $(BIN)spl.boot -O binary 42 | @echo "done!" 43 | $(CHAIN)size $(OBJ)main.elf 44 | 45 | dir: 46 | @mkdir -p $(OBJ) $(BIN) 47 | 48 | $(OBJ)core.o: force_look 49 | @echo "building core/" 50 | @cd core/ ; $(MAKE) $(MFLAGS) $(COPYARG) 51 | 52 | $(OBJ)proc.o: force_look 53 | @echo "building proc/" 54 | @cd proc/ ; $(MAKE) $(MFLAGS) $(COPYARG) 55 | 56 | $(OBJ)board.o: force_look 57 | @echo "building board/" 58 | @cd board/ ; $(MAKE) $(MFLAGS) $(COPYARG) 59 | 60 | $(OBJ)sys.o: force_look 61 | @echo "building sys/" 62 | @cd sys/ ; $(MAKE) $(MFLAGS) $(COPYARG) 63 | 64 | $(OBJ)kernel.o: force_look 65 | @echo "building kernel/" 66 | @cd kernel/ ; $(MAKE) $(MFLAGS) $(COPYARG) 67 | 68 | force_look: 69 | @true 70 | 71 | 72 | clean: 73 | @echo "cleaning up..." 74 | @rm -rf $(OBJ)*.o 75 | @rm -rf $(OBJ)*.elf 76 | @rm -rf $(BIN)*.boot 77 | @rm -rf core/obj/* 78 | @rm -rf proc/obj/* 79 | @rm -rf board/obj/* 80 | @rm -rf sys/obj/* 81 | @rm -rf kernel/obj/* 82 | @echo "done!" 83 | 84 | 85 | dump: 86 | $(CHAIN)objdump -D $(OBJ)main.elf -------------------------------------------------------------------------------- /08_test_CXX/proc/clock_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file clock_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning clock module usage: TRM 8 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "../sys/types.h" 10 | #include "clock_module.h" 11 | 12 | 13 | // TODO: implement module/reg validity check 14 | 15 | void CKM_setCLKModuleRegister(CLK_MODULE_t module, CKM_MODULE_REG reg, unsigned int value) 16 | { 17 | unsigned int addr_temp = module + reg; // clock module base + module offset, TRM 2.1 & 8.1.12.1 18 | PUT32(addr_temp, value); 19 | } 20 | unsigned int CKM_getCLKModuleRegister(CLK_MODULE_t module, CKM_MODULE_REG reg) 21 | { 22 | 23 | unsigned int addr_temp = module + reg; // clock module base + module offset, TRM 2.1 & 8.1.12.1 24 | return GET32(addr_temp); 25 | 26 | } 27 | 28 | 29 | 30 | /* 31 | The MIT License (MIT) 32 | 33 | Copyright (c) 2015 Alexis Marquet 34 | 35 | Permission is hereby granted, free of charge, to any person obtaining a copy 36 | of this software and associated documentation files (the "Software"), to deal 37 | in the Software without restriction, including without limitation the rights 38 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | copies of the Software, and to permit persons to whom the Software is 40 | furnished to do so, subject to the following conditions: 41 | 42 | The above copyright notice and this permission notice shall be included in 43 | all copies or substantial portions of the Software. 44 | 45 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 | THE SOFTWARE. 52 | */ 53 | -------------------------------------------------------------------------------- /08_test_CXX/proc/control_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file control_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning control module usage: TRM 9, TRM 9.3 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "control_module.h" 10 | 11 | #define CM_MODULE_REGISTER_BASE 0x44E10000 12 | 13 | 14 | void CM_setCtrlModule(CONTROL_MODULE module, unsigned int value) 15 | { 16 | PUT32(CM_MODULE_REGISTER_BASE + module, value); 17 | } 18 | 19 | unsigned int CM_getCtrlModule(CONTROL_MODULE module) 20 | { 21 | return GET32(CM_MODULE_REGISTER_BASE + module); 22 | } 23 | 24 | 25 | 26 | 27 | 28 | /* 29 | The MIT License (MIT) 30 | 31 | Copyright (c) 2015 Alexis Marquet 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy 34 | of this software and associated documentation files (the "Software"), to deal 35 | in the Software without restriction, including without limitation the rights 36 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 37 | copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in 41 | all copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 48 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 49 | THE SOFTWARE. 50 | */ 51 | -------------------------------------------------------------------------------- /08_test_CXX/proc/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)proc_init.o $(OBJ)UART.o $(OBJ)GPIO.o $(OBJ)control_module.o $(OBJ)clock_module.o $(OBJ)pad.o $(OBJ)proc_Handlers.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)proc.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)proc_init.o: proc_init.c 11 | $(CHAIN)gcc $(CFLAGS) -c proc_init.c -o $(OBJ)proc_init.o 12 | 13 | $(OBJ)proc_Handlers.o: proc_Handlers.c 14 | $(CHAIN)gcc $(CFLAGS) -c proc_Handlers.c -o $(OBJ)proc_Handlers.o 15 | 16 | $(OBJ)GPIO.o: GPIO.c 17 | $(CHAIN)gcc $(CFLAGS) -c GPIO.c -o $(OBJ)GPIO.o 18 | 19 | $(OBJ)pad.o: pad.c 20 | $(CHAIN)gcc $(CFLAGS) -c pad.c -o $(OBJ)pad.o 21 | 22 | $(OBJ)control_module.o: control_module.c 23 | $(CHAIN)gcc $(CFLAGS) -c control_module.c -o $(OBJ)control_module.o 24 | 25 | $(OBJ)clock_module.o: clock_module.c 26 | $(CHAIN)gcc $(CFLAGS) -c clock_module.c -o $(OBJ)clock_module.o 27 | 28 | $(OBJ)UART.o: UART.c 29 | $(CHAIN)gcc $(CFLAGS) -c UART.c -o $(OBJ)UART.o 30 | 31 | 32 | clean: 33 | rm -rf $(OBJ)*.o 34 | -------------------------------------------------------------------------------- /08_test_CXX/proc/pad.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pad.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation of the pad control functions: TRM 9.3.51, TRM 9.2.2.1 & Datasheet 4 6 | **/ 7 | 8 | #include "pad.h" 9 | #include "control_module.h" 10 | 11 | 12 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 13 | { 14 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 15 | { 16 | unsigned int temp = CM_getCtrlModule(module); 17 | temp &= ~(0b111); // turn down MUXMODE 18 | temp |= mode; // set new MUXMODE 19 | CM_setCtrlModule(module, temp); 20 | } 21 | else 22 | { 23 | // TODO: raise error (control module isnt a "conf " register) 24 | return; 25 | } 26 | } 27 | pinmode_t PAD_getMode(CONTROL_MODULE module) 28 | { 29 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 30 | { 31 | unsigned int temp = CM_getCtrlModule(module); 32 | temp &= ~(0b111); 33 | return (pinmode_t) temp; 34 | } 35 | else 36 | { 37 | // TODO: raise error (control module isnt a "conf " register) 38 | return -1; 39 | } 40 | } 41 | 42 | 43 | 44 | /* 45 | The MIT License (MIT) 46 | 47 | Copyright (c) 2015 Alexis Marquet 48 | 49 | Permission is hereby granted, free of charge, to any person obtaining a copy 50 | of this software and associated documentation files (the "Software"), to deal 51 | in the Software without restriction, including without limitation the rights 52 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 53 | copies of the Software, and to permit persons to whom the Software is 54 | furnished to do so, subject to the following conditions: 55 | 56 | The above copyright notice and this permission notice shall be included in 57 | all copies or substantial portions of the Software. 58 | 59 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 60 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 61 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 62 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 63 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 64 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 65 | THE SOFTWARE. 66 | */ 67 | -------------------------------------------------------------------------------- /08_test_CXX/proc/pad.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pad.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Types & prototypes of the pad control functions: TRM 9.3.51, TRM 9.2.2.1 & Datasheet 4 6 | **/ 7 | #ifndef __pad_H 8 | #define __pad_H 9 | 10 | 11 | 12 | #include "control_module.h" 13 | 14 | /** 15 | * @brief MUXMODES for pin pads 16 | **/ 17 | typedef enum 18 | { 19 | MODE_0 = 0, 20 | MODE_1 = 1, 21 | MODE_2 = 2, 22 | MODE_3 = 3, 23 | MODE_4 = 4, 24 | MODE_5 = 5, 25 | MODE_6 = 6, 26 | MODE_7 = 7 27 | 28 | }pinmode_t; 29 | 30 | 31 | /** 32 | * @fn void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 33 | * @brief Set a mode to a control module. 34 | * @param[in] module Module to set the mode to. 35 | * @param[in] mode Mode to set the module to. 36 | * @return void 37 | **/ 38 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode); 39 | 40 | 41 | /** 42 | * @fn pinmode_t PAD_getMode(CONTROL_MODULE module) 43 | * @brief Get the mode of a module. 44 | * @param[in] module Module to get the mode from; 45 | * @return mode of this control module 46 | **/ 47 | pinmode_t PAD_getMode(CONTROL_MODULE module); 48 | 49 | 50 | 51 | #endif /* defined(__pad_H) */ 52 | 53 | 54 | 55 | 56 | /* 57 | The MIT License (MIT) 58 | 59 | Copyright (c) 2015 Alexis Marquet 60 | 61 | Permission is hereby granted, free of charge, to any person obtaining a copy 62 | of this software and associated documentation files (the "Software"), to deal 63 | in the Software without restriction, including without limitation the rights 64 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 65 | copies of the Software, and to permit persons to whom the Software is 66 | furnished to do so, subject to the following conditions: 67 | 68 | The above copyright notice and this permission notice shall be included in 69 | all copies or substantial portions of the Software. 70 | 71 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 72 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 73 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 74 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 75 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 76 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 77 | THE SOFTWARE. 78 | */ 79 | -------------------------------------------------------------------------------- /08_test_CXX/proc/proc_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file proc_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief Initialize the processor and its needed peripherals 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "UART.h" 10 | #include 11 | 12 | #define NVIC 0x48200000 13 | #define CM_WKUP 0x44E00400 14 | 15 | void procInit() 16 | { 17 | 18 | 19 | 20 | /* peripherals */ 21 | PUT32(0x47400000+0x10,1); // reset USB controller to get the internet connection back 22 | 23 | PUT32(NVIC+0x10,1); // reset INTC controller 24 | while((GET32(NVIC+0x14)&0x1)==0); // wait until reset is done 25 | 26 | PUT32(NVIC+0x68,0xFF); // disable interrupt threshold 27 | PUT32(NVIC+0x50,1); // enable functional clock 28 | 29 | PUT32(NVIC+0x94,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 30 | PUT32(NVIC+0xB4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 31 | PUT32(NVIC+0xD4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 32 | PUT32(NVIC+0xF4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 33 | 34 | CPU_irqE(); 35 | 36 | UART_initUART(UART0,115200,STOP1,PARITY_NONE,FLOW_OFF); 37 | 38 | UART_putString(UART0,"$UART0 Initialized... compiled at " __TIME__ "\n",43); 39 | } -------------------------------------------------------------------------------- /08_test_CXX/sys/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)types.o $(OBJ)syscalls.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)sys.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)types.o: types.c 11 | $(CHAIN)gcc $(CFLAGS) -c types.c -o $(OBJ)types.o 12 | 13 | $(OBJ)syscalls.o: syscalls.c 14 | $(CHAIN)gcc $(CFLAGS) -c syscalls.c -o $(OBJ)syscalls.o 15 | 16 | 17 | clean: 18 | rm -rf $(OBJ)*.o 19 | -------------------------------------------------------------------------------- /08_test_CXX/sys/types.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file types.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief Dummy file for consistency with hierarchy 6 | **/ 7 | 8 | void types (void) 9 | { 10 | 11 | } -------------------------------------------------------------------------------- /08_test_CXX/sys/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file types.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Standard types declaration 6 | **/ 7 | 8 | #ifndef __types_H 9 | #define __types_H 10 | 11 | 12 | /** 13 | @brief boolean (true/false) 14 | **/ 15 | typedef enum 16 | { 17 | true = 1, 18 | false = 0 19 | }bool; 20 | 21 | 22 | 23 | #endif 24 | 25 | 26 | 27 | /* 28 | The MIT License (MIT) 29 | 30 | Copyright (c) 2015 Alexis Marquet 31 | 32 | Permission is hereby granted, free of charge, to any person obtaining a copy 33 | of this software and associated documentation files (the "Software"), to deal 34 | in the Software without restriction, including without limitation the rights 35 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 36 | copies of the Software, and to permit persons to whom the Software is 37 | furnished to do so, subject to the following conditions: 38 | 39 | The above copyright notice and this permission notice shall be included in 40 | all copies or substantial portions of the Software. 41 | 42 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 45 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 46 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 47 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 48 | THE SOFTWARE. 49 | */ 50 | -------------------------------------------------------------------------------- /09_USB_Bootloader/README.md: -------------------------------------------------------------------------------- 1 | 09_USB_Bootloader 2 | ============== 3 | 4 | 09_USB_Bootloader: This example implements a USB DFU bootloader. the device is connected via the mini USB port on the board (USB0) and 5 | enumerates itself as a DFU capable device. you then need to use dfu-util (http://dfu-util.sourceforge.net/) to download your code to the device. 6 | The code is launched from 0x80000000, like it was in 07_Bootloader. This bootloader is about 20 times faster than the previous one, which was 7 | run via UART0. -------------------------------------------------------------------------------- /09_USB_Bootloader/bin/spl.boot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/09_USB_Bootloader/bin/spl.boot -------------------------------------------------------------------------------- /09_USB_Bootloader/board/board_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file /board/board_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief board initialisation. every component that is NOT the SoC but is on the board must be init here. 6 | **/ 7 | 8 | #include "LED.h" 9 | 10 | void boardInit() 11 | { 12 | LED_init(); 13 | } 14 | 15 | /* 16 | The MIT License (MIT) 17 | 18 | Copyright (c) 2015 Alexis Marquet 19 | 20 | Permission is hereby granted, free of charge, to any person obtaining a copy 21 | of this software and associated documentation files (the "Software"), to deal 22 | in the Software without restriction, including without limitation the rights 23 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | copies of the Software, and to permit persons to whom the Software is 25 | furnished to do so, subject to the following conditions: 26 | 27 | The above copyright notice and this permission notice shall be included in 28 | all copies or substantial portions of the Software. 29 | 30 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 36 | THE SOFTWARE. 37 | */ 38 | -------------------------------------------------------------------------------- /09_USB_Bootloader/board/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)board_init.o $(OBJ)LED.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)board.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)LED.o: LED.c 11 | $(CHAIN)gcc $(CFLAGS) -c LED.c -o $(OBJ)LED.o 12 | 13 | $(OBJ)board_init.o: board_init.c 14 | $(CHAIN)gcc $(CFLAGS) -c board_init.c -o $(OBJ)board_init.o 15 | 16 | clean: 17 | rm -rf $(OBJ)*.o 18 | -------------------------------------------------------------------------------- /09_USB_Bootloader/core/core_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file core_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief this function is the core init function. its the first function do be called from the startup. 6 | * 7 | * @note the bss is already initialized at this point. 8 | **/ 9 | #include "llma.h" 10 | 11 | 12 | void coreInit() 13 | { 14 | CPU_irqD(); // disable interrupt 15 | } 16 | 17 | 18 | 19 | 20 | /* 21 | The MIT License (MIT) 22 | 23 | Copyright (c) 2015 Alexis Marquet 24 | 25 | Permission is hereby granted, free of charge, to any person obtaining a copy 26 | of this software and associated documentation files (the "Software"), to deal 27 | in the Software without restriction, including without limitation the rights 28 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 29 | copies of the Software, and to permit persons to whom the Software is 30 | furnished to do so, subject to the following conditions: 31 | 32 | The above copyright notice and this permission notice shall be included in 33 | all copies or substantial portions of the Software. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 38 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 40 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 41 | THE SOFTWARE. 42 | */ 43 | -------------------------------------------------------------------------------- /09_USB_Bootloader/core/llma.s: -------------------------------------------------------------------------------- 1 | /** 2 | * @file llma.s 3 | * @author Alexis Marquet 4 | * @date 27 Feb 2015 5 | * @brief contains Low Level Memory Access functions 6 | **/ 7 | 8 | 9 | .globl PUT32 10 | PUT32: 11 | str r1,[r0] 12 | bx lr 13 | 14 | .globl GET32 15 | GET32: 16 | ldr r0,[r0] 17 | bx lr 18 | 19 | .globl PUT16 20 | PUT16: 21 | strh r1,[r0] 22 | bx lr 23 | 24 | .globl GET16 25 | GET16: 26 | ldrh r0,[r0] 27 | bx lr 28 | 29 | .globl PUT8 30 | PUT8: 31 | strb r1,[r0] 32 | bx lr 33 | 34 | .globl GET8 35 | GET8: 36 | ldrb r0,[r0] 37 | bx lr 38 | 39 | .globl dummy 40 | dummy: 41 | bx lr 42 | 43 | 44 | .globl BRANCHTO 45 | BRANCHTO: 46 | DMB 47 | ISB 48 | DSB 49 | mov pc, r0 50 | bx lr //never happens 51 | 52 | 53 | .globl CPU_irqE 54 | CPU_irqE: 55 | dsb 56 | mrs r0, cpsr 57 | bic r0, r0, #0x80 58 | msr cpsr_c, r0 59 | DSB 60 | ISB 61 | bx lr 62 | 63 | .globl CPU_irqD 64 | CPU_irqD: 65 | dsb 66 | mrs r0, cpsr 67 | orr r0, r0, #0x80 68 | msr cpsr_c, r0 69 | DSB 70 | ISB 71 | bx lr 72 | 73 | /* 74 | The MIT License (MIT) 75 | 76 | Copyright (c) 2015 Alexis Marquet 77 | 78 | Permission is hereby granted, free of charge, to any person obtaining a copy 79 | of this software and associated documentation files (the "Software"), to deal 80 | in the Software without restriction, including without limitation the rights 81 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 82 | copies of the Software, and to permit persons to whom the Software is 83 | furnished to do so, subject to the following conditions: 84 | 85 | The above copyright notice and this permission notice shall be included in 86 | all copies or substantial portions of the Software. 87 | 88 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 89 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 90 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 91 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 92 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 93 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 94 | THE SOFTWARE. 95 | */ 96 | -------------------------------------------------------------------------------- /09_USB_Bootloader/core/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)startup_ARMCA8.o1 $(OBJ)core_handlers.o $(OBJ)llma.o $(OBJ)core_init.o $(OBJ)__aeabi.o 5 | $(CHAIN)ld -r $(OBJ)startup_ARMCA8.o1 $(OBJ)*.o -o $(PARENTOBJ)core.o 6 | 7 | 8 | 9 | dir: 10 | @mkdir -p $(OBJ) 11 | 12 | $(OBJ)startup_ARMCA8.o1: startup_ARMCA8.s 13 | $(CHAIN)as $(AFLAGS) -c startup_ARMCA8.s -o $(OBJ)startup_ARMCA8.o1 14 | 15 | $(OBJ)core_init.o: core_init.c 16 | $(CHAIN)gcc $(CFLAGS) -c core_init.c -o $(OBJ)core_init.o 17 | 18 | $(OBJ)core_handlers.o: core_handlers.s 19 | $(CHAIN)as $(AFLAGS) -c core_handlers.s -o $(OBJ)core_handlers.o 20 | 21 | $(OBJ)llma.o: llma.s 22 | $(CHAIN)as $(AFLAGS) -c llma.s -o $(OBJ)llma.o 23 | 24 | $(OBJ)__aeabi.o: __aeabi.s 25 | $(CHAIN)as $(AFLAGS) -c __aeabi.s -o $(OBJ)__aeabi.o 26 | 27 | 28 | 29 | 30 | clean: 31 | rm -rf $(OBJ)*.o 32 | 33 | -------------------------------------------------------------------------------- /09_USB_Bootloader/kernel/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.c 3 | * @author Alexis Marquet 4 | * @date 21 May 2015 5 | * @brief contains the main application 6 | **/ 7 | 8 | 9 | /** 10 | * @mainpage 11 | * 09_USB_Bootloader: This example implements a USB DFU bootloader. the device is connected via the mini USB port on the board (USB0) and 12 | * enumerates itself as a DFU capable device. you then need to use dfu-util (http://dfu-util.sourceforge.net/) to download your code to the device. 13 | * The code is launched from 0x80000000, like it was in 07_Bootloader. This bootloader is about 20 times faster than the previous one, which was 14 | * run via UART0. 15 | **/ 16 | 17 | #include 18 | #include 19 | #include 20 | #include "../core/llma.h" 21 | #include "../proc/clock_module.h" 22 | #include "../proc/interrupt.h" 23 | #include "../proc/USB.h" 24 | #include "../board/LED.h" 25 | #include "../sys/DFU.h" 26 | #include "../sys/types.h" 27 | int main () 28 | { 29 | CPU_irqE(); 30 | USB_init(); 31 | 32 | printf("USB DFU bootloader ready, send FW using \"dfu-util -D \"\n"); 33 | 34 | while(!DFU_update_ready){ 35 | asm volatile ("wfi \n"); 36 | } 37 | 38 | printf("about to branchhhhh\n"); 39 | LED_setValue(0x0); 40 | CPU_irqD(); 41 | BRANCHTO(0x80000000); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /09_USB_Bootloader/kernel/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)main.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)kernel.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)main.o: main.c 11 | $(CHAIN)gcc $(CFLAGS) -c main.c -o $(OBJ)main.o 12 | 13 | clean: 14 | rm -rf $(OBJ)*.o 15 | -------------------------------------------------------------------------------- /09_USB_Bootloader/makefile: -------------------------------------------------------------------------------- 1 | CHAINPATH=@/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/bin/ 2 | CHAIN=$(CHAINPATH)arm-none-eabi- 3 | CFLAGS=-std=gnu99 -Wall -mfpu=neon -mhard-float -mcpu=cortex-a8 -O0 -fstack-usage 4 | AFLAGS=-mfpu=neon 5 | OBJ=obj/ 6 | BIN=bin/ 7 | LIBPATH=/usr/local/gcc_arm/gcc-arm-none-eabi-4_8-2014q3/arm-none-eabi/lib/fpu/ 8 | 9 | COPYARG=CHAIN="$(CHAIN)" CFLAGS="$(CFLAGS)" AFLAGS="$(AFLAGS)" 10 | 11 | all: dir $(OBJ)core.o $(OBJ)proc.o $(OBJ)board.o $(OBJ)sys.o $(OBJ)kernel.o 12 | @rm -rf $(BIN)*.boot 13 | @echo "assembling output file..." 14 | $(CHAIN)ld -T memmap.ld $(OBJ)core.o $(OBJ)proc.o $(OBJ)board.o $(OBJ)sys.o $(OBJ)kernel.o -L $(LIBPATH) -l"c" -l"m" -o $(OBJ)main.elf 15 | $(CHAIN)objcopy $(OBJ)main.elf $(BIN)spl.boot -O binary 16 | @echo "done!" 17 | 18 | dir: 19 | @mkdir -p $(OBJ) $(BIN) 20 | 21 | $(OBJ)core.o: force_look 22 | @echo "building core/" 23 | @cd core/ ; $(MAKE) $(MFLAGS) $(COPYARG) 24 | 25 | $(OBJ)proc.o: force_look 26 | @echo "building proc/" 27 | @cd proc/ ; $(MAKE) $(MFLAGS) $(COPYARG) 28 | 29 | $(OBJ)board.o: force_look 30 | @echo "building board/" 31 | @cd board/ ; $(MAKE) $(MFLAGS) $(COPYARG) 32 | 33 | $(OBJ)sys.o: force_look 34 | @echo "building sys/" 35 | @cd sys/ ; $(MAKE) $(MFLAGS) $(COPYARG) 36 | 37 | $(OBJ)kernel.o: force_look 38 | @echo "building kernel/" 39 | @cd kernel/ ; $(MAKE) $(MFLAGS) $(COPYARG) 40 | 41 | force_look: 42 | @true 43 | 44 | copy: 45 | @echo "copying boot file..." 46 | @cp $(BIN)spl.boot ../boot 47 | @echo "done" 48 | 49 | clean: 50 | @echo "cleaning up..." 51 | @rm -rf $(OBJ)*.o 52 | @rm -rf $(OBJ)*.elf 53 | @rm -rf $(BIN)*.boot 54 | @rm -rf ../boot/*.boot 55 | @rm -rf core/obj/* 56 | @rm -rf proc/obj/* 57 | @rm -rf board/obj/* 58 | @rm -rf sys/obj/* 59 | @rm -rf kernel/obj/* 60 | @echo "done!" 61 | 62 | dump: 63 | $(CHAIN)objdump -D $(OBJ)main.elf -------------------------------------------------------------------------------- /09_USB_Bootloader/proc/DDR.h: -------------------------------------------------------------------------------- 1 | // 2 | // DDR.h 3 | // 4 | // 5 | // Created by Alexis Marquet on 29/04/15. 6 | // 7 | // 8 | 9 | #ifndef ____DDR__ 10 | #define ____DDR__ 11 | 12 | #include 13 | 14 | 15 | void config_ddr_x(void); 16 | 17 | #endif /* defined(____DDR__) */ 18 | -------------------------------------------------------------------------------- /09_USB_Bootloader/proc/EMIF.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef ____EMIF__ 4 | #define ____EMIF__ 5 | 6 | void DDR3_EMIF_Config(); 7 | 8 | 9 | #endif /* defined(____EMIF__) */ 10 | -------------------------------------------------------------------------------- /09_USB_Bootloader/proc/PLL.h: -------------------------------------------------------------------------------- 1 | // 2 | // PLL.h 3 | // 4 | // 5 | // Created by Alexis Marquet on 28/04/15. 6 | // 7 | // 8 | 9 | #ifndef ____PLL__ 10 | #define ____PLL__ 11 | 12 | #include 13 | 14 | uint32_t GetInputClockFrequency(); 15 | 16 | void MPU_PLL_Config(uint32_t clkin, uint32_t n, uint32_t m, uint32_t m2); 17 | 18 | void CORE_PLL_Config(uint32_t clkin, uint32_t n, uint32_t m, uint32_t m4, uint32_t m5, uint32_t m6); 19 | 20 | void DDR_PLL_Config(uint32_t clkin, uint32_t n, uint32_t m, uint32_t m2); 21 | 22 | void PER_PLL_Config(uint32_t clkin, uint32_t n, uint32_t m, uint32_t m2); 23 | 24 | void DISP_PLL_Config(uint32_t clkin, uint32_t n, uint32_t m, uint32_t m2); 25 | 26 | #endif /* defined(____PLL__) */ 27 | -------------------------------------------------------------------------------- /09_USB_Bootloader/proc/clock_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file clock_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning clock module usage: TRM 8 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "../sys/types.h" 10 | #include "clock_module.h" 11 | 12 | 13 | // TODO: implement module/reg validity check 14 | 15 | void CKM_setCLKModuleRegister(CLK_MODULE_t module, CKM_MODULE_REG reg, unsigned int value) 16 | { 17 | unsigned int addr_temp = module + reg; // clock module base + module offset, TRM 2.1 & 8.1.12.1 18 | PUT32(addr_temp, value); 19 | } 20 | unsigned int CKM_getCLKModuleRegister(CLK_MODULE_t module, CKM_MODULE_REG reg) 21 | { 22 | 23 | unsigned int addr_temp = module + reg; // clock module base + module offset, TRM 2.1 & 8.1.12.1 24 | return GET32(addr_temp); 25 | 26 | } 27 | 28 | 29 | 30 | /* 31 | The MIT License (MIT) 32 | 33 | Copyright (c) 2015 Alexis Marquet 34 | 35 | Permission is hereby granted, free of charge, to any person obtaining a copy 36 | of this software and associated documentation files (the "Software"), to deal 37 | in the Software without restriction, including without limitation the rights 38 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | copies of the Software, and to permit persons to whom the Software is 40 | furnished to do so, subject to the following conditions: 41 | 42 | The above copyright notice and this permission notice shall be included in 43 | all copies or substantial portions of the Software. 44 | 45 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 | THE SOFTWARE. 52 | */ 53 | -------------------------------------------------------------------------------- /09_USB_Bootloader/proc/control_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file control_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning control module usage: TRM 9, TRM 9.3 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "control_module.h" 10 | 11 | #define CM_MODULE_REGISTER_BASE 0x44E10000 12 | 13 | 14 | void CM_setCtrlModule(CONTROL_MODULE module, unsigned int value) 15 | { 16 | PUT32(CM_MODULE_REGISTER_BASE + module, value); 17 | } 18 | 19 | unsigned int CM_getCtrlModule(CONTROL_MODULE module) 20 | { 21 | return GET32(CM_MODULE_REGISTER_BASE + module); 22 | } 23 | 24 | 25 | 26 | 27 | 28 | /* 29 | The MIT License (MIT) 30 | 31 | Copyright (c) 2015 Alexis Marquet 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy 34 | of this software and associated documentation files (the "Software"), to deal 35 | in the Software without restriction, including without limitation the rights 36 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 37 | copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in 41 | all copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 48 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 49 | THE SOFTWARE. 50 | */ 51 | -------------------------------------------------------------------------------- /09_USB_Bootloader/proc/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)proc_init.o $(OBJ)UART.o $(OBJ)GPIO.o $(OBJ)control_module.o $(OBJ)clock_module.o $(OBJ)pad.o $(OBJ)proc_Handlers.o $(OBJ)PLL.o $(OBJ)EMIF.o $(OBJ)DDR.o $(OBJ)USB.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)proc.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)proc_init.o: proc_init.c 11 | $(CHAIN)gcc $(CFLAGS) -c proc_init.c -o $(OBJ)proc_init.o 12 | 13 | $(OBJ)proc_Handlers.o: proc_Handlers.c 14 | $(CHAIN)gcc $(CFLAGS) -c proc_Handlers.c -o $(OBJ)proc_Handlers.o 15 | 16 | $(OBJ)GPIO.o: GPIO.c 17 | $(CHAIN)gcc $(CFLAGS) -c GPIO.c -o $(OBJ)GPIO.o 18 | 19 | $(OBJ)pad.o: pad.c 20 | $(CHAIN)gcc $(CFLAGS) -c pad.c -o $(OBJ)pad.o 21 | 22 | $(OBJ)control_module.o: control_module.c 23 | $(CHAIN)gcc $(CFLAGS) -c control_module.c -o $(OBJ)control_module.o 24 | 25 | $(OBJ)clock_module.o: clock_module.c 26 | $(CHAIN)gcc $(CFLAGS) -c clock_module.c -o $(OBJ)clock_module.o 27 | 28 | $(OBJ)UART.o: UART.c 29 | $(CHAIN)gcc $(CFLAGS) -c UART.c -o $(OBJ)UART.o 30 | 31 | $(OBJ)PLL.o: PLL.c 32 | $(CHAIN)gcc $(CFLAGS) -c PLL.c -o $(OBJ)PLL.o 33 | 34 | $(OBJ)EMIF.o: EMIF.c 35 | $(CHAIN)gcc $(CFLAGS) -c EMIF.c -o $(OBJ)EMIF.o 36 | 37 | $(OBJ)DDR.o: DDR.c 38 | $(CHAIN)gcc $(CFLAGS) -c DDR.c -o $(OBJ)DDR.o 39 | 40 | $(OBJ)USB.o: USB.c 41 | $(CHAIN)gcc $(CFLAGS) -c USB.c -o $(OBJ)USB.o 42 | 43 | clean: 44 | rm -rf $(OBJ)*.o 45 | -------------------------------------------------------------------------------- /09_USB_Bootloader/proc/pad.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pad.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation of the pad control functions: TRM 9.3.51, TRM 9.2.2.1 & Datasheet 4 6 | **/ 7 | 8 | #include "pad.h" 9 | #include "control_module.h" 10 | 11 | 12 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 13 | { 14 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 15 | { 16 | unsigned int temp = CM_getCtrlModule(module); 17 | temp &= ~(0b111); // turn down MUXMODE 18 | temp |= mode; // set new MUXMODE 19 | CM_setCtrlModule(module, temp); 20 | } 21 | else 22 | { 23 | // TODO: raise error (control module isnt a "conf " register) 24 | return; 25 | } 26 | } 27 | pinmode_t PAD_getMode(CONTROL_MODULE module) 28 | { 29 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 30 | { 31 | unsigned int temp = CM_getCtrlModule(module); 32 | temp &= ~(0b111); 33 | return (pinmode_t) temp; 34 | } 35 | else 36 | { 37 | // TODO: raise error (control module isnt a "conf " register) 38 | return -1; 39 | } 40 | } 41 | 42 | 43 | 44 | /* 45 | The MIT License (MIT) 46 | 47 | Copyright (c) 2015 Alexis Marquet 48 | 49 | Permission is hereby granted, free of charge, to any person obtaining a copy 50 | of this software and associated documentation files (the "Software"), to deal 51 | in the Software without restriction, including without limitation the rights 52 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 53 | copies of the Software, and to permit persons to whom the Software is 54 | furnished to do so, subject to the following conditions: 55 | 56 | The above copyright notice and this permission notice shall be included in 57 | all copies or substantial portions of the Software. 58 | 59 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 60 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 61 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 62 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 63 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 64 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 65 | THE SOFTWARE. 66 | */ 67 | -------------------------------------------------------------------------------- /09_USB_Bootloader/proc/proc_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file proc_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief Initialize the processor and its needed peripherals 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "UART.h" 10 | #include "PLL.h" 11 | #include "EMIF.h" 12 | #include "DDR.h" 13 | #include 14 | 15 | #define NVIC 0x48200000 16 | #define CM_WKUP 0x44E00400 17 | 18 | void procInit() 19 | { 20 | 21 | 22 | 23 | /* peripherals */ 24 | PUT32(0x47400000+0x10,1); // reset USB controller to get the internet connection back 25 | 26 | PUT32(NVIC+0x10,1); // reset INTC controller 27 | while((GET32(NVIC+0x14)&0x1)==0); // wait until reset is done 28 | 29 | PUT32(NVIC+0x68,0xFF); // disable interrupt threshold 30 | PUT32(NVIC+0x50,1); // enable functional clock 31 | 32 | PUT32(NVIC+0x94,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 33 | PUT32(NVIC+0xB4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 34 | PUT32(NVIC+0xD4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 35 | PUT32(NVIC+0xF4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 36 | 37 | CPU_irqE(); 38 | 39 | UART_initUART(UART0,115200,STOP1,PARITY_NONE,FLOW_OFF); 40 | 41 | UART_putString(UART0,"$UART0 Initialized... compiled on " __DATE__ " at " __TIME__ "\n",58); 42 | 43 | 44 | uint32_t clkin = GetInputClockFrequency(); 45 | if(clkin==24) 46 | { 47 | MPU_PLL_Config (clkin, 23, 500, 1); 48 | CORE_PLL_Config(clkin, 23, 1000, 10, 8, 4); 49 | DDR_PLL_Config (clkin, 23, 400, 1); 50 | PER_PLL_Config (clkin, 23, 960, 5); 51 | DISP_PLL_Config(clkin, 23, 48, 1); 52 | } 53 | else 54 | { 55 | printf("error, clkin invalid\n"); 56 | while(1); 57 | } 58 | //RAM 59 | DDR3_EMIF_Config(); 60 | config_ddr_x();// this works 61 | } -------------------------------------------------------------------------------- /09_USB_Bootloader/sys/DFU.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DFU.h 3 | * @author Alexis Marquet 4 | * @date 21 May 2015 5 | * @brief Types and declarations for DFU module. reference: UNIVERSAL SERIAL BUS, DEVICE CLASS SPECIFICATION FOR DEVICE FIRMWARE UPGRADE.pdf V1.1 6 | * The DFU class is a bit different than the other USB classes, as it communicates via ENDP0 (control endpoint) instead of a 7 | * dedicated endpoint. the code in DFU.* and USB.* is very linked to each other. 8 | **/ 9 | 10 | #ifndef ____DFU__ 11 | #define ____DFU__ 12 | 13 | #include 14 | #include "../proc/USB.h" 15 | #include "types.h" 16 | 17 | 18 | /** 19 | * @brief uncomment this line to print DFU Debug information 20 | **/ 21 | // #define DFU_DEBUG 22 | 23 | 24 | /** 25 | * @brief DFU functional Descriptor, USB_DFU 4.1.3 26 | **/ 27 | struct USBDFUFunctionalDescriptor 28 | { 29 | #pragma pack(1) 30 | uint8_t bLength; 31 | uint8_t bDescriptorType; 32 | uint8_t bmAttributes; 33 | uint16_t wDetachTimeOut; 34 | uint16_t wTransferSize; 35 | uint16_t bcdDFUVersion; 36 | }; 37 | 38 | 39 | /** 40 | * @brief DFU GetState request answer, USB_DFU 6.1.2 41 | **/ 42 | struct USBDFU_GETSTATE_Answer 43 | { 44 | #pragma pack(1) 45 | uint8_t bStatus; 46 | uint8_t bwPollTimeout[3]; 47 | uint8_t bState; 48 | uint8_t iString; 49 | }; 50 | 51 | 52 | /** 53 | * @brief DFU state machine, USB_DFU 6.1.2 54 | **/ 55 | enum USBDFU_State 56 | { 57 | appIDLE = 0x00, 58 | appDETACH = 0x01, 59 | dfuIDLE = 0x02, 60 | dfuDNLOAD_SYNC = 0x03, 61 | dfuDNBUSY = 0x04, 62 | dfuDNLOAD_IDLE = 0x05, 63 | dfuMANIFEST_SYNC = 0x06, 64 | dfuMANIFEST = 0x07, 65 | dfuMANIFEST_WAIT_RESET = 0x08, 66 | dfuUPLOAD_IDLE = 0x09, 67 | dfuERROR = 0x0A 68 | }; 69 | 70 | const struct USBDFUFunctionalDescriptor DFUFunc; 71 | 72 | /** 73 | * @brief boolead is true when DFU has downloader all the firmware and put it in the ram (0x80000000). 74 | **/ 75 | bool DFU_update_ready; 76 | 77 | /** 78 | * @fn void USB_Setup_Class(struct USBSetupPacket s) 79 | * @brief This function is called from the ENDP0 interrupt. it deals with all the DFU class-specific setup packets 80 | * @param[in] s The setup packet containing the DFU specific request 81 | **/ 82 | void USB_Setup_Class(struct USBSetupPacket s); 83 | 84 | #endif /* defined(____DFU__) */ 85 | -------------------------------------------------------------------------------- /09_USB_Bootloader/sys/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)types.o $(OBJ)syscalls.o $(OBJ)DFU.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)sys.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)types.o: types.c 11 | $(CHAIN)gcc $(CFLAGS) -c types.c -o $(OBJ)types.o 12 | 13 | $(OBJ)syscalls.o: syscalls.c 14 | $(CHAIN)gcc $(CFLAGS) -c syscalls.c -o $(OBJ)syscalls.o 15 | 16 | $(OBJ)DFU.o: DFU.c 17 | $(CHAIN)gcc $(CFLAGS) -c DFU.c -o $(OBJ)DFU.o 18 | 19 | 20 | clean: 21 | rm -rf $(OBJ)*.o 22 | -------------------------------------------------------------------------------- /09_USB_Bootloader/sys/types.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file types.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief Dummy file for consistency with hierarchy 6 | **/ 7 | 8 | void types (void) 9 | { 10 | 11 | } -------------------------------------------------------------------------------- /09_USB_Bootloader/sys/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file types.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Standard types declaration 6 | **/ 7 | 8 | #ifndef __types_H 9 | #define __types_H 10 | 11 | 12 | /** 13 | @brief boolean (true/false) 14 | **/ 15 | typedef enum 16 | { 17 | true = 1, 18 | false = 0 19 | }bool; 20 | 21 | 22 | #endif 23 | 24 | 25 | 26 | /* 27 | The MIT License (MIT) 28 | 29 | Copyright (c) 2015 Alexis Marquet 30 | 31 | Permission is hereby granted, free of charge, to any person obtaining a copy 32 | of this software and associated documentation files (the "Software"), to deal 33 | in the Software without restriction, including without limitation the rights 34 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 35 | copies of the Software, and to permit persons to whom the Software is 36 | furnished to do so, subject to the following conditions: 37 | 38 | The above copyright notice and this permission notice shall be included in 39 | all copies or substantial portions of the Software. 40 | 41 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 42 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 43 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 44 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 45 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 46 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 47 | THE SOFTWARE. 48 | */ 49 | -------------------------------------------------------------------------------- /10_I2C/README.md: -------------------------------------------------------------------------------- 1 | 10_I2C 2 | ============== 3 | 4 | 10_i2C: This example implements I2C. a lot of the AM335x I2C-specific are 5 | from the Starterware for Sitara processors, from TI ( http://processors.wiki.ti.com/index.php/StarterWare ). 6 | Their read & write function were not working for me, so I had to rewrite them almost completely.\n 7 | First, The I2C0 part gets initialized. I then probe the bus to see which addresses are Ack-ing the 8 | request. normaly, you should get (on the Beaglebone black) the addresses 0x48 (TPS65217 chip, which is 9 | referenced as addres 0x24 (7bit) in its datasheed), 0x68 (TDA19988 chip, CEC core), and 0xa0 (24LC32A, 10 | the EEPROM chip). I curently have no idea why the HDMI core of the TDA19988 does not answer to its 11 | address (0xE0), and as the chip is under IP, that might be hard to find an answer...\n 12 | Secondly, I set the read pointer on the EEPROM chip to 0x000. I then read the EEPROM_ID 13 | structure from it (referenced in http://processors.wiki.ti.com/index.php/AM335x_Starter_Kit_ID_Memory_Programming ) 14 | and print it.\n 15 | A few notes, the read/write routines did not work after being used aprox. 32 times. the solution 16 | I found was reinitialising the I2C part at the begining of each read/write operation. I still 17 | can't figure out what's causing this bug.\n 18 | -------------------------------------------------------------------------------- /10_I2C/board/EEPROM.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 24XX32A.cpp 3 | * @author Alexis Marquet 4 | * @date 26 May 2015 5 | * @brief Types & function implementation for reading the on-board EEPROM (24XX32A Serial EEPROM). 6 | * The EEPROM can only be read because the WP pin is tied to VDD with a pull-up. 7 | **/ 8 | extern "C" 9 | { 10 | #include 11 | #include 12 | } 13 | #include "../proc/I2C.h" 14 | 15 | #include "EEPROM.h" 16 | 17 | #include 18 | 19 | #define Address_24XX32A (0xa0) 20 | 21 | using namespace std; 22 | 23 | uint32_t EEPROM_read(uint32_t startAddress, uint8_t *b, uint32_t length) 24 | { 25 | uint8_t rxb[5]; 26 | rxb[0] = (uint8_t) startAddress >> 4; 27 | rxb[1] = (uint8_t) startAddress & 0xFF; 28 | 29 | if(I2C_write(I2C0,0xa0,&rxb[0],2)) 30 | { 31 | return I2C_read(I2C0,0xa0,b,length); 32 | } 33 | return 0; 34 | } 35 | 36 | 37 | /* 38 | The MIT License (MIT) 39 | 40 | Copyright (c) 2015 Alexis Marquet 41 | 42 | Permission is hereby granted, free of charge, to any person obtaining a copy 43 | of this software and associated documentation files (the "Software"), to deal 44 | in the Software without restriction, including without limitation the rights 45 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 46 | copies of the Software, and to permit persons to whom the Software is 47 | furnished to do so, subject to the following conditions: 48 | 49 | The above copyright notice and this permission notice shall be included in 50 | all copies or substantial portions of the Software. 51 | 52 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 53 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 54 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 55 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 56 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 57 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 58 | THE SOFTWARE. 59 | */ -------------------------------------------------------------------------------- /10_I2C/board/board_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file /board/board_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief board initialisation. every component that is NOT the SoC but is on the board must be init here. 6 | **/ 7 | 8 | #include "LED.h" 9 | 10 | void boardInit() 11 | { 12 | LED_init(); 13 | } 14 | 15 | /* 16 | The MIT License (MIT) 17 | 18 | Copyright (c) 2015 Alexis Marquet 19 | 20 | Permission is hereby granted, free of charge, to any person obtaining a copy 21 | of this software and associated documentation files (the "Software"), to deal 22 | in the Software without restriction, including without limitation the rights 23 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | copies of the Software, and to permit persons to whom the Software is 25 | furnished to do so, subject to the following conditions: 26 | 27 | The above copyright notice and this permission notice shall be included in 28 | all copies or substantial portions of the Software. 29 | 30 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 36 | THE SOFTWARE. 37 | */ 38 | -------------------------------------------------------------------------------- /10_I2C/board/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)board_init.o $(OBJ)LED.o $(OBJ)EEPROM.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)board.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)LED.o: LED.c 11 | $(CHAIN)gcc $(CFLAGS) -c LED.c -o $(OBJ)LED.o 12 | 13 | $(OBJ)EEPROM.o: EEPROM.cpp 14 | $(CHAIN)g++ $(CPPFLAGS) -c EEPROM.cpp -o $(OBJ)EEPROM.o 15 | 16 | $(OBJ)board_init.o: board_init.c 17 | $(CHAIN)gcc $(CFLAGS) -c board_init.c -o $(OBJ)board_init.o 18 | 19 | clean: 20 | rm -rf $(OBJ)*.o 21 | -------------------------------------------------------------------------------- /10_I2C/core/core_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file core_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief this function is the core init function. its the first function do be called from the startup. 6 | * 7 | * @note the bss is already initialized at this point. 8 | **/ 9 | #include "llma.h" 10 | 11 | 12 | void coreInit() 13 | { 14 | CPU_irqD(); // disable interrupt 15 | } 16 | 17 | 18 | 19 | 20 | /* 21 | The MIT License (MIT) 22 | 23 | Copyright (c) 2015 Alexis Marquet 24 | 25 | Permission is hereby granted, free of charge, to any person obtaining a copy 26 | of this software and associated documentation files (the "Software"), to deal 27 | in the Software without restriction, including without limitation the rights 28 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 29 | copies of the Software, and to permit persons to whom the Software is 30 | furnished to do so, subject to the following conditions: 31 | 32 | The above copyright notice and this permission notice shall be included in 33 | all copies or substantial portions of the Software. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 38 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 40 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 41 | THE SOFTWARE. 42 | */ 43 | -------------------------------------------------------------------------------- /10_I2C/core/llma.s: -------------------------------------------------------------------------------- 1 | /** 2 | * @file llma.s 3 | * @author Alexis Marquet 4 | * @date 27 Feb 2015 5 | * @brief contains Low Level Memory Access functions 6 | **/ 7 | 8 | 9 | .globl PUT32 10 | PUT32: 11 | str r1,[r0] 12 | bx lr 13 | 14 | .globl GET32 15 | GET32: 16 | ldr r0,[r0] 17 | bx lr 18 | 19 | .globl PUT16 20 | PUT16: 21 | strh r1,[r0] 22 | bx lr 23 | 24 | .globl GET16 25 | GET16: 26 | ldrh r0,[r0] 27 | bx lr 28 | 29 | .globl PUT8 30 | PUT8: 31 | strb r1,[r0] 32 | bx lr 33 | 34 | .globl GET8 35 | GET8: 36 | ldrb r0,[r0] 37 | bx lr 38 | 39 | .globl BRANCHTO 40 | BRANCHTO: 41 | mov pc, r0 42 | bx lr //never happens 43 | 44 | 45 | .globl CPU_irqE 46 | CPU_irqE: 47 | dsb 48 | mrs r0, cpsr 49 | bic r0, r0, #0x80 50 | msr cpsr_c, r0 51 | DSB 52 | ISB 53 | bx lr 54 | 55 | .globl CPU_irqD 56 | CPU_irqD: 57 | dsb 58 | mrs r0, cpsr 59 | orr r0, r0, #0x80 60 | msr cpsr_c, r0 61 | DSB 62 | ISB 63 | bx lr 64 | 65 | /* 66 | The MIT License (MIT) 67 | 68 | Copyright (c) 2015 Alexis Marquet 69 | 70 | Permission is hereby granted, free of charge, to any person obtaining a copy 71 | of this software and associated documentation files (the "Software"), to deal 72 | in the Software without restriction, including without limitation the rights 73 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 74 | copies of the Software, and to permit persons to whom the Software is 75 | furnished to do so, subject to the following conditions: 76 | 77 | The above copyright notice and this permission notice shall be included in 78 | all copies or substantial portions of the Software. 79 | 80 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 81 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 82 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 83 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 84 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 85 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 86 | THE SOFTWARE. 87 | */ 88 | -------------------------------------------------------------------------------- /10_I2C/core/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)startup_ARMCA8.o1 $(OBJ)core_handlers.o $(OBJ)llma.o $(OBJ)core_init.o 5 | $(CHAIN)ld -r $(OBJ)startup_ARMCA8.o1 $(OBJ)*.o -o $(PARENTOBJ)core.o 6 | 7 | 8 | 9 | dir: 10 | @mkdir -p $(OBJ) 11 | 12 | $(OBJ)startup_ARMCA8.o1: startup_ARMCA8.s 13 | $(CHAIN)as $(AFLAGS) -c startup_ARMCA8.s -o $(OBJ)startup_ARMCA8.o1 14 | 15 | $(OBJ)core_init.o: core_init.c 16 | $(CHAIN)gcc $(CFLAGS) -c core_init.c -o $(OBJ)core_init.o 17 | 18 | $(OBJ)core_handlers.o: core_handlers.s 19 | $(CHAIN)as $(AFLAGS) -c core_handlers.s -o $(OBJ)core_handlers.o 20 | 21 | $(OBJ)llma.o: llma.s 22 | $(CHAIN)as $(AFLAGS) -c llma.s -o $(OBJ)llma.o 23 | 24 | 25 | 26 | 27 | clean: 28 | rm -rf $(OBJ)*.o 29 | 30 | -------------------------------------------------------------------------------- /10_I2C/kernel/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)main.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)kernel.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)main.o: main.cpp 11 | $(CHAIN)g++ $(CPPFLAGS) -c main.cpp -o $(OBJ)main.o 12 | 13 | clean: 14 | rm -rf $(OBJ)*.o 15 | -------------------------------------------------------------------------------- /10_I2C/proc/clock_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file clock_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning clock module usage: TRM 8 6 | **/ 7 | #include 8 | #include "../core/llma.h" 9 | #include "../sys/types.h" 10 | #include "clock_module.h" 11 | 12 | 13 | 14 | // TODO: implement module/reg validity check 15 | 16 | void CLKM_setCLKModuleRegister(CLK_MODULE_t module, CLK_MODULE_REG reg, uint32_t value) 17 | { 18 | uint32_t addr_temp = module + reg; // clock module base + module offset, TRM 2.1 & 8.1.12.1 19 | PUT32(addr_temp, value); 20 | } 21 | uint32_t CLKM_getCLKModuleRegister(CLK_MODULE_t module, CLK_MODULE_REG reg) 22 | { 23 | 24 | uint32_t addr_temp = module + reg; // clock module base + module offset, TRM 2.1 & 8.1.12.1 25 | return GET32(addr_temp); 26 | 27 | } 28 | 29 | 30 | 31 | /* 32 | The MIT License (MIT) 33 | 34 | Copyright (c) 2015 Alexis Marquet 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a copy 37 | of this software and associated documentation files (the "Software"), to deal 38 | in the Software without restriction, including without limitation the rights 39 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 40 | copies of the Software, and to permit persons to whom the Software is 41 | furnished to do so, subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included in 44 | all copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 49 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 52 | THE SOFTWARE. 53 | */ 54 | -------------------------------------------------------------------------------- /10_I2C/proc/control_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file control_module.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation concerning control module usage: TRM 9, TRM 9.3 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "control_module.h" 10 | 11 | #define CM_MODULE_REGISTER_BASE 0x44E10000 12 | 13 | 14 | void CM_setCtrlModule(CONTROL_MODULE module, uint32_t value) 15 | { 16 | PUT32(CM_MODULE_REGISTER_BASE + module, value); 17 | } 18 | 19 | uint32_t CM_getCtrlModule(CONTROL_MODULE module) 20 | { 21 | return GET32(CM_MODULE_REGISTER_BASE + module); 22 | } 23 | 24 | 25 | 26 | 27 | 28 | /* 29 | The MIT License (MIT) 30 | 31 | Copyright (c) 2015 Alexis Marquet 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy 34 | of this software and associated documentation files (the "Software"), to deal 35 | in the Software without restriction, including without limitation the rights 36 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 37 | copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in 41 | all copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 48 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 49 | THE SOFTWARE. 50 | */ 51 | -------------------------------------------------------------------------------- /10_I2C/proc/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)proc_init.o $(OBJ)UART.o $(OBJ)GPIO.o $(OBJ)control_module.o $(OBJ)clock_module.o $(OBJ)pad.o $(OBJ)proc_Handlers.o $(OBJ)I2C.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)proc.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)proc_init.o: proc_init.c 11 | $(CHAIN)gcc $(CFLAGS) -c proc_init.c -o $(OBJ)proc_init.o 12 | 13 | $(OBJ)proc_Handlers.o: proc_Handlers.c 14 | $(CHAIN)gcc $(CFLAGS) -c proc_Handlers.c -o $(OBJ)proc_Handlers.o 15 | 16 | $(OBJ)GPIO.o: GPIO.c 17 | $(CHAIN)gcc $(CFLAGS) -c GPIO.c -o $(OBJ)GPIO.o 18 | 19 | $(OBJ)pad.o: pad.c 20 | $(CHAIN)gcc $(CFLAGS) -c pad.c -o $(OBJ)pad.o 21 | 22 | $(OBJ)control_module.o: control_module.c 23 | $(CHAIN)gcc $(CFLAGS) -c control_module.c -o $(OBJ)control_module.o 24 | 25 | $(OBJ)clock_module.o: clock_module.c 26 | $(CHAIN)gcc $(CFLAGS) -c clock_module.c -o $(OBJ)clock_module.o 27 | 28 | $(OBJ)UART.o: UART.c 29 | $(CHAIN)gcc $(CFLAGS) -c UART.c -o $(OBJ)UART.o 30 | 31 | $(OBJ)I2C.o: I2C.cpp 32 | $(CHAIN)g++ $(CPPFLAGS) -c I2C.cpp -o $(OBJ)I2C.o 33 | 34 | clean: 35 | rm -rf $(OBJ)*.o 36 | -------------------------------------------------------------------------------- /10_I2C/proc/pad.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pad.c 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Implementation of the pad control functions: TRM 9.3.51, TRM 9.2.2.1 & Datasheet 4 6 | **/ 7 | 8 | #include "pad.h" 9 | #include "control_module.h" 10 | 11 | 12 | void PAD_setMode(CONTROL_MODULE module, pinmode_t mode) 13 | { 14 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 15 | { 16 | uint32_t temp = CM_getCtrlModule(module); 17 | temp &= ~(0b111); // turn down MUXMODE 18 | temp |= mode; // set new MUXMODE 19 | CM_setCtrlModule(module, temp); 20 | } 21 | else 22 | { 23 | // TODO: raise error (control module isnt a "conf " register) 24 | return; 25 | } 26 | } 27 | pinmode_t PAD_getMode(CONTROL_MODULE module) 28 | { 29 | if((module <= CM_conf_usb1_drvvbus ) && (module >= CM_conf_gpmc_ad0)) 30 | { 31 | uint32_t temp = CM_getCtrlModule(module); 32 | temp &= ~(0b111); 33 | return (pinmode_t) temp; 34 | } 35 | else 36 | { 37 | // TODO: raise error (control module isnt a "conf " register) 38 | return -1; 39 | } 40 | } 41 | 42 | 43 | 44 | /* 45 | The MIT License (MIT) 46 | 47 | Copyright (c) 2015 Alexis Marquet 48 | 49 | Permission is hereby granted, free of charge, to any person obtaining a copy 50 | of this software and associated documentation files (the "Software"), to deal 51 | in the Software without restriction, including without limitation the rights 52 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 53 | copies of the Software, and to permit persons to whom the Software is 54 | furnished to do so, subject to the following conditions: 55 | 56 | The above copyright notice and this permission notice shall be included in 57 | all copies or substantial portions of the Software. 58 | 59 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 60 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 61 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 62 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 63 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 64 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 65 | THE SOFTWARE. 66 | */ 67 | -------------------------------------------------------------------------------- /10_I2C/proc/proc_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file proc_init.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief Initialize the processor and its needed peripherals 6 | **/ 7 | 8 | #include "../core/llma.h" 9 | #include "UART.h" 10 | #include 11 | 12 | #define NVIC 0x48200000 13 | #define CM_WKUP 0x44E00400 14 | 15 | void procInit() 16 | { 17 | 18 | 19 | 20 | /* peripherals */ 21 | PUT32(0x47400000+0x10,1); // reset USB controller to get the internet connection back 22 | 23 | PUT32(NVIC+0x10,1); // reset INTC controller 24 | while((GET32(NVIC+0x14)&0x1)==0); // wait until reset is done 25 | 26 | PUT32(NVIC+0x68,0xFF); // disable interrupt threshold 27 | PUT32(NVIC+0x50,1); // enable functional clock 28 | 29 | PUT32(NVIC+0x94,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 30 | PUT32(NVIC+0xB4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 31 | PUT32(NVIC+0xD4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 32 | PUT32(NVIC+0xF4,0xFFFFFFFF); // clear INTC_ISR_CLEAR0 33 | 34 | CPU_irqE(); 35 | 36 | UART_initUART(UART0,115200,STOP1,PARITY_NONE,FLOW_OFF); 37 | 38 | UART_putString(UART0,"$UART0 Initialized...\n",22); 39 | } -------------------------------------------------------------------------------- /10_I2C/sys/makefile: -------------------------------------------------------------------------------- 1 | OBJ=obj/ 2 | PARENTOBJ=../obj/ 3 | 4 | all: dir $(OBJ)types.o $(OBJ)syscalls.o 5 | $(CHAIN)ld -r $(OBJ)*.o -o $(PARENTOBJ)sys.o 6 | 7 | dir: 8 | @mkdir -p $(OBJ) 9 | 10 | $(OBJ)types.o: types.c 11 | $(CHAIN)gcc $(CFLAGS) -c types.c -o $(OBJ)types.o 12 | 13 | $(OBJ)syscalls.o: syscalls.c 14 | $(CHAIN)gcc $(CFLAGS) -c syscalls.c -o $(OBJ)syscalls.o 15 | 16 | 17 | clean: 18 | rm -rf $(OBJ)*.o 19 | -------------------------------------------------------------------------------- /10_I2C/sys/types.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file types.c 3 | * @author Alexis Marquet 4 | * @date 28 Apr 2015 5 | * @brief Dummy file for consistency with hierarchy 6 | **/ 7 | 8 | void types (void) 9 | { 10 | 11 | } -------------------------------------------------------------------------------- /10_I2C/sys/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file types.h 3 | * @author Alexis Marquet 4 | * @date 03 Dec 2014 5 | * @brief Standard types declaration 6 | **/ 7 | 8 | #ifndef __types_H 9 | #define __types_H 10 | 11 | 12 | /** 13 | @brief boolean (true/false) 14 | **/ 15 | typedef enum 16 | { 17 | true = 1, 18 | false = 0 19 | }bool; 20 | 21 | 22 | 23 | #endif 24 | 25 | 26 | 27 | /* 28 | The MIT License (MIT) 29 | 30 | Copyright (c) 2015 Alexis Marquet 31 | 32 | Permission is hereby granted, free of charge, to any person obtaining a copy 33 | of this software and associated documentation files (the "Software"), to deal 34 | in the Software without restriction, including without limitation the rights 35 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 36 | copies of the Software, and to permit persons to whom the Software is 37 | furnished to do so, subject to the following conditions: 38 | 39 | The above copyright notice and this permission notice shall be included in 40 | all copies or substantial portions of the Software. 41 | 42 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 45 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 46 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 47 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 48 | THE SOFTWARE. 49 | */ 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Alexis Marquet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Uboot/MLO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/Uboot/MLO -------------------------------------------------------------------------------- /Uboot/u-boot.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allexoll/BBB-BareMetal/b4ebe9755b1561d2c07ac97aadbbcfaa7ef55c66/Uboot/u-boot.img -------------------------------------------------------------------------------- /Uboot/uEnv.txt: -------------------------------------------------------------------------------- 1 | uenvcmd=setenv loadaddr 0x80000000; fatload mmc 0 ${loadaddr} spl.boot; echo *** Booting to BareMetal ***;go ${loadaddr}; 2 | --------------------------------------------------------------------------------