2009-11-28 10:28:11 +01:00
|
|
|
/**
|
2009-11-29 11:03:08 +01:00
|
|
|
******************************************************************************
|
2009-11-28 12:25:16 +01:00
|
|
|
*
|
2009-11-29 11:03:08 +01:00
|
|
|
* @file pios_sys.c
|
2010-01-31 18:56:54 +01:00
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* Parts by Thorsten Klose (tk@midibox.org) (tk@midibox.org)
|
2009-11-29 11:03:08 +01:00
|
|
|
* @brief Sets up basic system hardware, functions are called from Main.
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
2009-11-30 10:26:01 +01:00
|
|
|
* @defgroup PIOS_SYS System Functions
|
2009-11-29 13:38:42 +01:00
|
|
|
* @{
|
2009-11-29 11:03:08 +01:00
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2009-11-28 10:28:11 +01:00
|
|
|
/*
|
|
|
|
* This program 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2009-11-29 07:09:33 +01:00
|
|
|
|
2009-11-28 10:28:11 +01:00
|
|
|
/* Project Includes */
|
|
|
|
#include "pios.h"
|
|
|
|
|
2010-02-28 07:47:49 +01:00
|
|
|
#if !defined(PIOS_DONT_USE_SYS)
|
|
|
|
|
|
|
|
|
2009-11-29 07:09:33 +01:00
|
|
|
/* Private Function Prototypes */
|
|
|
|
void NVIC_Configuration(void);
|
2010-01-21 00:48:04 +01:00
|
|
|
void SysTick_Handler(void);
|
2009-12-22 07:28:12 +01:00
|
|
|
|
2010-01-31 17:48:23 +01:00
|
|
|
/* Local Macros */
|
|
|
|
#define MEM8(addr) (*((volatile uint8_t *)(addr)))
|
|
|
|
|
2009-11-29 08:15:59 +01:00
|
|
|
/**
|
2010-02-28 09:44:01 +01:00
|
|
|
* Initialises all system peripherals
|
2009-11-29 08:15:59 +01:00
|
|
|
*/
|
2009-12-08 03:13:21 +01:00
|
|
|
void PIOS_SYS_Init(void)
|
2009-11-28 10:28:11 +01:00
|
|
|
{
|
2009-11-28 15:16:50 +01:00
|
|
|
/* Setup STM32 system (RCC, clock, PLL and Flash configuration) - CMSIS Function */
|
2009-11-28 10:28:11 +01:00
|
|
|
SystemInit();
|
|
|
|
|
2010-01-23 18:31:14 +01:00
|
|
|
/* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */
|
2010-02-28 09:44:01 +01:00
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
|
2010-01-23 18:31:14 +01:00
|
|
|
|
|
|
|
/* Activate pull-ups on all pins by default */
|
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
GPIO_StructInit(&GPIO_InitStructure);
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
|
|
|
GPIO_InitStructure.GPIO_Pin = 0xffff;
|
|
|
|
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|
|
|
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
2010-02-28 09:44:01 +01:00
|
|
|
#if (PIOS_USB_ENABLED)
|
|
|
|
GPIO_InitStructure.GPIO_Pin = 0xffff & ~GPIO_Pin_11 & ~GPIO_Pin_12; /* Exclude USB pins */
|
|
|
|
#endif
|
|
|
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
2010-01-23 18:31:14 +01:00
|
|
|
|
2010-02-28 09:44:01 +01:00
|
|
|
#if (PIOS_USB_ENABLED)
|
2010-02-12 11:11:17 +01:00
|
|
|
/* Ensure that pull-up is active on detect pin */
|
2010-01-25 16:23:55 +01:00
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
2010-02-28 09:44:01 +01:00
|
|
|
GPIO_InitStructure.GPIO_Pin = PIOS_USB_DETECT_GPIO_PIN;
|
|
|
|
GPIO_Init(PIOS_USB_DETECT_GPIO_PORT, &GPIO_InitStructure);
|
|
|
|
#endif
|
2010-01-23 18:31:14 +01:00
|
|
|
|
2010-02-28 09:44:01 +01:00
|
|
|
/* Initialise Basic NVIC */
|
2009-11-28 10:28:11 +01:00
|
|
|
NVIC_Configuration();
|
2010-03-04 08:07:27 +01:00
|
|
|
|
|
|
|
#if !defined(PIOS_DONT_USE_LED)
|
2010-02-28 09:44:01 +01:00
|
|
|
/* Initialise LEDs */
|
2009-12-08 03:13:21 +01:00
|
|
|
PIOS_LED_Init();
|
2010-03-04 08:07:27 +01:00
|
|
|
#endif
|
2009-11-28 10:28:11 +01:00
|
|
|
}
|
|
|
|
|
2010-01-31 17:48:23 +01:00
|
|
|
/**
|
|
|
|
* Returns the serial number as a string
|
|
|
|
* param[out] str pointer to a string which can store at least 32 digits + zero terminator!
|
|
|
|
* (24 digits returned for STM32)
|
|
|
|
* return < 0 if feature not supported
|
|
|
|
*/
|
|
|
|
int32_t PIOS_SYS_SerialNumberGet(char *str)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Stored in the so called "electronic signature" */
|
|
|
|
for(i=0; i<24; ++i) {
|
|
|
|
uint8_t b = MEM8(0x1ffff7e8 + (i/2));
|
|
|
|
if( !(i & 1) )
|
|
|
|
b >>= 4;
|
|
|
|
b &= 0x0f;
|
|
|
|
|
|
|
|
str[i] = ((b > 9) ? ('A'-10) : '0') + b;
|
|
|
|
}
|
|
|
|
str[i] = 0;
|
|
|
|
|
|
|
|
/* No error */
|
|
|
|
return 0;
|
|
|
|
}
|
2009-11-29 07:09:33 +01:00
|
|
|
|
2009-11-29 08:15:59 +01:00
|
|
|
/**
|
2009-11-29 15:21:50 +01:00
|
|
|
* Configures Vector Table base location and SysTick
|
2009-11-29 08:15:59 +01:00
|
|
|
*/
|
2009-11-28 10:28:11 +01:00
|
|
|
void NVIC_Configuration(void)
|
|
|
|
{
|
|
|
|
/* Set the Vector Table base address as specified in .ld file */
|
|
|
|
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
|
2009-11-29 07:09:33 +01:00
|
|
|
|
2010-02-28 09:44:01 +01:00
|
|
|
/* 4 bits for Interrupt priorities so no sub priorities */
|
2009-11-28 10:28:11 +01:00
|
|
|
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
|
|
|
|
|
|
|
|
/* Configure HCLK clock as SysTick clock source. */
|
2010-01-23 18:31:14 +01:00
|
|
|
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
|
2009-11-28 10:28:11 +01:00
|
|
|
}
|
2009-11-30 12:42:05 +01:00
|
|
|
|
2010-02-28 09:44:01 +01:00
|
|
|
#ifdef USE_FULL_ASSERT
|
2009-11-30 12:42:05 +01:00
|
|
|
/**
|
|
|
|
* Reports the name of the source file and the source line number
|
|
|
|
* where the assert_param error has occurred.
|
|
|
|
* \param[in] file pointer to the source file name
|
|
|
|
* \param[in] line assert_param error line source number
|
|
|
|
* \retval None
|
|
|
|
*/
|
|
|
|
void assert_failed(uint8_t* file, uint32_t line)
|
|
|
|
{
|
|
|
|
/* When serial debugging is implemented, use something like this. */
|
|
|
|
/* printf("Wrong parameters value: file %s on line %d\r\n", file, line); */
|
|
|
|
|
|
|
|
/* Setup the LEDs to Alternate */
|
2009-12-08 03:13:21 +01:00
|
|
|
PIOS_LED_On(LED1);
|
|
|
|
PIOS_LED_Off(LED2);
|
2009-11-30 12:42:05 +01:00
|
|
|
|
|
|
|
/* Infinite loop */
|
|
|
|
while (1)
|
|
|
|
{
|
2009-12-08 03:13:21 +01:00
|
|
|
PIOS_LED_Toggle(LED1);
|
|
|
|
PIOS_LED_Toggle(LED2);
|
2010-01-21 00:48:04 +01:00
|
|
|
for(int i = 0; i < 1000000; i++);
|
2009-11-30 12:42:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-02-28 07:47:49 +01:00
|
|
|
|
|
|
|
#endif
|