mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 21:35:44 +03:00
Fixed sdcard issues
Reset CPU clock to 168mhz (no overclocking)
This commit is contained in:
parent
c3e4eefcfc
commit
9b3e8ab01c
4 changed files with 34 additions and 23 deletions
|
@ -15,8 +15,6 @@
|
|||
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "sdcard.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
@ -29,6 +27,7 @@
|
|||
#include "drivers/bus_spi.h"
|
||||
#include "drivers/system.h"
|
||||
|
||||
#include "sdcard.h"
|
||||
#include "sdcard_standard.h"
|
||||
|
||||
#ifdef USE_SDCARD
|
||||
|
@ -37,8 +36,8 @@
|
|||
#define SDCARD_PROFILING
|
||||
#endif
|
||||
|
||||
#define SET_CS_HIGH IOHi(sdcardDetectPin)
|
||||
#define SET_CS_LOW IOLo(sdcardDetectPin)
|
||||
#define SET_CS_HIGH IOHi(sdCardCsPin)
|
||||
#define SET_CS_LOW IOLo(sdCardCsPin)
|
||||
|
||||
#define SDCARD_INIT_NUM_DUMMY_BYTES 10
|
||||
#define SDCARD_MAXIMUM_BYTE_DELAY_FOR_CMD_REPLY 8
|
||||
|
@ -117,23 +116,27 @@ static sdcard_t sdcard;
|
|||
|
||||
STATIC_ASSERT(sizeof(sdcardCSD_t) == 16, sdcard_csd_bitfields_didnt_pack_properly);
|
||||
|
||||
static IO_t sdcardDetectPin = IO_NONE;
|
||||
#ifdef SDCARD_DETECT_PIN
|
||||
static IO_t sdCardDetectPin = IO_NONE;
|
||||
#endif
|
||||
|
||||
static IO_t sdCardCsPin = IO_NONE;
|
||||
|
||||
void sdcardInsertionDetectDeinit(void)
|
||||
{
|
||||
#ifdef SDCARD_DETECT_PIN
|
||||
sdcardDetectPin = IOGetByTag(IO_TAG(SDCARD_DETECT_PIN));
|
||||
IOInit(sdcardDetectPin, OWNER_SYSTEM, RESOURCE_SPI);
|
||||
IOConfigGPIO(sdcardDetectPin, SPI_IO_CS_CFG);
|
||||
sdCardDetectPin = IOGetByTag(IO_TAG(SDCARD_DETECT_PIN));
|
||||
IOInit(sdCardDetectPin, OWNER_SYSTEM, RESOURCE_SPI);
|
||||
IOConfigGPIO(sdCardDetectPin, IOCFG_IN_FLOATING);
|
||||
#endif
|
||||
}
|
||||
|
||||
void sdcardInsertionDetectInit(void)
|
||||
{
|
||||
#ifdef SDCARD_DETECT_PIN
|
||||
sdcardDetectPin = IOGetByTag(IO_TAG(SDCARD_DETECT_PIN));
|
||||
IOInit(sdcardDetectPin, OWNER_SDCARD, RESOURCE_INPUT);
|
||||
IOConfigGPIO(sdcardDetectPin, SPI_IO_CS_CFG);
|
||||
sdCardDetectPin = IOGetByTag(IO_TAG(SDCARD_DETECT_PIN));
|
||||
IOInit(sdCardDetectPin, OWNER_SDCARD, RESOURCE_INPUT);
|
||||
IOConfigGPIO(sdCardDetectPin, IOCFG_IPU);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -146,7 +149,7 @@ bool sdcard_isInserted(void)
|
|||
|
||||
#ifdef SDCARD_DETECT_PIN
|
||||
|
||||
result = IORead(sdcardDetectPin) != 0;
|
||||
result = IORead(sdCardDetectPin) != 0;
|
||||
|
||||
#ifdef SDCARD_DETECT_INVERTED
|
||||
result = !result;
|
||||
|
@ -542,6 +545,12 @@ void sdcard_init(bool useDMA)
|
|||
(void) useDMA;
|
||||
#endif
|
||||
|
||||
#ifdef SDCARD_SPI_CS_PIN
|
||||
sdCardCsPin = IOGetByTag(IO_TAG(SDCARD_SPI_CS_PIN));
|
||||
IOInit(sdCardCsPin, OWNER_SDCARD, RESOURCE_SPI);
|
||||
IOConfigGPIO(sdCardCsPin, SPI_IO_CS_CFG);
|
||||
#endif // SDCARD_SPI_CS_PIN
|
||||
|
||||
// Max frequency is initially 400kHz
|
||||
spiSetDivisor(SDCARD_SPI_INSTANCE, SDCARD_SPI_INITIALIZATION_CLOCK_DIVIDER);
|
||||
|
||||
|
@ -554,15 +563,13 @@ void sdcard_init(bool useDMA)
|
|||
spiTransfer(SDCARD_SPI_INSTANCE, NULL, NULL, SDCARD_INIT_NUM_DUMMY_BYTES);
|
||||
|
||||
// Wait for that transmission to finish before we enable the SDCard, so it receives the required number of cycles:
|
||||
int time = 0;
|
||||
int time = 100000;
|
||||
while (spiIsBusBusy(SDCARD_SPI_INSTANCE)) {
|
||||
if (time > 10) {
|
||||
if (time-- == 0) {
|
||||
sdcard.state = SDCARD_STATE_NOT_PRESENT;
|
||||
sdcard.failureCount++;
|
||||
return;
|
||||
}
|
||||
delay(1000);
|
||||
time++;
|
||||
}
|
||||
|
||||
sdcard.operationStartTime = millis();
|
||||
|
|
|
@ -377,9 +377,13 @@ void init(void)
|
|||
#endif
|
||||
|
||||
#ifdef USE_SPI
|
||||
#ifdef USE_SPI_DEVICE_1
|
||||
spiInit(SPIDEV_1);
|
||||
#endif
|
||||
#ifdef USE_SPI_DEVICE_2
|
||||
spiInit(SPIDEV_2);
|
||||
#ifdef STM32F303xC
|
||||
#endif
|
||||
#ifdef USE_SPI_DEVICE_3
|
||||
#ifdef ALIENFLIGHTF3
|
||||
if (hardwareRevision == AFF3_REV_2) {
|
||||
spiInit(SPIDEV_3);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8)
|
||||
#define CONFIG_SERIALRX_PROVIDER SERIALRX_SBUS
|
||||
#define CONFIG_BLACKBOX_DEVICE BLACKBOX_DEVICE_NONE
|
||||
#define CONFIG_BLACKBOX_DEVICE BLACKBOX_DEVICE_SDCARD
|
||||
#define CONFIG_FEATURE_RX_SERIAL
|
||||
#define CONFIG_FEATURE_ONESHOT125
|
||||
#define CONFIG_RX_SERIAL_PORT 3
|
||||
|
@ -60,7 +60,7 @@
|
|||
#define USE_BARO_MS5611
|
||||
#define MS5611_I2C_INSTANCE I2CDEV_1
|
||||
|
||||
//#define USE_SDCARD
|
||||
#define USE_SDCARD
|
||||
|
||||
#define SDCARD_DETECT_INVERTED
|
||||
|
||||
|
|
|
@ -384,7 +384,7 @@ uint32_t hse_value = HSE_VALUE;
|
|||
#endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F401xx || STM32F469_479xx */
|
||||
|
||||
/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
|
||||
#define PLL_Q 8
|
||||
#define PLL_Q 7
|
||||
|
||||
#if defined(STM32F446xx)
|
||||
/* PLL division factor for I2S, SAI, SYSTEM and SPDIF: Clock = PLL_VCO / PLLR */
|
||||
|
@ -398,7 +398,7 @@ uint32_t hse_value = HSE_VALUE;
|
|||
#endif /* STM32F427_437x || STM32F429_439xx || STM32F446xx || STM32F469_479xx */
|
||||
|
||||
#if defined (STM32F40_41xxx)
|
||||
#define PLL_N 384
|
||||
#define PLL_N 336
|
||||
/* SYSCLK = PLL_VCO / PLL_P */
|
||||
#define PLL_P 2
|
||||
#endif /* STM32F40_41xxx */
|
||||
|
@ -434,7 +434,7 @@ uint32_t hse_value = HSE_VALUE;
|
|||
*/
|
||||
|
||||
#if defined(STM32F40_41xxx)
|
||||
uint32_t SystemCoreClock = 192000000;
|
||||
uint32_t SystemCoreClock = 168000000;
|
||||
#endif /* STM32F40_41xxx */
|
||||
|
||||
#if defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F446xx) || defined(STM32F469_479xx)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue