cancel
Showing results for 
Search instead for 
Did you mean: 

HSE clock on STM32L100CDISCOVERY

david239955_stm1_st
Associate II
Posted on February 19, 2014 at 14:10

Hi all,

I have a question about HSE clock source. I loaded the demo and added some code to check the HSE clock on PA8.

...
GPIO_InitTypeDef GPIO_InitStructure;
...
int main(void){ 
...
RCC_HSEConfig(RCC_HSE_ON);
RCC_WaitForHSEStartUp();
/* GPIOA clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); 
RCC_MCOConfig(RCC_MCOSource_HSE , RCC_MCODiv_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_MCO); 
/*GPIOA Configuration: Pin 8*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; 
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; 
GPIO_Init(GPIOA, &GPIO_InitStructure); 
...

Then I measured with Oscilloscope on PA8 and it shows 4MHz , but when I measure direct on the pin of the oscillator it shows 8MHz. Where is the problem? Best Regards, David. #stm32l100cdiscovery
11 REPLIES 11
Posted on February 19, 2014 at 15:37

  /* SYSCFG Peripheral clock enable */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on February 19, 2014 at 15:50

>   /* SYSCFG Peripheral clock enable */

Why?

JW

Posted on February 19, 2014 at 16:20

A guess based on other STM32 architectures.

Would probably want the BYPASS mode on too if the 8 MHz is derived from the ST-LINK's STM32F103

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
david239955_stm1_st
Associate II
Posted on February 20, 2014 at 07:51

Hi clive1,

I added the line:

RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

And nothing changed, then i commented this line and added:

RCC_HSEConfig(RCC_HSE_ON);
RCC_HSEConfig(RCC_HSE_Bypass); // This one
RCC_WaitForHSEStartUp();

And now I have on PA8 the desired 8 MHz

Now I tried to do the same thing with mysystem_stm32l1xx.c file and again not working.

I added My file generated withSTM32L1xx_Clock_Configuration_V1.2.0

Thanks for help.

Best Regards,

David.

________________

Attachments :

MY_system_stm32l1xx.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hzzt&d=%2Fa%2F0X0000000bS0%2FWSCHjEzAmcOY61uK0ORbxshu_fCpksqMDgJ4SkfWnLw&asPdf=false
david239955_stm1_st
Associate II
Posted on February 21, 2014 at 08:54

Any suggestions? 

Best Regards,

David.

Posted on February 21, 2014 at 11:50

I'd have to put an STM32L100C-DISCO on the bench to confirm/understand your situation.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on February 21, 2014 at 23:12

    RCC_HSEConfig(RCC_HSE_Bypass);

Gets symmetric 8 MHz

    RCC_HSEConfig(RCC_HSE_ON);

Gets asymmetric 4 MHz, odd but duly noted.

The oscillator circuit doesn't need enabling as there is no crystal, but an external source.

The startup_stm32l1xx.c uses the PLL + HSI, so doesn't address the bypass mode like other DISCO boards have.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
david239955_stm1_st
Associate II
Posted on February 24, 2014 at 11:35

Hi clive1,

Thanks for the answer. Her is what I tried: First HSI picture attached http://itinypic.com/28cftqb.jpg. And added the line:

RCC_HSEConfig(RCC_HSE_Bypass);

and get the 8MHz. Second HSEpicture attached http://itinypic.com/28cftqb.jpg. Added the line:

RCC_HSEConfig(RCC_HSE_Bypass);
//or
RCC_HSEConfig(RCC_HSE_ON);
//or nothing

always get the 4MHz clk onRCC_MCOSource_HSE output. Next I tried to use timer for time base of 1ms with interrupt ie. to toggle GPIO. The code for timer:

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/*GPIOC clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
/* TIM3 clock enable in Time base mode*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
/*GPIOC Configuration: Pin 5*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* ------------------- TIMER Configuration -----------------------------------*/
/*TIM3*/
TIM_TimeBaseStructure.TIM_Prescaler =0;//31;
TIM_TimeBaseStructure.TIM_CounterMode =TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period =31999;//1000;
TIM_TimeBaseStructure.TIM_ClockDivision =0;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/*----------------------------------------------------------------------------*/
/* Enable the TIM3 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the TIM3 to generate interrupt */
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
/* Enable TIM3 */
TIM_Cmd(TIM3, ENABLE);
//Interrupt
/* TIM3 */
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
GPIO_ToggleBits(GPIOC, GPIO_Pin_5);
}
}

According to table:

* 5. This file configures the system clock as follows:
*=============================================================================
* System Clock Configuration
*=============================================================================
* System Clock source | PLL(HSI)
*-----------------------------------------------------------------------------
* SYSCLK | 32000000 Hz
*-----------------------------------------------------------------------------
* HCLK | 32000000 Hz
*-----------------------------------------------------------------------------
* AHB Prescaler | 1
*-----------------------------------------------------------------------------
* APB1 Prescaler | 1
*-----------------------------------------------------------------------------
* APB2 Prescaler | 1
*-----------------------------------------------------------------------------
* HSE Frequency | 8000000 Hz
*-----------------------------------------------------------------------------
* PLL DIV | 2
*-----------------------------------------------------------------------------
* PLL MUL | 4
*-----------------------------------------------------------------------------
* VDD | 3.3 V
*-----------------------------------------------------------------------------
* Vcore | 1.8 V (Range 1)
*-----------------------------------------------------------------------------
* Flash Latency | 1 WS
*-----------------------------------------------------------------------------
* Require 48MHz for USB clock | Disabled
*-----------------------------------------------------------------------------
*=============================================================================

Clk for TIM3 = 32MHz. Prescaler=0,Period=319 UpdateRate=TIMCLK/(prescaler+1)/(Period+1)=32MHz/1/32000=1kHz => 1ms update. When I measure the GPIOC PIN5 with the scope I get 500 Hz => 2ms ??? How or where can I check the value of HCLK, AHB Prescaler, APB1 Prescaler, PCLK1, TIM3CLK? Thank for Your time. Best Regards, David.
Posted on February 24, 2014 at 14:03

When I measure the GPIOC PIN5 with the scope I get 500 Hz => 2ms ???

Toggling tends to do that, as it doubles the period. You could call it twice in the interrupt handler.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..