Skip to content

[NUCLEO_L152RE/F103RB] Add LSE configuration for RTC #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@
#define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */

#if !defined (LSE_VALUE)
#define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
#endif

/**
* @brief STM32F10x Standard Peripheral Library version number
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Cloc

extern void SystemInit(void);
extern void SystemCoreClockUpdate(void);
extern void SetSysClock(void);

/**
* @}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ typedef enum {
} ADCName;

typedef enum {
UART_1 = (int)USART1_BASE,
UART_1 = (int)USART1_BASE,
UART_2 = (int)USART2_BASE,
UART_3 = (int)USART3_BASE
} UARTName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "analogin_api.h"
#include "wait_api.h"

#if DEVICE_ANALOGIN

#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#include "wait_api.h"

static const PinMap PinMap_ADC[] = {
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AIN, 0)}, // ADC12_IN0
Expand All @@ -57,15 +57,14 @@ static const PinMap PinMap_ADC[] = {
int adc_inited = 0;

void analogin_init(analogin_t *obj, PinName pin) {

ADC_TypeDef *adc;
ADC_TypeDef *adc;
ADC_InitTypeDef ADC_InitStructure;

// Get the peripheral name from the pin and assign it to the object
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);

if (obj->adc == (ADCName)NC) {
error("ADC pin mapping failed");
error("ADC pin mapping failed");
}

// Configure GPIO
Expand All @@ -80,12 +79,12 @@ void analogin_init(analogin_t *obj, PinName pin) {

// Get ADC registers structure address
adc = (ADC_TypeDef *)(obj->adc);

// Enable ADC clock (14 MHz maximum)
// PCLK2 = 64 MHz --> ADC clock = 64/6 = 10.666 MHz
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

// Configure ADC
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
Expand All @@ -100,87 +99,87 @@ void analogin_init(analogin_t *obj, PinName pin) {

// Calibrate ADC
ADC_ResetCalibration(adc);
while(ADC_GetResetCalibrationStatus(adc));
while (ADC_GetResetCalibrationStatus(adc));
ADC_StartCalibration(adc);
while(ADC_GetCalibrationStatus(adc));
while (ADC_GetCalibrationStatus(adc));
}
}

static inline uint16_t adc_read(analogin_t *obj) {
// Get ADC registers structure address
ADC_TypeDef *adc = (ADC_TypeDef *)(obj->adc);
int channel = 0;
// Configure ADC channel
switch (obj->pin) {
case PA_0:
channel = 0;
break;
case PA_1:
channel = 1;
break;
case PA_2:
channel = 2;
break;
case PA_3:
channel = 3;
break;
case PA_4:
channel = 4;
break;
case PA_5:
channel = 5;
break;
case PA_6:
channel = 6;
break;
case PA_7:
channel = 7;
break;
case PB_0:
channel = 8;
break;
case PB_1:
channel = 9;
break;
case PC_0:
channel = 10;
break;
case PC_1:
channel = 11;
break;
case PC_2:
channel = 12;
break;
case PC_3:
channel = 13;
break;
case PC_4:
channel = 14;
break;
case PC_5:
channel = 15;
break;
default:
return 0;
}

ADC_RegularChannelConfig(adc, channel, 1, ADC_SampleTime_7Cycles5);
ADC_SoftwareStartConvCmd(adc, ENABLE); // Start conversion
while(ADC_GetFlagStatus(adc, ADC_FLAG_EOC) == RESET); // Wait end of conversion
return(ADC_GetConversionValue(adc)); // Get conversion value
// Get ADC registers structure address
ADC_TypeDef *adc = (ADC_TypeDef *)(obj->adc);
int channel = 0;

// Configure ADC channel
switch (obj->pin) {
case PA_0:
channel = 0;
break;
case PA_1:
channel = 1;
break;
case PA_2:
channel = 2;
break;
case PA_3:
channel = 3;
break;
case PA_4:
channel = 4;
break;
case PA_5:
channel = 5;
break;
case PA_6:
channel = 6;
break;
case PA_7:
channel = 7;
break;
case PB_0:
channel = 8;
break;
case PB_1:
channel = 9;
break;
case PC_0:
channel = 10;
break;
case PC_1:
channel = 11;
break;
case PC_2:
channel = 12;
break;
case PC_3:
channel = 13;
break;
case PC_4:
channel = 14;
break;
case PC_5:
channel = 15;
break;
default:
return 0;
}

ADC_RegularChannelConfig(adc, channel, 1, ADC_SampleTime_7Cycles5);

ADC_SoftwareStartConvCmd(adc, ENABLE); // Start conversion

while (ADC_GetFlagStatus(adc, ADC_FLAG_EOC) == RESET); // Wait end of conversion

return (ADC_GetConversionValue(adc)); // Get conversion value
}

uint16_t analogin_read_u16(analogin_t *obj) {
return(adc_read(obj));
return (adc_read(obj));
}

float analogin_read(analogin_t *obj) {
uint16_t value = adc_read(obj);
return (float)value * (1.0f / (float)0xFFF); // 12 bits range
uint16_t value = adc_read(obj);
return (float)value * (1.0f / (float)0xFFF); // 12 bits range
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
#define DEVICE_INTERRUPTIN 1

#define DEVICE_ANALOGIN 1
#define DEVICE_ANALOGOUT 0
#define DEVICE_ANALOGOUT 0 // Not present on this device

#define DEVICE_SERIAL 1

#define DEVICE_I2C 1
#define DEVICE_I2CSLAVE 0
#define DEVICE_I2CSLAVE 0 // Not yet supported

#define DEVICE_SPI 1
#define DEVICE_SPISLAVE 0
#define DEVICE_SPISLAVE 0 // Not yet supported

#define DEVICE_RTC 1

Expand All @@ -63,7 +63,7 @@

#define DEVICE_STDIO_MESSAGES 1

//#define DEVICE_ERROR_RED 0
#define DEVICE_ERROR_RED 0

#include "objects.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

extern uint32_t Set_GPIO_Clock(uint32_t port_idx);

uint32_t gpio_set(PinName pin) {
uint32_t gpio_set(PinName pin) {
if (pin == NC) return 0;

pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
Expand All @@ -45,11 +45,11 @@ void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) return;

uint32_t port_index = STM_PORT(pin);

// Enable GPIO clock
uint32_t gpio_add = Set_GPIO_Clock(port_index);
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;

// Fill GPIO object structure for future use
obj->pin = pin;
obj->mask = gpio_set(pin);
Expand All @@ -65,8 +65,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (direction == PIN_OUTPUT) {
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_Out_PP, 0));
}
else { // PIN_INPUT
} else { // PIN_INPUT
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
}
}
Loading