1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

Just trying to get a simple 'Hello World' program going (LED flashing)

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1358 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
pip 2010-08-21 17:14:34 +00:00 committed by pip
parent b36d251bd9
commit 519ce846ee
4 changed files with 108 additions and 126 deletions

View File

@ -70,6 +70,8 @@ PIPBEE = ./
PIPBEEINC = $(PIPBEE)/inc
PIOS = ../PiOS
PIOSINC = $(PIOS)/inc
FLIGHTLIB = ../Libraries
FLIGHTLIBINC = ../Libraries/inc
PIOSSTM32F10X = $(PIOS)/STM32F10x
PIOSCOMMON = $(PIOS)/Common
APPLIBDIR = $(PIOSSTM32F10X)/Libraries
@ -95,7 +97,6 @@ SRC += $(PIOSSTM32F10X)/pios_delay.c
SRC += $(PIOSSTM32F10X)/pios_usart.c
SRC += $(PIOSSTM32F10X)/pios_irq.c
SRC += $(PIOSSTM32F10X)/pios_adc.c
SRC += $(PIOSSTM32F10X)/pios_i2c.c
SRC += $(PIOSSTM32F10X)/pios_gpio.c
SRC += $(PIOSSTM32F10X)/pios_spi.c
@ -116,7 +117,6 @@ SRC += $(STMSPDSRCDIR)/stm32f10x_dma.c
SRC += $(STMSPDSRCDIR)/stm32f10x_exti.c
SRC += $(STMSPDSRCDIR)/stm32f10x_flash.c
SRC += $(STMSPDSRCDIR)/stm32f10x_gpio.c
SRC += $(STMSPDSRCDIR)/stm32f10x_i2c.c
SRC += $(STMSPDSRCDIR)/stm32f10x_pwr.c
SRC += $(STMSPDSRCDIR)/stm32f10x_rcc.c
SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c
@ -155,6 +155,7 @@ ASRCARM =
# Each directory must be seperated by a space.
EXTRAINCDIRS += $(PIOS)
EXTRAINCDIRS += $(PIOSINC)
EXTRAINCDIRS += $(FLIGHTLIBINC)
EXTRAINCDIRS += $(PIOSSTM32F10X)
EXTRAINCDIRS += $(PIOSCOMMON)
EXTRAINCDIRS += $(STMSPDINCDIR)
@ -288,7 +289,7 @@ OOCD_EXE=openocd
# debug level
OOCD_CL=-d0
# interface and board/target settings (using the OOCD target-library here)
OOCD_CL+=-f ../Project/OpenOCD/floss-jtag.openpilot.cfg -f ../Project/OpenOCD/stm32.cfg
OOCD_CL+=-f ../Project/OpenOCD/floss-jtag.ahrs.cfg -f ../Project/OpenOCD/stm32.cfg
# initialize
OOCD_CL+=-c init
# show the targets

View File

