mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-26 16:30:07 +08:00
[logger] high_speed_logger_spi_link
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE module SYSTEM "module.dtd">
|
||||
|
||||
<module name="loggers">
|
||||
<doc>
|
||||
<description>Connect to external High-Speed SD-logger via SPI</description>
|
||||
</doc>
|
||||
<header>
|
||||
<file name="high_speed_logger_spi_link.h"/>
|
||||
</header>
|
||||
<init fun="high_speed_logger_spi_link_init()"/>
|
||||
<periodic fun="high_speed_logger_spi_link_periodic()" autorun="TRUE"/>
|
||||
<makefile>
|
||||
<define name="SPI_MASTER" value="1" />
|
||||
<define name="USE_SPI1" value="1" />
|
||||
<define name="HIGH_SPEED_LOGGER_SPI_LINK_DEVICE" value="spi1" />
|
||||
<define name="USE_SPI_SLAVE5" value="1" />
|
||||
<define name="HIGH_SPEED_LOGGER_SPI_LINK_SLAVE_NUMBER" value="SPI_SLAVE5" />
|
||||
<file name="high_speed_logger_spi_link.c"/>
|
||||
</makefile>
|
||||
</module>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<!DOCTYPE module SYSTEM "module.dtd">
|
||||
|
||||
<module name="openlog">
|
||||
<doc>
|
||||
<description>Openlog on-board data logger</description>
|
||||
</doc>
|
||||
<header>
|
||||
<file name="openlog.h"/>
|
||||
</header>
|
||||
<init fun="init_openlog()"/>
|
||||
<periodic fun="periodic_2Hz_openlog()" freq="2." autorun="TRUE"/>
|
||||
<makefile>
|
||||
<file name="openlog.c"/>
|
||||
</makefile>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2013 The Paparazzi Team
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "high_speed_logger_spi_link.h"
|
||||
|
||||
#include "subsystems/imu.h"
|
||||
#include "mcu_periph/spi.h"
|
||||
|
||||
struct high_speed_logger_spi_link_data high_speed_logger_spi_link_data;
|
||||
uint16_t testData = 1234;
|
||||
|
||||
struct spi_transaction high_speed_logger_spi_link_transaction;
|
||||
|
||||
static void high_speed_logger_spi_link_trans_cb( struct spi_transaction *trans );
|
||||
|
||||
void high_speed_logger_spi_link_init(void) {
|
||||
high_speed_logger_spi_link_data.id = 0;
|
||||
|
||||
high_speed_logger_spi_link_transaction.select = SPISelectUnselect;
|
||||
high_speed_logger_spi_link_transaction.cpol = SPICpolIdleHigh;
|
||||
high_speed_logger_spi_link_transaction.cpha = SPICphaEdge2;
|
||||
high_speed_logger_spi_link_transaction.dss = SPIDss8bit;
|
||||
high_speed_logger_spi_link_transaction.bitorder = SPIMSBFirst;
|
||||
high_speed_logger_spi_link_transaction.cdiv = SPIDiv64;
|
||||
high_speed_logger_spi_link_transaction.slave_idx = HIGH_SPEED_LOGGER_SPI_LINK_SLAVE_NUMBER;
|
||||
high_speed_logger_spi_link_transaction.output_length = sizeof(high_speed_logger_spi_link_data);
|
||||
high_speed_logger_spi_link_transaction.output_buf = (uint8_t*) &high_speed_logger_spi_link_data;
|
||||
high_speed_logger_spi_link_transaction.input_length = 0;
|
||||
high_speed_logger_spi_link_transaction.input_buf = NULL;
|
||||
high_speed_logger_spi_link_transaction.after_cb = high_speed_logger_spi_link_trans_cb;
|
||||
}
|
||||
|
||||
|
||||
void high_speed_logger_spi_link_periodic(void)
|
||||
{
|
||||
high_speed_logger_spi_link_data.gyro_p = imu.gyro_unscaled.p;
|
||||
high_speed_logger_spi_link_data.gyro_q = imu.gyro_unscaled.q;
|
||||
high_speed_logger_spi_link_data.gyro_r = imu.gyro_unscaled.r;
|
||||
high_speed_logger_spi_link_data.acc_x = imu.accel_unscaled.x;
|
||||
high_speed_logger_spi_link_data.acc_y = imu.accel_unscaled.y;
|
||||
high_speed_logger_spi_link_data.acc_z = imu.accel_unscaled.z;
|
||||
high_speed_logger_spi_link_data.mag_x = imu.mag_unscaled.x;
|
||||
high_speed_logger_spi_link_data.mag_y = imu.mag_unscaled.x;
|
||||
high_speed_logger_spi_link_data.mag_z = imu.mag_unscaled.x;
|
||||
|
||||
spi_submit(&(HIGH_SPEED_LOGGER_SPI_LINK_DEVICE), &high_speed_logger_spi_link_transaction);
|
||||
|
||||
high_speed_logger_spi_link_data.id++;
|
||||
}
|
||||
|
||||
static void high_speed_logger_spi_link_trans_cb( struct spi_transaction *trans ) {
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2013 The Paparazzi Team
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HIGH_SPEED_LOGGER_SPI_LINK_H_
|
||||
#define HIGH_SPEED_LOGGER_SPI_LINK_H_
|
||||
|
||||
#include "std.h"
|
||||
|
||||
extern void high_speed_logger_spi_link_init(void);
|
||||
extern void high_speed_logger_spi_link_periodic(void);
|
||||
|
||||
#define PACKED __attribute__((__packed__))
|
||||
|
||||
struct PACKED high_speed_logger_spi_link_data {
|
||||
int32_t id; // 1
|
||||
int32_t gyro_p; // 2
|
||||
int32_t gyro_q;
|
||||
int32_t gyro_r;
|
||||
int32_t acc_x; // 5
|
||||
int32_t acc_y;
|
||||
int32_t acc_z;
|
||||
int32_t mag_x; // 8
|
||||
int32_t mag_y;
|
||||
int32_t mag_z;
|
||||
int32_t phi; // 11
|
||||
int32_t theta;
|
||||
int32_t psi;
|
||||
int32_t extra1; // 14
|
||||
int32_t extra2; // 15
|
||||
int32_t extra3; // 16
|
||||
};
|
||||
|
||||
#endif /* HIGH_SPEED_LOGGER_SPI_LINK_H_ */
|
||||
@@ -1,134 +0,0 @@
|
||||
#include "spiLink.h"
|
||||
#include <stm32/gpio.h>
|
||||
#include <stm32/misc.h>
|
||||
#include <stm32/rcc.h>
|
||||
#include <stm32/exti.h>
|
||||
#include <stm32/spi.h>
|
||||
#include <stm32/dma.h>
|
||||
|
||||
#include "subsystems/imu.h"
|
||||
|
||||
struct LoggerData loggerData;
|
||||
uint16_t testData = 1234;
|
||||
volatile bool_t previousSpi1TransferComplete = TRUE;
|
||||
|
||||
DMA_InitTypeDef DMA_InitStructure;
|
||||
|
||||
void logger_spiLink_init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
//NVIC_InitTypeDef NVIC_InitStructure;
|
||||
SPI_InitTypeDef SPI_InitStructure;
|
||||
|
||||
// Enable SPI1 Clock (APB2)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1 | RCC_APB2Periph_AFIO, ENABLE);
|
||||
|
||||
// Configure SPI pins as Alternative Functions pins
|
||||
// Output pins (push/pull: MOSI,SCK,SS)
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7;
|
||||
//sck, miso, mosi
|
||||
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_5 | GPIO_Pin_7;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
// Input pin (open drain: MISO)
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
// SPI1 config
|
||||
SPI_I2S_DeInit(SPI1);
|
||||
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
||||
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
|
||||
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
|
||||
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
|
||||
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
|
||||
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
|
||||
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
|
||||
SPI_InitStructure.SPI_CRCPolynomial = 7;
|
||||
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
|
||||
SPI_Init(SPI1, &SPI_InitStructure);
|
||||
|
||||
SPI_Cmd(SPI1, ENABLE);
|
||||
SPI_SSOutputCmd(SPI1,ENABLE);
|
||||
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
|
||||
|
||||
DMA_DeInit(DMA1_Channel3);
|
||||
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
|
||||
DMA_InitStructure.DMA_MemoryBaseAddr = &loggerData;
|
||||
DMA_InitStructure.DMA_BufferSize = sizeof(loggerData);
|
||||
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&SPI1->DR);
|
||||
//DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(SPI1_BASE+0x0C);
|
||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
|
||||
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
|
||||
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
|
||||
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
|
||||
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
||||
DMA_Init(DMA1_Channel3, &DMA_InitStructure);
|
||||
|
||||
// Enable DMA1 channel4 IRQ Channel ( SPI RX)
|
||||
NVIC_InitTypeDef NVIC_Init_Structure;
|
||||
NVIC_Init_Structure.NVIC_IRQChannel = DMA1_Channel3_IRQn;
|
||||
NVIC_Init_Structure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_Init_Structure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_Init_Structure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_Init_Structure);
|
||||
|
||||
|
||||
// Enable the SPI1 Tx DMA requests
|
||||
SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Tx, ENABLE);
|
||||
|
||||
// Enable the SPI1 Tx DMA stream
|
||||
DMA_Cmd(DMA1_Channel3, ENABLE);
|
||||
|
||||
DMA_ITConfig(DMA1_Channel3, DMA_IT_TC, ENABLE);
|
||||
}
|
||||
|
||||
void dma1_c3_irq_handler(void)
|
||||
{
|
||||
if (DMA_GetITStatus(DMA1_IT_TC3)) {
|
||||
DMA_ClearITPendingBit(DMA1_IT_GL3 | DMA1_IT_TC3);
|
||||
previousSpi1TransferComplete = TRUE;
|
||||
DMA_ClearFlag(DMA1_FLAG_HT3 | DMA1_FLAG_TC3);
|
||||
DMA_ITConfig(DMA1_Channel3, DMA_IT_TC, DISABLE);
|
||||
SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Tx, DISABLE);
|
||||
DMA_Cmd(DMA1_Channel3, DISABLE);
|
||||
DMA_DeInit(DMA1_Channel3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void logger_spiLink_periodic(void)
|
||||
{
|
||||
if (previousSpi1TransferComplete) {
|
||||
loggerData.gyro_p = imu.gyro_unscaled.p;
|
||||
loggerData.gyro_q = imu.gyro_unscaled.q;
|
||||
loggerData.gyro_r = imu.gyro_unscaled.r;
|
||||
loggerData.acc_x = imu.accel_unscaled.x;
|
||||
loggerData.acc_y = imu.accel_unscaled.y;
|
||||
loggerData.acc_z = imu.accel_unscaled.z;
|
||||
loggerData.mag_x = imu.mag_unscaled.x;
|
||||
loggerData.mag_y = imu.mag_unscaled.x;
|
||||
loggerData.mag_z = imu.mag_unscaled.x;
|
||||
|
||||
|
||||
previousSpi1TransferComplete = FALSE;
|
||||
|
||||
DMA_Init(DMA1_Channel3, &DMA_InitStructure);
|
||||
// Enable the SPI1 Tx DMA requests
|
||||
SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Tx, ENABLE);
|
||||
|
||||
// Enable the SPI1 Tx DMA stream
|
||||
DMA_Cmd(DMA1_Channel3, ENABLE);
|
||||
|
||||
DMA_ITConfig(DMA1_Channel3, DMA_IT_TC, ENABLE);
|
||||
|
||||
//SPI_I2S_SendData(SPI1,testData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#ifndef LOGGER_SPILINK_H_
|
||||
#define LOGGER_SPILINK_H_
|
||||
|
||||
#include "std.h"
|
||||
#define USE_DMA1_C3_IRQ
|
||||
extern void logger_spiLink_init(void);
|
||||
extern void logger_spiLink_periodic(void);
|
||||
|
||||
|
||||
#define PACKED __attribute__((__packed__))
|
||||
|
||||
struct PACKED LoggerData {
|
||||
int32_t gyro_p;
|
||||
int32_t gyro_q;
|
||||
int32_t gyro_r;
|
||||
int32_t acc_x;
|
||||
int32_t acc_y;
|
||||
int32_t acc_z;
|
||||
int32_t mag_x;
|
||||
int32_t mag_y;
|
||||
int32_t mag_z;
|
||||
};
|
||||
|
||||
#endif /* LOGGER_SPILINK_H_ */
|
||||
Reference in New Issue
Block a user