cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L051C6T6 MSI clock range problem

tomasz_matuska
Associate II
Posted on June 02, 2015 at 00:55

Hello!

I have a problem with MSI clock configuration on STM32L051C6T6. I wanted to test my device with this microcontroller and I generated a simple code for Keil MDK v5 (LED blinking and USART transmission) using a CubeMX tool. CubeMX generated SystemClock_Config function, that should set a MSI clock speed (range) at 536 kHz (listed below). But when I run the program, microcontroller does not work and everything seems to be dead. When I debugged the code, it get stucked at the macro that writes the value of the clock speed to the registers and Keil showed error Internal Communication Error. When I changed MSI clock speed to 072 kHz it works fine, but debug still get stucked at the same line as before. When I changed MSI clock speed to 144 kHz, code and debug work just fine. I double checked the code generated by CubeMX with all documents from ST website. Can somebody please explain me why the lower speeds do not work? Maybe I did something wrong? Please help me with my problem. Function generated by CubeMX

void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
__PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = 0;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_0;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
__SYSCFG_CLK_ENABLE();
}

#stm32l #clock-configuration #msi
15 REPLIES 15
tomasz_matuska
Associate II
Posted on June 04, 2015 at 21:25

Sorry for double post. 

I think the rest of the values of the registers are OK since setting higher clock speeds works fine. I am only changing those MSIRANGE bits.
Posted on June 05, 2015 at 09:15

I found out that I don't have a toolchain set up for 'L0 (and don't have time to play with it), but I was able to play with the L053-DISCOVERY in the debugger (EPS debugger on CodeBlocks, but I have a non-public preview as the production version does not support L0 yet). So I set in the debugger manually TIM2's OC to toggle the red LED (TIM2CH1->PA5), with ARR set to max (i.e. one toggle per 65536 clocks) the LED blinks rapidly. Then I changed RCC_ICSCR down from 5 to 0 and the LED blinked slower and slower with each change, as expected, and this worked flawlessly down to 0.

I might try to set up a toolchain and write some simple demo program during the weekend.

JW

tomasz_matuska
Associate II
Posted on June 09, 2015 at 14:37

So, have you been trying anything?

Posted on June 10, 2015 at 00:11

See attached .c file. Runs on the L053 DISCOVERY, should be easily adaptable to 'L

After reset, timer TIM2 is run to blink the red LED using output compare -> toggle on TIM2_CH1->PA5. The settings shown produce cca 12Hz (a really rapid blinking) with the reset-default MSI at range 5 (i.e. 2MHz), MSI as system clock, no AHB/APB prescaling.

When button connected to PA0 (idle->GND, pressed->VCC) is pressed, green LED connected to PB4 is lit and the next MSI range is selected (the red LED goes into a barely perceptible cca 25Hz blinking after the first press, then to a very slow once-in-3-seconds after the second button press, and then frequency of blinking doubles with every button press etc.). When the button is released, green LED goes off.

The attached bin could be loaded into the DISCOVERY simply by copying it into the virtual disk provided by the onboard STLinkv2/1.

JW

________________

Attachments :

msi_scaling.bin : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0gs&d=%2Fa%2F0X0000000bcV%2FNo5qYfyyyFMwz_g6wPb4PijrtcJILGq8BTXHidinzyg&asPdf=false

msi_scaling.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0gn&d=%2Fa%2F0X0000000bcW%2F22dhlj5C7mbAYJCeJK6X9zmViQOwo_E4G_zB0omgTEc&asPdf=false
tomasz_matuska
Associate II
Posted on June 10, 2015 at 12:10

Thanks, I am going to try it.

tomasz_matuska
Associate II
Posted on June 12, 2015 at 19:49

I wrote my own function with clock configuration and it works fine (debugg does not work, there is a freq limit for ST-LINK as previously mentioned). Your code Jan, works fine as well.

The conclusion is : CubeMX has some kind of bug, and generated automatically clock config function is not working properly. Maybe it is a Keil issue, maybe not.

Anyway I can move forward. Thank you for all your help.