@ -115,15 +115,15 @@ TIM8 | | | |
//
// See also pios_board.c
//-------------------------
#define PIOS_SPI_OP 0
#define PIOS_SPI_PERIF 0
//-------------------------
// PIOS_USART
//-------------------------
#define PIOS_USART_RX_BUFFER_SIZE 256
#define PIOS_USART_TX_BUFFER_SIZE 256
#define PIOS_COM_AUX 0
#define PIOS_COM_DEBUG PIOS_COM_AUX
#define PIOS_COM_COM 0
#define PIOS_COM_DEBUG PIOS_COM_COM
#if 0
//-------------------------
@ -142,19 +142,19 @@ TIM8 | | | |
#define PIOS_ADC_TEMP_SENSOR_ADC ADC1
#define PIOS_ADC_TEMP_SENSOR_ADC_CHANNEL 1
#define PIOS_ADC_PIN8_GPIO_PORT GPIOB // PB1 (PSU Voltage)
#define PIOS_ADC_PIN8_GPIO_PIN GPIO_Pin_1 // ADC12_IN9
#define PIOS_ADC_PIN8_GPIO_CHANNEL ADC_Channel_9
#define PIOS_ADC_PIN8_ADC ADC2
#define PIOS_ADC_PIN8_ADC_NUMBER 4
#define PIOS_ADC_PIN1_GPIO_PORT GPIOB // PB1 (PSU Voltage)
#define PIOS_ADC_PIN1_GPIO_PIN GPIO_Pin_1 // ADC12_IN9
#define PIOS_ADC_PIN1_GPIO_CHANNEL ADC_Channel_9
#define PIOS_ADC_PIN1_ADC ADC2
#define PIOS_ADC_PIN1_ADC_NUMBER 4
#define PIOS_ADC_NUM_PINS 1
#define PIOS_ADC_PORTS { PIOS_ADC_PIN8_GPIO_PORT }
#define PIOS_ADC_PINS { PIOS_ADC_PIN8_GPIO_PIN }
#define PIOS_ADC_CHANNELS { PIOS_ADC_PIN8_GPIO_CHANNEL }
#define PIOS_ADC_MAPPING { PIOS_ADC_PIN8_ADC }
#define PIOS_ADC_CHANNEL_MAPPING { PIOS_ADC_PIN8_ADC_NUMBER }
#define PIOS_ADC_PORTS { PIOS_ADC_PIN1_GPIO_PORT }
#define PIOS_ADC_PINS { PIOS_ADC_PIN1_GPIO_PIN }
#define PIOS_ADC_CHANNELS { PIOS_ADC_PIN1_GPIO_CHANNEL }
#define PIOS_ADC_MAPPING { PIOS_ADC_PIN1_ADC }
#define PIOS_ADC_CHANNEL_MAPPING { PIOS_ADC_PIN1_ADC_NUMBER }
#define PIOS_ADC_NUM_CHANNELS (PIOS_ADC_NUM_PINS + PIOS_ADC_USE_TEMP_SENSOR)
#define PIOS_ADC_NUM_ADC_CHANNELS 2
#define PIOS_ADC_USE_ADC2 1
@ -188,49 +188,19 @@ TIM8 | | | |
#define PIOS_ADC_TEMP_SENSOR_ADC ADC1
#define PIOS_ADC_TEMP_SENSOR_ADC_CHANNEL 1
#define PIOS_ADC_PIN1_GPIO_PORT GPIOA // PA0 (Accel Z)
#define PIOS_ADC_PIN1_GPIO_PIN GPIO_Pin_0 // ADC12_IN0
#define PIOS_ADC_PIN1_GPIO_CHANNEL ADC_Channel_0
#define PIOS_ADC_PIN1_ADC ADC1
#define PIOS_ADC_PIN1_ADC_NUMBER 1
#define PIOS_ADC_PIN1_GPIO_PORT GPIOB // PB1 (PSU Voltage)
#define PIOS_ADC_PIN1_GPIO_PIN GPIO_Pin_1 // ADC12_IN9
#define PIOS_ADC_PIN1_GPIO_CHANNEL ADC_Channel_9
#define PIOS_ADC_PIN1_ADC ADC2
#define PIOS_ADC_PIN1_ADC_NUMBER 4
#define PIOS_ADC_PIN2_GPIO_PORT GPIOA // PA1 (Accel Y)
#define PIOS_ADC_PIN2_GPIO_PIN GPIO_Pin_1 // ADC123_IN1
#define PIOS_ADC_PIN2_GPIO_CHANNEL ADC_Channel_1
#define PIOS_ADC_PIN2_ADC ADC1
#define PIOS_ADC_PIN2_ADC_NUMBER 2
#define PIOS_ADC_NUM_PINS 1
#define PIOS_ADC_PIN3_GPIO_PORT GPIOA // PA1 (Accel X)
#define PIOS_ADC_PIN3_GPIO_PIN GPIO_Pin_2 // ADC12_IN2
#define PIOS_ADC_PIN3_GPIO_CHANNEL ADC_Channel_2
#define PIOS_ADC_PIN3_ADC ADC1
#define PIOS_ADC_PIN3_ADC_NUMBER 3
#define PIOS_ADC_PIN4_GPIO_PORT GPIOA // PA4 (Gyro X)
#define PIOS_ADC_PIN4_GPIO_PIN GPIO_Pin_4 // ADC12_IN4
#define PIOS_ADC_PIN4_GPIO_CHANNEL ADC_Channel_4
#define PIOS_ADC_PIN4_ADC ADC2
#define PIOS_ADC_PIN4_ADC_NUMBER 1
#define PIOS_ADC_PIN5_GPIO_PORT GPIOA // PA5 (Gyro Y)
#define PIOS_ADC_PIN5_GPIO_PIN GPIO_Pin_5 // ADC12_IN5
#define PIOS_ADC_PIN5_GPIO_CHANNEL ADC_Channel_5
#define PIOS_ADC_PIN5_ADC ADC2
#define PIOS_ADC_PIN5_ADC_NUMBER 2
#define PIOS_ADC_PIN6_GPIO_PORT GPIOA // PA7 (Gyro Z)
#define PIOS_ADC_PIN6_GPIO_PIN GPIO_Pin_7 // ADC12_IN7
#define PIOS_ADC_PIN6_GPIO_CHANNEL ADC_Channel_7
#define PIOS_ADC_PIN6_ADC ADC2
#define PIOS_ADC_PIN6_ADC_NUMBER 3
#define PIOS_ADC_NUM_PINS 6
#define PIOS_ADC_PORTS { PIOS_ADC_PIN1_GPIO_PORT, PIOS_ADC_PIN2_GPIO_PORT, PIOS_ADC_PIN3_GPIO_PORT, PIOS_ADC_PIN4_GPIO_PORT, PIOS_ADC_PIN5_GPIO_PORT, PIOS_ADC_PIN6_GPIO_PORT }
#define PIOS_ADC_PINS { PIOS_ADC_PIN1_GPIO_PIN, PIOS_ADC_PIN2_GPIO_PIN, PIOS_ADC_PIN3_GPIO_PIN, PIOS_ADC_PIN4_GPIO_PIN, PIOS_ADC_PIN5_GPIO_PIN, PIOS_ADC_PIN6_GPIO_PIN }
#define PIOS_ADC_CHANNELS { PIOS_ADC_PIN1_GPIO_CHANNEL, PIOS_ADC_PIN2_GPIO_CHANNEL, PIOS_ADC_PIN3_GPIO_CHANNEL, PIOS_ADC_PIN4_GPIO_CHANNEL, PIOS_ADC_PIN5_GPIO_CHANNEL, PIOS_ADC_PIN6_GPIO_CHANNEL }
#define PIOS_ADC_MAPPING { PIOS_ADC_PIN1_ADC, PIOS_ADC_PIN2_ADC, PIOS_ADC_PIN3_ADC, PIOS_ADC_PIN4_ADC, PIOS_ADC_PIN5_ADC, PIOS_ADC_PIN6_ADC }
#define PIOS_ADC_CHANNEL_MAPPING { PIOS_ADC_PIN1_ADC_NUMBER, PIOS_ADC_PIN2_ADC_NUMBER, PIOS_ADC_PIN3_ADC_NUMBER, PIOS_ADC_PIN4_ADC_NUMBER, PIOS_ADC_PIN5_ADC_NUMBER, PIOS_ADC_PIN6_ADC_NUMBER }
#define PIOS_ADC_PORTS { PIOS_ADC_PIN1_GPIO_PORT }
#define PIOS_ADC_PINS { PIOS_ADC_PIN1_GPIO_PIN }
#define PIOS_ADC_CHANNELS { PIOS_ADC_PIN1_GPIO_CHANNEL }
#define PIOS_ADC_MAPPING { PIOS_ADC_PIN1_ADC }
#define PIOS_ADC_CHANNEL_MAPPING { PIOS_ADC_PIN1_ADC_NUMBER }
#define PIOS_ADC_NUM_CHANNELS (PIOS_ADC_NUM_PINS + PIOS_ADC_USE_TEMP_SENSOR)
#define PIOS_ADC_NUM_ADC_CHANNELS 2
#define PIOS_ADC_USE_ADC2 1

