Files
@ 7b13b1c2f3a1
Branch filter:
Location: therm/stm32l100c_discovery.c - annotation
7b13b1c2f3a1
4.8 KiB
text/plain
Relocated USB init. Need to test with ext xtal
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc dc0c251991cc | #include "stm32l100c_discovery.h"
GPIO_TypeDef* GPIO_PORT[LEDn] = {LED3_GPIO_PORT, LED4_GPIO_PORT};
const uint16_t GPIO_PIN[LEDn] = {LED3_PIN, LED4_PIN};
const uint32_t GPIO_CLK[LEDn] = {LED3_GPIO_CLK, LED4_GPIO_CLK};
GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_GPIO_PORT};
const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN};
const uint32_t BUTTON_CLK[BUTTONn] = {USER_BUTTON_GPIO_CLK};
const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {USER_BUTTON_EXTI_LINE};
const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {USER_BUTTON_EXTI_PORT_SOURCE};
const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {USER_BUTTON_EXTI_PIN_SOURCE};
const uint16_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn};
/**
* @brief Configures LED GPIO.
* @param Led: Specifies the Led to be configured.
* This parameter can be one of following parameters:
* @arg LED3
* @arg LED4
* @retval None
*/
void STM_EVAL_LEDInit(Led_TypeDef Led)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable the GPIO_LED Clock */
RCC_AHBPeriphClockCmd(GPIO_CLK[Led], ENABLE);
/* Configure the GPIO_LED pin */
GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
}
/**
* @brief Turns selected LED On.
* @param Led: Specifies the Led to be set on.
* This parameter can be one of following parameters:
* @arg LED3
* @arg LED4
* @retval None
*/
void STM_EVAL_LEDOn(Led_TypeDef Led)
{
GPIO_PORT[Led]->BSRRL = GPIO_PIN[Led];
}
/**
* @brief Turns selected LED Off.
* @param Led: Specifies the Led to be set off.
* This parameter can be one of following parameters:
* @arg LED3
* @arg LED4
* @retval None
*/
void STM_EVAL_LEDOff(Led_TypeDef Led)
{
GPIO_PORT[Led]->BSRRH = GPIO_PIN[Led];
}
/**
* @brief Toggles the selected LED.
* @param Led: Specifies the Led to be toggled.
* This parameter can be one of following parameters:
* @arg LED3
* @arg LED4
* @retval None
*/
void STM_EVAL_LEDToggle(Led_TypeDef Led)
{
GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
}
/**
* @brief Configures Button GPIO and EXTI Line.
* @param Button: Specifies the Button to be configured.
* This parameter can be:
* @arg BUTTON_USER: User Push Button
* @param Button_Mode: Specifies Button mode.
* This parameter can be one of following parameters:
* @arg BUTTON_MODE_GPIO: Button will be used as simple IO
* @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
* generation capability
* @retval None
*/
void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the BUTTON Clock */
RCC_AHBPeriphClockCmd(BUTTON_CLK[Button], ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Configure Button pin as input */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
if (Button_Mode == BUTTON_MODE_EXTI)
{
/* Connect Button EXTI Line to Button GPIO Pin */
SYSCFG_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
/* Configure Button EXTI line */
EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
if (Button != BUTTON_USER)
{
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
}
else
{
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
}
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable and set Button EXTI Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
}
/**
* @brief Returns the selected Button state.
* @param Button: Specifies the Button to be checked.
* This parameter can be one of following parameters:
* @arg BUTTON_USER: User Push Button
* @retval The Button GPIO pin value.
*/
uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
{
/* There is no Wakeup button on STM32f0-Discovery Kit */
return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
}
|