mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
OSD uSDcard support, settings save/load works (tested on 128MB card). booting takes some time for some reason.
This commit is contained in:
parent
ad0473e646
commit
52c3627bb2
@ -94,7 +94,7 @@ endif
|
||||
MODULES = Osd/osdgen
|
||||
MODULES += GPS
|
||||
MODULES += Osd/osdinput
|
||||
MODULES += Extensions/MagBaro
|
||||
#MODULES += Extensions/MagBaro
|
||||
MODULES += Telemetry
|
||||
MODULES += FirmwareIAP
|
||||
|
||||
@ -215,10 +215,11 @@ SRC += $(PIOSCOMMON)/pios_video.c
|
||||
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_cdc.c
|
||||
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c
|
||||
SRC += $(PIOSCOMMON)/pios_usb_util.c
|
||||
SRC += $(PIOSCOMMON)/pios_sdcard.c
|
||||
|
||||
# optional component libraries
|
||||
include $(PIOSCOMMONLIB)/FreeRTOS/library.mk
|
||||
#include $(PIOSCOMMONLIB)/dosfs/library.mk
|
||||
include $(PIOSCOMMONLIB)/dosfs/library.mk
|
||||
include $(PIOSCOMMONLIB)/msheap/library.mk
|
||||
|
||||
## PIOS Hardware (STM32F4xx)
|
||||
|
@ -40,7 +40,7 @@
|
||||
#define PIOS_INCLUDE_LED
|
||||
#define PIOS_INCLUDE_IAP
|
||||
//#define PIOS_INCLUDE_SERVO
|
||||
//#define PIOS_INCLUDE_SPI
|
||||
#define PIOS_INCLUDE_SPI
|
||||
#define PIOS_INCLUDE_SYS
|
||||
#define PIOS_INCLUDE_USART
|
||||
//#define PIOS_INCLUDE_GPIO
|
||||
@ -59,6 +59,7 @@
|
||||
//#define PIOS_OVERO_SPI
|
||||
#define PIOS_INCLUDE_BMP085
|
||||
#define PIOS_INCLUDE_HMC5883
|
||||
#define PIOS_INCLUDE_SDCARD
|
||||
|
||||
/* Supported receiver interfaces */
|
||||
//#define PIOS_INCLUDE_RCVR
|
||||
@ -90,5 +91,6 @@
|
||||
|
||||
// This actually needs calibrating
|
||||
#define IDLE_COUNTS_PER_SEC_AT_NO_LOAD (8379692)
|
||||
#define LOG_FILENAME "PIOS.LOG"
|
||||
|
||||
#endif /* PIOS_CONFIG_H */
|
||||
|
@ -243,6 +243,17 @@ void PIOS_Board_Init(void) {
|
||||
|
||||
PIOS_LED_Init(&pios_led_cfg);
|
||||
|
||||
#if defined(PIOS_INCLUDE_SPI)
|
||||
/* Set up the SPI interface to the SD card */
|
||||
if (PIOS_SPI_Init(&pios_spi_sdcard_id, &pios_spi_sdcard_cfg)) {
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
|
||||
/* Enable and mount the SDCard */
|
||||
PIOS_SDCARD_Init(pios_spi_sdcard_id);
|
||||
PIOS_SDCARD_MountFS(0);
|
||||
#endif /* PIOS_INCLUDE_SPI */
|
||||
|
||||
/* Initialize UAVObject libraries */
|
||||
EventDispatcherInitialize();
|
||||
UAVObjInitialize();
|
||||
|
@ -282,4 +282,22 @@ extern uint32_t pios_i2c_flexiport_adapter_id;
|
||||
//------------------------
|
||||
#define PIOS_BMP085_OVERSAMPLING 3
|
||||
|
||||
|
||||
/**
|
||||
* glue macros for file IO
|
||||
* STM32 uses DOSFS for file IO
|
||||
*/
|
||||
#define PIOS_FOPEN_READ(filename,file) DFS_OpenFile(&PIOS_SDCARD_VolInfo, (uint8_t *)filename, DFS_READ, PIOS_SDCARD_Sector, &file) != DFS_OK
|
||||
|
||||
#define PIOS_FOPEN_WRITE(filename,file) DFS_OpenFile(&PIOS_SDCARD_VolInfo, (uint8_t *)filename, DFS_WRITE, PIOS_SDCARD_Sector, &file) != DFS_OK
|
||||
|
||||
#define PIOS_FREAD(file,bufferadr,length,resultadr) DFS_ReadFile(file, PIOS_SDCARD_Sector, (uint8_t*)bufferadr, resultadr, length) != DFS_OK
|
||||
|
||||
#define PIOS_FWRITE(file,bufferadr,length,resultadr) DFS_WriteFile(file, PIOS_SDCARD_Sector, (uint8_t*)bufferadr, resultadr, length)
|
||||
|
||||
#define PIOS_FCLOSE(file) DFS_Close(&file)
|
||||
|
||||
#define PIOS_FUNLINK(filename) DFS_UnlinkFile(&PIOS_SDCARD_VolInfo, (uint8_t *)filename, PIOS_SDCARD_Sector)
|
||||
|
||||
|
||||
#endif /* PIOS_BOARD_H */
|
||||
|
@ -3,6 +3,6 @@
|
||||
#
|
||||
|
||||
DOSFS_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
|
||||
SRC += $(wildcard $(DOSFS_DIR)/*.c)
|
||||
SRC += $(wildcard $(DOSFS_DIR)*.c)
|
||||
EXTRAINCDIRS += $(DOSFS_DIR)
|
||||
|
||||
|
@ -126,7 +126,7 @@ int32_t PIOS_SDCARD_PowerOn(void)
|
||||
|
||||
SDCARD_MUTEX_TAKE;
|
||||
/* Ensure that chip select line deactivated */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 1); /* spi, pin_value */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0, 1); /* spi, pin_value */
|
||||
|
||||
/* Init SPI port for slow frequency access (ca. 0.3 MBit/s) */
|
||||
PIOS_SPI_SetClockSpeed(PIOS_SDCARD_SPI, PIOS_SPI_PRESCALER_256);
|
||||
@ -137,7 +137,7 @@ int32_t PIOS_SDCARD_PowerOn(void)
|
||||
}
|
||||
|
||||
/* Activate chip select */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0); /* spi, pin_value */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0, 0); /* spi, pin_value */
|
||||
|
||||
/* wait for 1 mS */
|
||||
PIOS_DELAY_WaituS(1000);
|
||||
@ -202,7 +202,7 @@ int32_t PIOS_SDCARD_PowerOn(void)
|
||||
|
||||
error:
|
||||
/* Deactivate chip select */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 1); /* spi, pin_value */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0, 1); /* spi, pin_value */
|
||||
|
||||
/* Send dummy byte once deactivated to drop cards DO */
|
||||
PIOS_SPI_TransferByte(PIOS_SDCARD_SPI, 0xff);
|
||||
@ -272,7 +272,7 @@ int32_t PIOS_SDCARD_CheckAvailable(uint8_t was_available)
|
||||
PIOS_SPI_SetClockSpeed(PIOS_SDCARD_SPI, PIOS_SPI_PRESCALER_4);
|
||||
|
||||
/* Activate chip select */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0); /* spi, pin_value */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0, 0); /* spi, pin_value */
|
||||
|
||||
/* Send STATUS command to check if media is available */
|
||||
ret = PIOS_SDCARD_SendSDCCmd(SDCMD_SEND_STATUS, 0, SDCMD_SEND_STATUS_CRC);
|
||||
@ -281,7 +281,7 @@ int32_t PIOS_SDCARD_CheckAvailable(uint8_t was_available)
|
||||
PIOS_SPI_SetClockSpeed(PIOS_SDCARD_SPI, PIOS_SPI_PRESCALER_256);
|
||||
|
||||
/* Deactivate chip select */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 1); /* spi, pin_value */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0, 1); /* spi, pin_value */
|
||||
/* send 80 clock cycles to start up */
|
||||
uint8_t i;
|
||||
for (i = 0; i < 10; ++i) {
|
||||
@ -289,7 +289,7 @@ int32_t PIOS_SDCARD_CheckAvailable(uint8_t was_available)
|
||||
}
|
||||
|
||||
/* Activate chip select */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0); /* spi, pin_value */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0, 0); /* spi, pin_value */
|
||||
|
||||
/* Send CMD0 to reset the media */
|
||||
if ((ret = (PIOS_SDCARD_SendSDCCmd(SDCMD_GO_IDLE_STATE, 0, SDCMD_GO_IDLE_STATE_CRC))) < 0) {
|
||||
@ -297,7 +297,7 @@ int32_t PIOS_SDCARD_CheckAvailable(uint8_t was_available)
|
||||
}
|
||||
|
||||
/* Deactivate chip select */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 1); /* spi, pin_value */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0, 1); /* spi, pin_value */
|
||||
|
||||
SDCARD_MUTEX_GIVE;
|
||||
/* Run power-on sequence (negative return = not available) */
|
||||
@ -306,7 +306,7 @@ int32_t PIOS_SDCARD_CheckAvailable(uint8_t was_available)
|
||||
|
||||
not_available:
|
||||
/* Deactivate chip select */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 1); /* spi, pin_value */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0, 1); /* spi, pin_value */
|
||||
/* Send dummy byte once deactivated to drop cards DO */
|
||||
PIOS_SPI_TransferByte(PIOS_SDCARD_SPI, 0xff);
|
||||
SDCARD_MUTEX_GIVE;
|
||||
@ -336,7 +336,7 @@ int32_t PIOS_SDCARD_SendSDCCmd(uint8_t cmd, uint32_t addr, uint8_t crc)
|
||||
}
|
||||
|
||||
/* Activate chip select */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0); /* spi, pin_value */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0, 0); /* spi, pin_value */
|
||||
|
||||
/* Transfer to card */
|
||||
PIOS_SPI_TransferByte(PIOS_SDCARD_SPI, (uint8_t) cmd);
|
||||
@ -385,7 +385,7 @@ int32_t PIOS_SDCARD_SendSDCCmd(uint8_t cmd, uint32_t addr, uint8_t crc)
|
||||
|
||||
/* Deactivate chip-select on timeout, and return error code */
|
||||
if (timeout) {
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 1); /* spi, pin_value */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0, 1); /* spi, pin_value */
|
||||
|
||||
/* Send dummy byte once deactivated to drop cards DO */
|
||||
PIOS_SPI_TransferByte(PIOS_SDCARD_SPI, 0xff);
|
||||
@ -458,7 +458,7 @@ int32_t PIOS_SDCARD_SectorRead(uint32_t sector, uint8_t * buffer)
|
||||
|
||||
error:
|
||||
/* Deactivate chip select */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 1); // spi, pin_value
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0, 1); // spi, pin_value
|
||||
|
||||
/* Send dummy byte once deactivated to drop cards DO */
|
||||
PIOS_SPI_TransferByte(PIOS_SDCARD_SPI, 0xff);
|
||||
@ -540,7 +540,7 @@ int32_t PIOS_SDCARD_SectorWrite(uint32_t sector, uint8_t * buffer)
|
||||
|
||||
error:
|
||||
/* Deactivate chip select */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 1); /* spi, pin_value */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0, 1); /* spi, pin_value */
|
||||
/* Send dummy byte once deactivated to drop cards DO */
|
||||
PIOS_SPI_TransferByte(PIOS_SDCARD_SPI, 0xff);
|
||||
|
||||
@ -629,7 +629,7 @@ int32_t PIOS_SDCARD_CIDRead(SDCARDCidTypeDef * cid)
|
||||
|
||||
error:
|
||||
/* deactivate chip select */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 1); /* spi, pin_value */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0, 1); /* spi, pin_value */
|
||||
/* Send dummy byte once deactivated to drop cards DO */
|
||||
PIOS_SPI_TransferByte(PIOS_SDCARD_SPI, 0xff);
|
||||
SDCARD_MUTEX_GIVE;
|
||||
@ -747,7 +747,7 @@ int32_t PIOS_SDCARD_CSDRead(SDCARDCsdTypeDef * csd)
|
||||
|
||||
error:
|
||||
/* Deactivate chip select */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 1); /* spi, pin_value */
|
||||
PIOS_SPI_RC_PinSet(PIOS_SDCARD_SPI, 0, 1); /* spi, pin_value */
|
||||
/* Send dummy byte once deactivated to drop cards DO */
|
||||
PIOS_SPI_TransferByte(PIOS_SDCARD_SPI, 0xff);
|
||||
SDCARD_MUTEX_GIVE;
|
||||
|
@ -63,7 +63,7 @@
|
||||
#include <dosfs.h>
|
||||
|
||||
/* Mass Storage Device Includes */
|
||||
#include <msd.h>
|
||||
//#include <msd.h>
|
||||
#endif
|
||||
|
||||
/* Generic initcall infrastructure */
|
||||
|
@ -71,6 +71,134 @@ const struct pios_led_cfg * PIOS_BOARD_HW_DEFS_GetLedCfg (uint32_t board_revisio
|
||||
|
||||
#endif /* PIOS_INCLUDE_LED */
|
||||
|
||||
#if defined(PIOS_INCLUDE_SPI)
|
||||
|
||||
#include <pios_spi_priv.h>
|
||||
|
||||
/* MicroSD Interface
|
||||
*
|
||||
* 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_sdcard_irq_handler(void);
|
||||
void DMA1_Channel2_IRQHandler() __attribute__ ((alias ("PIOS_SPI_sdcard_irq_handler")));
|
||||
void DMA1_Channel3_IRQHandler() __attribute__ ((alias ("PIOS_SPI_sdcard_irq_handler")));
|
||||
static const struct pios_spi_cfg pios_spi_sdcard_cfg = {
|
||||
.regs = SPI2,
|
||||
.remap = GPIO_AF_SPI2,
|
||||
.init = {
|
||||
.SPI_Mode = SPI_Mode_Master,
|
||||
.SPI_Direction = SPI_Direction_2Lines_FullDuplex,
|
||||
.SPI_DataSize = SPI_DataSize_8b,
|
||||
.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 = SPI_BaudRatePrescaler_256, /* Maximum divider (ie. slowest clock rate) */
|
||||
},
|
||||
.use_crc = false,
|
||||
.dma = {
|
||||
.irq = {
|
||||
.flags = (DMA_IT_TCIF3|DMA_IT_TEIF3|DMA_IT_HTIF3|DMA_IT_TCIF3),
|
||||
.init = {
|
||||
.NVIC_IRQChannel = DMA1_Stream3_IRQn,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.rx = {
|
||||
.channel = DMA1_Stream3,
|
||||
.init = {
|
||||
.DMA_Channel = DMA_Channel_0,
|
||||
.DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR),
|
||||
.DMA_DIR = DMA_DIR_PeripheralToMemory,
|
||||
.DMA_PeripheralInc = DMA_PeripheralInc_Disable,
|
||||
.DMA_MemoryInc = DMA_MemoryInc_Enable,
|
||||
.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
|
||||
.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
|
||||
.DMA_Mode = DMA_Mode_Normal,
|
||||
.DMA_Priority = DMA_Priority_Medium,
|
||||
.DMA_FIFOMode = DMA_FIFOMode_Disable,
|
||||
.DMA_FIFOThreshold = DMA_FIFOThreshold_Full,
|
||||
.DMA_MemoryBurst = DMA_MemoryBurst_Single,
|
||||
.DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
|
||||
},
|
||||
},
|
||||
.tx = {
|
||||
.channel = DMA1_Stream4,
|
||||
.init = {
|
||||
.DMA_Channel = DMA_Channel_0,
|
||||
.DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR),
|
||||
.DMA_DIR = DMA_DIR_MemoryToPeripheral,
|
||||
.DMA_PeripheralInc = DMA_PeripheralInc_Disable,
|
||||
.DMA_MemoryInc = DMA_MemoryInc_Enable,
|
||||
.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
|
||||
.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
|
||||
.DMA_Mode = DMA_Mode_Normal,
|
||||
.DMA_Priority = DMA_Priority_Medium,
|
||||
.DMA_FIFOMode = DMA_FIFOMode_Disable,
|
||||
.DMA_FIFOThreshold = DMA_FIFOThreshold_Full,
|
||||
.DMA_MemoryBurst = DMA_MemoryBurst_Single,
|
||||
.DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
|
||||
},
|
||||
},
|
||||
},
|
||||
.sclk = {
|
||||
.gpio = GPIOB,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_13,
|
||||
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||
.GPIO_Mode = GPIO_Mode_AF,
|
||||
.GPIO_OType = GPIO_OType_PP,
|
||||
.GPIO_PuPd = GPIO_PuPd_UP
|
||||
},
|
||||
},
|
||||
.miso = {
|
||||
.gpio = GPIOB,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_14,
|
||||
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||
.GPIO_Mode = GPIO_Mode_AF,
|
||||
.GPIO_OType = GPIO_OType_PP,
|
||||
.GPIO_PuPd = GPIO_PuPd_UP
|
||||
},
|
||||
},
|
||||
.mosi = {
|
||||
.gpio = GPIOB,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_15,
|
||||
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||
.GPIO_Mode = GPIO_Mode_AF,
|
||||
.GPIO_OType = GPIO_OType_PP,
|
||||
.GPIO_PuPd = GPIO_PuPd_UP
|
||||
},
|
||||
},
|
||||
.slave_count = 1,
|
||||
.ssel = {{
|
||||
.gpio = GPIOB,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_12,
|
||||
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||
.GPIO_Mode = GPIO_Mode_OUT,
|
||||
.GPIO_OType = GPIO_OType_PP,
|
||||
.GPIO_PuPd = GPIO_PuPd_UP
|
||||
},
|
||||
}},
|
||||
};
|
||||
|
||||
static uint32_t pios_spi_sdcard_id;
|
||||
void PIOS_SPI_sdcard_irq_handler(void)
|
||||
{
|
||||
/* Call into the generic code to handle the IRQ for this specific device */
|
||||
PIOS_SPI_IRQ_Handler(pios_spi_sdcard_id);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#include <pios_usart_priv.h>
|
||||
|
||||
#if defined(PIOS_INCLUDE_GPS)
|
||||
|
Loading…
x
Reference in New Issue
Block a user