This commit is contained in:
Romain Goyet
2015-05-06 21:50:01 +02:00
parent cc98a1c094
commit 037c03e85a
15 changed files with 121 additions and 17 deletions

View File

@@ -2,7 +2,8 @@ CC=arm-none-eabi-gcc
LD=arm-none-eabi-ld.bfd
GDB=arm-none-eabi-gdb
OBJCOPY=arm-none-eabi-objcopy
CFLAGS = -Iarch/stm32f429 -Iexternal/freertos/include -Iexternal -Iexternal/freertos/portable/GCC/ARM_CM4F -Iexternal/newlib/libc/include
CFLAGS = -I. -Iinclude -Iexternal/freertos/include -Iexternal -Iexternal/freertos/portable/GCC/ARM_CM4F -Iexternal/newlib/libc/include
#CFLAGS = -I. -Iexternal/freertos/include -Iexternal -Iexternal/freertos/portable/GCC/ARM_CM4F -Iexternal/newlib/libc/include -Iinclude
#-I/Users/romain/local/arm-none-eabi/include
CFLAGS += -std=c99 -g -Wall
#CFLAGS += -march=armv7e-m -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16
@@ -13,14 +14,17 @@ CFLAGS += -target thumbv7em-unknown-eabi -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -ffre
#CFLAGS += -Os -fdata-sections -ffunction-sections
#LDFLAGS += --gc-sections
objs := boot/crt0.o arch/stm32f429/isr.o arch/stm32f429/registers/rcc.o arch/stm32f429/registers/gpio.o arch/stm32f429/registers/spi.o external/freertos/tasks.o external/freertos/list.o external/freertos/queue.o external/freertos/portable/GCC/ARM_CM4F/port.o external/freertos/portable/MemMang/heap_1.o external/newlib/libc/string/memset.o external/newlib/libc/string/memcpy.o
objs := boot/crt0.o
objs += external/freertos/tasks.o external/freertos/list.o external/freertos/queue.o external/freertos/portable/GCC/ARM_CM4F/port.o external/freertos/portable/MemMang/heap_1.o
objs += external/newlib/libc/string/memset.o external/newlib/libc/string/memcpy.o
objs += platform/stm32f429/boot/isr.o platform/stm32f429/registers/gpio.o platform/stm32f429/registers/rcc.o platform/stm32f429/registers/spi.o platform/stm32f429/spi.o
default: clean boot.elf
run: boot.elf
$(GDB) -x gdb_script.gdb boot.elf
test: test.elf
$(GDB) -x test/gdb_script.gdb test.elf
@@ -37,7 +41,7 @@ boot.bin: boot.elf
boot.elf: $(objs) src/lcd_spi.o
@echo "LD $@"
@$(LD) -T boot/stm32f429.ld $(objs) src/lcd_spi.o -o $@
@$(LD) -T platform/stm32f429/boot/flash.ld $(objs) src/lcd_spi.o -o $@
%.o: %.c
@echo "CC $@"

View File

@@ -1,3 +0,0 @@
#include <registers/gpio.h>
#include <registers/rcc.h>
#include <registers/spi.h>

View File

@@ -0,0 +1,3 @@
#include "registers/gpio.h"
#include "registers/rcc.h"
#include "registers/spi.h"

View File

@@ -1,4 +1,4 @@
#include <registers/gpio.h>
#include "gpio.h"
#define GPIOA_BASE 0x40020000
#define GPIOB_BASE 0x40020400

View File

@@ -1,4 +1,4 @@
#include <registers/spi.h>
#include "spi.h"
#define SPI1_BASE 0x40013000
#define SPI2_BASE 0x40003800

View File

