1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

Delays fixed.

SD Card fixed and working, tested with 2Gb and 8Gb (SDHC) cards.
Changed startup_stm32f10x_HD.S to work with SysTick_Handler, needs to be changed back for FreeRTOS to work.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@132 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
gussy 2010-01-20 23:48:04 +00:00 committed by gussy
parent 90f1fab5fe
commit 998ab12de4
7 changed files with 77 additions and 37 deletions

View File

@ -41,15 +41,15 @@
//Using DMA
#define STM32_USE_DMA
//Setup for SPI1 on v1.2 hardware (CD is on GPIO_Pin_4)
//Setup for SPI1 on v1 hardware (CD is on GPIO_Pin_4)
#define CARD_SUPPLY_SWITCHABLE 0
#define SOCKET_WP_CP_CONNECTED 0
#define SPI_SD SPI1
//CS is on PC5
#define GPIO_CS GPIOC
#define RCC_APB2Periph_GPIO_CS RCC_APB2Periph_GPIOC
#define GPIO_Pin_CS GPIO_Pin_5
//CS is on PA4
#define GPIO_CS GPIOA
#define RCC_APB2Periph_GPIO_CS RCC_APB2Periph_GPIOA
#define GPIO_Pin_CS GPIO_Pin_4
#define GPIO_SPI_SD GPIOA
#define GPIO_Pin_SPI_SD_SCK GPIO_Pin_5

View File

@ -46,21 +46,27 @@ void PIOS_SDCARD_Init(void)
if(f_mount(0, &Fatfs[0]) != FR_OK) {
/* Failed to setup MicroSD memory structure, flash LED1 forever */
while(1) {
for(int i = 0; i < 100000; i++);
for(int i = 0; i < 1000000; i++);
PIOS_LED_Toggle(LED1);
}
} else {
/* Try to Open Logging file */
if ( f_open(&logfile, LOG_FILENAME, FA_CREATE_ALWAYS | FA_WRITE ) != FR_OK ) {
FRESULT foresult = f_open(&logfile, LOG_FILENAME, FA_CREATE_ALWAYS | FA_WRITE);
if (foresult != FR_OK) {
/* Failed to mount MicroSD or create file, flash LED1 forever */
PIOS_LED_Off(LED1);
PIOS_LED_Off(LED2);
while(1) {
for(int i = 0; i < 100000; i++);
for(int i = 0; i < 1000000; i++);
PIOS_LED_Toggle(LED1);
PIOS_LED_Toggle(LED2);
}
} else {
result = f_puts("Hello\n", &logfile );
if ( result != EOF ) { result = f_puts("pios rocks!\n", &logfile ); }
f_close( &logfile );
result = f_puts("Hello\n", &logfile);
if (result != EOF ) {
result = f_puts("pios rocks!\n", &logfile );
}
f_close(&logfile);
}
}
}

View File

@ -84,3 +84,24 @@ int32_t PIOS_DELAY_Wait_uS(uint16_t uS)
/* No error */
return 0;
}
/**
* Waits for a specific number of mS<BR>
* Example:<BR>
* \code
* // Wait for 500 mS
* PIOS_DELAY_Wait_mS(500);
* \endcode
* \param[in] mS delay (1..65535 milliseconds)
* \return < 0 on errors
*/
int32_t PIOS_DELAY_Wait_mS(uint16_t mS)
{
uint16_t start = PIOS_DELAY_TIMER->CNT;
/* Note that this event works on 16bit counter wrap-arounds */
while((uint16_t)(PIOS_DELAY_TIMER->CNT - start) <= (mS * 1000));
/* No error */
return 0;
}

View File

@ -31,14 +31,13 @@
/* Private Function Prototypes */
void NVIC_Configuration(void);
void SysTick_Handler(void);
/**
* Initializes all system peripherals
*/
void PIOS_SYS_Init(void)
{
/* Setup STM32 system (RCC, clock, PLL and Flash configuration) - CMSIS Function */
SystemInit();
@ -47,7 +46,6 @@ void PIOS_SYS_Init(void)
/* Initialize LEDs */
PIOS_LED_Init();
}
@ -63,7 +61,19 @@ void NVIC_Configuration(void)
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
/* Configure HCLK clock as SysTick clock source. */
SysTick_CLKSourceConfig( SysTick_CLKSource_HCLK );
//SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
/* Set SysTick to 10mS tick */
if(SysTick_Config(SystemFrequency / 100))
{
/* Capture error */
while (1);
}
}
void SysTick_Handler(void)
{
disk_timerproc();
}
#ifdef USE_FULL_ASSERT
@ -86,10 +96,9 @@ void assert_failed(uint8_t* file, uint32_t line)
/* Infinite loop */
while (1)
{
for(int i = 0; i < 1000; i++);
PIOS_LED_Toggle(LED1);
for(int i = 0; i < 1000; i++);
PIOS_LED_Toggle(LED2);
for(int i = 0; i < 1000000; i++);
}
}
#endif

View File

@ -155,7 +155,8 @@ g_pfnVectors:
.word DebugMon_Handler
.word 0
.word xPortPendSVHandler
.word xPortSysTickHandler
//.word xPortSysTickHandler
.word SysTick_Handler
.word WWDG_IRQHandler
.word PVD_IRQHandler
.word TAMPER_IRQHandler

View File

@ -30,6 +30,7 @@
/* Public Functions */
extern int32_t PIOS_DELAY_Init(void);
extern int32_t PIOS_DELAY_Wait_uS(uint16_t uS);
extern int32_t PIOS_DELAY_Wait_mS(uint16_t mS);
#endif /* PIOS_DELAY_H */

View File

@ -41,8 +41,9 @@ static uint32_t IdleTimePercent = 0;
void vApplicationIdleHook(void);
/* Function Prototypes */
void TestTask(void *pvParameters);
void TickTask(void *pvParameters);
void Flashy(void);
void SysTick_Handler(void);
/**
* Main function
@ -57,14 +58,16 @@ int main()
/* Delay system */
PIOS_DELAY_Init();
Flashy();
/* Enables the SDCard */
// PIOS_SDCARD_Init();
PIOS_SDCARD_Init();
/* Call LoadSettings which populates System Vars
so the rest of the hardware can be configured. */
// PIOS_Settings_Load();
//PIOS_Settings_Load();
for(;;) {
}
/* Com ports init */
// PIOS_COM_Init();
@ -77,7 +80,7 @@ int main()
/* Create a FreeRTOS task */
xTaskCreate( TestTask, ( signed portCHAR * ) "Test", configMINIMAL_STACK_SIZE , NULL, 2, NULL );
xTaskCreate(TickTask, (signed portCHAR *) "Test", configMINIMAL_STACK_SIZE , NULL, 2, NULL);
/* Start the FreeRTOS scheduler */
vTaskStartScheduler();
@ -105,19 +108,18 @@ void Flashy(void)
}
}
void TestTask( void *pvParameters )
void TickTask(void *pvParameters)
{
const portTickType xDelay = 500 / portTICK_RATE_MS;
const portTickType xDelay = 10 / portTICK_RATE_MS;
while(1)
{
PIOS_LED_Toggle(LED1);
vTaskDelay(xDelay);
}
for(;;)
{
PIOS_LED_Toggle(LED2);
vTaskDelay(xDelay);
}
}
/**
* Idle hook function
*/