diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..5761abcfd --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.o diff --git a/Makefile b/Makefile index e029093ee..8ba214344 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ GDB=arm-none-eabi-gdb OBJCOPY=arm-none-eabi-objcopy CFLAGS=-march=armv7e-m -mcpu=cortex-m4 -mthumb -std=c99 -g -Iarch/stm32f429 -objs := boot/crt0.o src/blinky.o arch/stm32f429/registers.o +objs := boot/crt0.o src/blinky.o arch/stm32f429/registers/rcc.o arch/stm32f429/registers/gpio.o run: boot.elf $(GDB) -x gdb_script.gdb boot.elf diff --git a/arch/stm32f429/registers.c b/arch/stm32f429/registers.c deleted file mode 100644 index 4b58ddb5e..000000000 --- a/arch/stm32f429/registers.c +++ /dev/null @@ -1,2 +0,0 @@ -#define RCC_BASE 0x40023800 -void * RCC_AHB1ENR = (void *)(RCC_BASE + 0x30); diff --git a/arch/stm32f429/registers.h b/arch/stm32f429/registers.h index e09e4d893..709b3abca 100644 --- a/arch/stm32f429/registers.h +++ b/arch/stm32f429/registers.h @@ -1,30 +1,2 @@ -extern struct { - unsigned int GPIOAEN:1; - unsigned int GPIOBEN:1; - unsigned int GPIOCEN:1; - unsigned int GPIODEN:1; - unsigned int GPIOEEN:1; - unsigned int GPIOFEN:1; - unsigned int GPIOGEN:1; - unsigned int GPIOHEN:1; - unsigned int GPIOIEN:1; - unsigned int GPIOJEN:1; - unsigned int GPIOKEN:1; - unsigned int :1; - unsigned int CRCEN:1; - unsigned int :5; - unsigned int BKPSRAMEN:1; - unsigned int :1; - unsigned int CCMDATARAMEN:1; - unsigned int DMA1EN:1; - unsigned int DMA2EN:1; - unsigned int DMA2DEN:1; - unsigned int :1; - unsigned int ETHMACEN:1; - unsigned int ETHMACTXEN:1; - unsigned int ETHMACRXEN:1; - unsigned int ETHMACPTPEN:1; - unsigned int OTGHSEN:1; - unsigned int OTGHSULPIEN:1; - unsigned int :1; -} * RCC_AHB1ENR; +#include +#include diff --git a/arch/stm32f429/registers.o b/arch/stm32f429/registers.o deleted file mode 100644 index 5ad9f2d7d..000000000 Binary files a/arch/stm32f429/registers.o and /dev/null differ diff --git a/arch/stm32f429/registers/gpio.c b/arch/stm32f429/registers/gpio.c new file mode 100644 index 000000000..e6fff28ff --- /dev/null +++ b/arch/stm32f429/registers/gpio.c @@ -0,0 +1,51 @@ +#include + +#define GPIOA_BASE 0x40020000 +GPIO_MODER_t * GPIOA_MODER = (void *)(GPIOA_BASE); + +#define GPIOB_BASE 0x40020400 +GPIO_MODER_t * GPIOB_MODER = (GPIO_MODER_t *)(GPIOB_BASE); + +#define GPIOC_BASE 0x40020800 +GPIO_MODER_t * GPIOC_MODER = (GPIO_MODER_t *)(GPIOC_BASE); + +#define GPIOD_BASE 0x40020C00 +GPIO_MODER_t * GPIOD_MODER = (GPIO_MODER_t *)(GPIOD_BASE); + +#define GPIOE_BASE 0x40021000 +GPIO_MODER_t * GPIOE_MODER = (GPIO_MODER_t *)(GPIOE_BASE); + +#define GPIOF_BASE 0x40021400 +GPIO_MODER_t * GPIOF_MODER = (GPIO_MODER_t *)(GPIOF_BASE); + +#define GPIOG_BASE 0x40021800 +GPIO_MODER_t * GPIOG_MODER = (GPIO_MODER_t *)(GPIOG_BASE); + +#define GPIOH_BASE 0x40021C00 +GPIO_MODER_t * GPIOH_MODER = (GPIO_MODER_t *)(GPIOH_BASE); + +#define GPIOI_BASE 0x40022000 +GPIO_MODER_t * GPIOI_MODER = (GPIO_MODER_t *)(GPIOI_BASE); + +#define GPIOJ_BASE 0x40022400 +GPIO_MODER_t * GPIOJ_MODER = (GPIO_MODER_t *)(GPIOJ_BASE); + +#define GPIOK_BASE 0x40022800 +GPIO_MODER_t * GPIOK_MODER = (GPIO_MODER_t *)(GPIOK_BASE); + +GPIO_MODER_t * GPIO_MODER(GPIO_t gpio) { + GPIO_MODER_t * gpioModeRegisters[11] = { + GPIOA_MODER, + GPIOB_MODER, + GPIOC_MODER, + GPIOD_MODER, + GPIOE_MODER, + GPIOF_MODER, + GPIOG_MODER, + GPIOH_MODER, + GPIOI_MODER, + GPIOJ_MODER, + GPIOK_MODER + }; + return gpioModeRegisters[gpio]; +} diff --git a/arch/stm32f429/registers/gpio.h b/arch/stm32f429/registers/gpio.h new file mode 100644 index 000000000..f2395325e --- /dev/null +++ b/arch/stm32f429/registers/gpio.h @@ -0,0 +1,53 @@ +typedef enum { + GPIO_MODE_INPUT = 0, + GPIO_MODE_OUTPUT = 1, + GPIO_MODE_ALTERNATE_FUNCTION = 2, + GPIO_MODE_ANALOG = 3 +} GPIO_MODE_t; + +typedef struct { + GPIO_MODE_t MODER0:2; + unsigned int MODER1:2; + unsigned int MODER2:2; + unsigned int MODER3:2; + unsigned int MODER4:2; + unsigned int MODER5:2; + unsigned int MODER6:2; + unsigned int MODER7:2; + unsigned int MODER8:2; + unsigned int MODER9:2; + unsigned int MODER10:2; + unsigned int MODER11:2; + unsigned int MODER12:2; + unsigned int MODER13:2; + unsigned int MODER14:2; + unsigned int MODER15:2; +} GPIO_MODER_t; + +typedef enum { + GPIOA = 0, + GPIOB = 1, + GPIOC = 2, + GPIOD = 3, + GPIOE = 4, + GPIOF = 5, + GPIOG = 6, + GPIOH = 7, + GPIOI = 8, + GPIOJ = 9, + GPIOK = 10 +} GPIO_t; + +GPIO_MODER_t * GPIO_MODER(GPIO_t gpio); + +extern GPIO_MODER_t * GPIOA_MODER; +extern GPIO_MODER_t * GPIOB_MODER; +extern GPIO_MODER_t * GPIOC_MODER; +extern GPIO_MODER_t * GPIOD_MODER; +extern GPIO_MODER_t * GPIOE_MODER; +extern GPIO_MODER_t * GPIOF_MODER; +extern GPIO_MODER_t * GPIOG_MODER; +extern GPIO_MODER_t * GPIOH_MODER; +extern GPIO_MODER_t * GPIOI_MODER; +extern GPIO_MODER_t * GPIOJ_MODER; +extern GPIO_MODER_t * GPIOK_MODER; diff --git a/arch/stm32f429/registers/rcc.c b/arch/stm32f429/registers/rcc.c new file mode 100644 index 000000000..7a1b19f32 --- /dev/null +++ b/arch/stm32f429/registers/rcc.c @@ -0,0 +1,7 @@ +// The non-inclusion of rcc.h here is voluntary. +// Since we didn't define a type for RCC_AHB1ENR, we cannot implement it here +// If we don't include rcc.h, we declare a "new" symbol which will happen to match... +//#include + +#define RCC_BASE 0x40023800 +void * RCC_AHB1ENR = (void *)(RCC_BASE + 0x30); diff --git a/arch/stm32f429/registers/rcc.h b/arch/stm32f429/registers/rcc.h new file mode 100644 index 000000000..86fab9618 --- /dev/null +++ b/arch/stm32f429/registers/rcc.h @@ -0,0 +1,32 @@ +/* Sample usage : "RCC_AHB1ENR->GPIOAEN = 1;" will enable the clock on GPIOA.*/ +extern struct { + unsigned int GPIOAEN:1; + unsigned int GPIOBEN:1; + unsigned int GPIOCEN:1; + unsigned int GPIODEN:1; + unsigned int GPIOEEN:1; + unsigned int GPIOFEN:1; + unsigned int GPIOGEN:1; + unsigned int GPIOHEN:1; + unsigned int GPIOIEN:1; + unsigned int GPIOJEN:1; + unsigned int GPIOKEN:1; + unsigned int :1; + unsigned int CRCEN:1; + unsigned int :5; + unsigned int BKPSRAMEN:1; + unsigned int :1; + unsigned int CCMDATARAMEN:1; + unsigned int DMA1EN:1; + unsigned int DMA2EN:1; + unsigned int DMA2DEN:1; + unsigned int :1; + unsigned int ETHMACEN:1; + unsigned int ETHMACTXEN:1; + unsigned int ETHMACRXEN:1; + unsigned int ETHMACPTPEN:1; + unsigned int OTGHSEN:1; + unsigned int OTGHSULPIEN:1; + unsigned int :1; +} * RCC_AHB1ENR; +