@@ -1,3 +1,6 @@
#ifndef STM32F429_REGISTERS_SPI_H
#define STM32F429_REGISTERS_SPI_H 1
#include <stdint.h>
typedef enum {
@@ -67,3 +70,5 @@ SPI_SR_t * SPI_SR(SPI_t spi);
typedef uint16_t SPI_DR_t;
SPI_DR_t * SPI_DR(SPI_t spi);
#endif

5
platform/stm32f429/spi.c Normal file
View File

@@ -0,0 +1,5 @@
#include "spi.h"
void spi_init(spi_port_t * port) {
// Do shit!
}

17
platform/stm32f429/spi.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef STM32F429_SPI_H
#define STM32F429_SPI_H 1
#include <spi.h>
#include <platform/stm32f429/registers/spi.h>
struct spi_port {
struct {
SPI_CR1_t controlRegister1;
// SPI_CR2_t controlRegister1;
} config;
struct {
int b;
} state;
};
#endif

View File

@@ -1,21 +1,30 @@
#include <registers.h>
#include <FreeRTOS.h>
#include <task.h>
#include <timers.h>
#include <semphr.h>
#include <platform/stm32f429/registers.h>
#include <platform/stm32f429/spi.h>
/* This code sends data to the onboard LCD over SPI
*
* The LCD has two interfaces, SPI and direct RGB.
* We'll only use SPI in this one.
*
* The documentation gives the following mapping
* Pin name - LCD-SPI
* NRST - Reset
* PC2 - CSX // Chip select for LCD
* PD13 - DCX // Data/Command register
* PF7 - SCL // SPI Clock
* PF9 - SDI/SDO // MOSI
* The Discovery board has the IM[0-3] pins of the LCD controller
* connected to low, high, high, low = 0b0110. (UM1670 p. 33).
* This tells the LCD controller to expect data this way:
* "4 wire, 8-bit serial, SDA = In/out"
* See ILI9341 p. 63
*
* Now how are the LCD pins connected to the MCU ones?
* The Discovery board doc says this:
* MCU pin - LCD-SPI
* NRST - Reset
* PC2 - CSX // Chip select for LCD
* PD13 - DCX // Data/Command register
* PF7 - SCL // SPI Clock
* PF9 - SDI/SDO // MOSI
*
* See UM1670 p. 19 to 24. */
@@ -46,8 +55,62 @@ void SpiSend(void * pvParameters) {
vTaskDelay(100/portTICK_PERIOD_MS);
}
}
/*
struct spi_port {
// Private data:
.config = {
},
.state = {
}
};
// Public API, private impl.
spi_init();
spi_write();
*/
int main(int argc, char * argv[]) {
spi_port_t my_spi_port = {
.config = {
.controlRegister1 = {
.BIDIMODE = 1,
.BIDIOE = 1,
.MSTR = 1,
.DFF = SPI_DFF_16_BITS,
.CPOL = 0,
.BR = SPI_BR_DIV_256,
.SSM = 1,
.SSI = 1,
.SPE = 1
}
}
};
spi_init(&my_spi_port);
/*
// Code we'd like to write:
spi_port my_spi_port;
spi_init(&my_spi_port);
ili9431 lcd_panel = {
.port = my_spi_port
};
ili9431_init(&lcd_panel);
lcd_panel.clear();
lcd_panel.setGammaCurve();
char * fb = lcd_panel.framebuffer;
for (int i=0;i<100;i++) {
*fb[i] = 1;
}
*/
// We'll use GPIO pins F6-F9 to emit SPI data
// GPIO are grouped by letter. All GPIO groups live on the "AHB1" bus.
// (this is documented in the STM32F4 reference mnual, page 65)
@@ -55,6 +118,16 @@ int main(int argc, char * argv[]) {
// Step 1 : Enable clock in RCC_AHBxENR
RCC_AHB1ENR->GPIOFEN = 1;
// Step 2 : Set the GPIO pin C2 as output
RCC_AHB1ENR->GPIOCEN = 1;
GPIO_MODER(GPIOC)->MODER2 = GPIO_MODE_OUTPUT;
RCC_AHB1ENR->GPIOCEN = 1;
GPIO_MODER(GPIOC)->MODER2 = GPIO_MODE_OUTPUT;
// From now on, we'll control pin C2 with
// GPIO_ODR(GPIOC)->ODR2 = desiredValue;
// Step 2 : Configure the GPIO pin to "Alternate function number 5"
// This means "SPI5 on pins F6-F9", cf STM32F249 p78
GPIO_MODER(GPIOF)->MODER6 = GPIO_MODE_ALTERNATE_FUNCTION;