View File

@ -34,27 +34,27 @@
* NOTE: Leave this declared as const data so that it ends up in the
* .rodata section (ie. Flash) rather than in the .bss section (RAM).
*/
void PIOS_SPI_op_irq_handler(void);
void DMA1_Channel5_IRQHandler() __attribute__ ((alias ("PIOS_SPI_op_irq_handler")));
void DMA1_Channel4_IRQHandler() __attribute__ ((alias ("PIOS_SPI_op_irq_handler")));
static const struct pios_spi_cfg pios_spi_op_cfg = {
.regs = SPI2,
void PIOS_SPI_perif_irq_handler(void);
void DMA1_Channel5_IRQHandler() __attribute__ ((alias ("PIOS_SPI_perif_irq_handler")));
void DMA1_Channel4_IRQHandler() __attribute__ ((alias ("PIOS_SPI_perif_irq_handler")));
static const struct pios_spi_cfg pios_spi_perif_cfg = {
.regs = SPI1,
.init = {
.SPI_Mode = SPI_Mode_Slave,
.SPI_Mode = SPI_Mode_Master,
.SPI_Direction = SPI_Direction_2Lines_FullDuplex,
.SPI_DataSize = SPI_DataSize_8b,
.SPI_NSS = SPI_NSS_Hard,
.SPI_NSS = SPI_NSS_Soft,
.SPI_FirstBit = SPI_FirstBit_MSB,
.SPI_CRCPolynomial = 7,
.SPI_CPOL = SPI_CPOL_High,
.SPI_CPHA = SPI_CPHA_2Edge,
.SPI_BaudRatePrescaler = 7 << 3, /* Maximum divider (ie. slowest clock rate) */
},
.use_crc = TRUE,
.dma = {
.ahb_clk = RCC_AHBPeriph_DMA1,
.irq = {
.handler = PIOS_SPI_op_irq_handler,
.handler = PIOS_SPI_perif_irq_handler,
.flags = (DMA1_FLAG_TC4 | DMA1_FLAG_TE4 | DMA1_FLAG_HT4 | DMA1_FLAG_GL4),
.init = {
.NVIC_IRQChannel = DMA1_Channel4_IRQn,
@ -67,7 +67,7 @@ static const struct pios_spi_cfg pios_spi_op_cfg = {
.rx = {
.channel = DMA1_Channel4,
.init = {
.DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR),
.DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR),
.DMA_DIR = DMA_DIR_PeripheralSRC,
.DMA_PeripheralInc = DMA_PeripheralInc_Disable,
.DMA_MemoryInc = DMA_MemoryInc_Enable,
@ -81,7 +81,7 @@ static const struct pios_spi_cfg pios_spi_op_cfg = {
.tx = {
.channel = DMA1_Channel5,
.init = {
.DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR),
.DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR),
.DMA_DIR = DMA_DIR_PeripheralDST,
.DMA_PeripheralInc = DMA_PeripheralInc_Disable,
.DMA_MemoryInc = DMA_MemoryInc_Enable,
@ -94,34 +94,34 @@ static const struct pios_spi_cfg pios_spi_op_cfg = {
},
},
.ssel = {
.gpio = GPIOB,
.gpio = GPIOA,
.init = {
.GPIO_Pin = GPIO_Pin_12,
.GPIO_Speed = GPIO_Speed_50MHz,
.GPIO_Pin = GPIO_Pin_4,
.GPIO_Speed = GPIO_Speed_10MHz,
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
},
},
.sclk = {
.gpio = GPIOB,
.gpio = GPIOA,
.init = {
.GPIO_Pin = GPIO_Pin_13,
.GPIO_Speed = GPIO_Speed_50MHz,
.GPIO_Pin = GPIO_Pin_5,
.GPIO_Speed = GPIO_Speed_10MHz,
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
},
},
.miso = {
.gpio = GPIOB,
.gpio = GPIOA,
.init = {
.GPIO_Pin = GPIO_Pin_14,
.GPIO_Speed = GPIO_Speed_50MHz,
.GPIO_Pin = GPIO_Pin_6,
.GPIO_Speed = GPIO_Speed_10MHz,
.GPIO_Mode = GPIO_Mode_AF_PP,
},
},
.mosi = {
.gpio = GPIOB,
.gpio = GPIOA,
.init = {
.GPIO_Pin = GPIO_Pin_15,
.GPIO_Speed = GPIO_Speed_50MHz,
.GPIO_Pin = GPIO_Pin_7,
.GPIO_Speed = GPIO_Speed_10MHz,
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
},
},
@ -132,16 +132,16 @@ static const struct pios_spi_cfg pios_spi_op_cfg = {
*/
struct pios_spi_dev pios_spi_devs[] = {
{
.cfg = &pios_spi_op_cfg,
.cfg = &pios_spi_perif_cfg,
},
};
uint8_t pios_spi_num_devices = NELEMENTS(pios_spi_devs);
void PIOS_SPI_op_irq_handler(void)
void PIOS_SPI_perif_irq_handler(void)
{
/* Call into the generic code to handle the IRQ for this specific device */
PIOS_SPI_IRQ_Handler(PIOS_SPI_OP);
PIOS_SPI_IRQ_Handler(PIOS_SPI_PERIF);
}
#endif /* PIOS_INCLUDE_SPI */
@ -152,10 +152,10 @@ void PIOS_SPI_op_irq_handler(void)
/*
* AUX USART
*/
void PIOS_USART_aux_irq_handler(void);
void USART3_IRQHandler() __attribute__ ((alias ("PIOS_USART_aux_irq_handler")));
const struct pios_usart_cfg pios_usart_aux_cfg = {
.regs = USART3,
void PIOS_USART_com_irq_handler(void);
void USART3_IRQHandler() __attribute__ ((alias ("PIOS_USART_com_irq_handler")));
const struct pios_usart_cfg pios_usart_com_cfg = {
.regs = USART1,
.init = {
.USART_BaudRate = 57600,
.USART_WordLength = USART_WordLength_8b,
@ -165,26 +165,26 @@ const struct pios_usart_cfg pios_usart_aux_cfg = {
.USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
},
.irq = {
.handler = PIOS_USART_aux_irq_handler,
.handler = PIOS_USART_com_irq_handler,
.init = {
.NVIC_IRQChannel = USART3_IRQn,
.NVIC_IRQChannel = USART1_IRQn,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
},
},
.rx = {
.gpio = GPIOB,
.gpio = GPIOA,
.init = {
.GPIO_Pin = GPIO_Pin_11,
.GPIO_Pin = GPIO_Pin_10,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_IPU,
},
},
.tx = {
.gpio = GPIOB,
.gpio = GPIOA,
.init = {
.GPIO_Pin = GPIO_Pin_10,
.GPIO_Pin = GPIO_Pin_9,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_AF_PP,
},
@ -195,17 +195,17 @@ const struct pios_usart_cfg pios_usart_aux_cfg = {
* Board specific number of devices.
*/
struct pios_usart_dev pios_usart_devs[] = {
#define PIOS_USART_AUX 0
#define PIOS_USART_COM 0
{
.cfg = &pios_usart_aux_cfg,
.cfg = &pios_usart_com_cfg,
},
};
uint8_t pios_usart_num_devices = NELEMENTS(pios_usart_devs);
void PIOS_USART_aux_irq_handler(void)
void PIOS_USART_com_irq_handler(void)
{
PIOS_USART_IRQ_Handler(PIOS_USART_AUX);
PIOS_USART_IRQ_Handler(PIOS_USART_COM);
}
#endif /* PIOS_INCLUDE_USART */
@ -224,7 +224,7 @@ extern const struct pios_com_driver pios_usart_com_driver;
struct pios_com_dev pios_com_devs[] = {
{
.id = PIOS_USART_AUX,
.id = PIOS_USART_COM,
.driver = &pios_usart_com_driver,
},
};

View File

@ -38,16 +38,13 @@
*/
int main()
{
uint32_t loop_ctr = 0;
uint32_t loop_ctr2 = 0;
// Brings up System using CMSIS functions, enables the LEDs.
PIOS_SYS_Init();
// Delay system
PIOS_DELAY_Init();
// Communication system
// UART communication system
PIOS_COM_Init();
// ADC system
@ -55,36 +52,50 @@ int main()
// SPI link to master
PIOS_SPI_Init();
// *************
// LED test
PIOS_LED_Off(LED1);
PIOS_LED_Off(LED2);
PIOS_LED_Off(LED3);
PIOS_LED_Off(LED4);
/*
for (int i = 0; i < 2; i++)
{
PIOS_LED_Toggle(LED1);
PIOS_DELAY_WaitmS(200);
PIOS_LED_Toggle(LED2);
PIOS_DELAY_WaitmS(200);
PIOS_LED_Toggle(LED3);
PIOS_DELAY_WaitmS(200);
PIOS_LED_Toggle(LED4);
PIOS_DELAY_WaitmS(200);
}
*/
// *************
// Main loop
while (1)
{
if (++loop_ctr > 10000000)
/* uint32_t loop_ctr;
if (++loop_ctr >= 10000000)
{
loop_ctr = 0;
if (++loop_ctr2 > 3) loop_ctr2 = 0;
switch (loop_ctr2)
{
case 0:
PIOS_LED_Toggle(LED1);
break;
case 1:
PIOS_LED_Toggle(LED2);
break;
case 2:
PIOS_LED_Toggle(LED3);
break;
case 3:
PIOS_LED_Toggle(LED4);
break;
default:
loop_ctr2 = 0;
PIOS_LED_Toggle(LED1);
break;
}
PIOS_LED_Toggle(LED2);
}
*/
// just sequence the LED's for now
PIOS_LED_Toggle(LED1);
PIOS_DELAY_WaitmS(200);
PIOS_LED_Toggle(LED2);
PIOS_DELAY_WaitmS(200);
PIOS_LED_Toggle(LED3);
PIOS_DELAY_WaitmS(200);
PIOS_LED_Toggle(LED4);
PIOS_DELAY_WaitmS(200);
}
return 0;