Necleo L152RE rtos sample (also for F401RE & F411RE mbed)

<updated on May 20th, 2015>
New information for L152 System Clock (see 3)a)).

1) Overview

As of today(May 16th, 2015), mbed-rtos is startting the Nucleo-L152RE mbed board officially mbed-rtos Revision 77).
Unfortunately there are still has a trouble for clock setting.
This note intends to explain how to modify the source code and demonstrate an example program using mbed-rtos.

Followings are points:
(1) Need to change Clock definition
L152RE clock (Two clock variant!):
32MHz to 24MHz (c-02 NEW Board) & Keep 32MHz (use RC internal clock, C-01 OLD original board)
F411RE clock: 100MHz to 96MHz
Please refer below for F411RE.
/users/kenjiArai/code/Nucleo_F411RE_SysClk/
(2) (Not rtos issue) Set RTC properly with External 32.768KHz clock
/users/kenjiArai/notebook/nucleo-series-rtc-control-under-power-onoff-and-re/
/users/kenjiArai/code/Nucleo_RTC_battery_bkup_pwr_off_okay/

2) Rev.77 mbed-rtos problem

Here is a sample program result.

PC_2 sets 1 sec target but result is 1.354 sec because 32/24 = 1.333.
PC_3 is 666.619 mSec / 1.333 = 500.09 mSec (yes, target 500mSec).
Here is a new revision which I modify the definition.

3) Software modification

a) System clock modification / L152RE Case

<This is old information>

/mbed-rtos/mbed-rtos/rtx/TARGET_CORTEX_M/RTX_Conf_CM.c

#if 1
#    define OS_CLOCK       24000000
#else
#    define OS_CLOCK       32000000
#endif

/mbed-src/targets/cmsis/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/system_stm32l1xx.c

#if 1
  // SYSCLK = 24 MHz ((8 MHz * 6) / 2)
  // USBCLK = 48 MHz (8 MHz * 6) --> USB OK
  RCC_OscInitStruct.PLL.PLLState        = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource       = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL          = RCC_PLL_MUL6;
  RCC_OscInitStruct.PLL.PLLDIV          = RCC_PLL_DIV2;
#else
  // SYSCLK = 32 MHz ((8 MHz * 8) / 2)
  // USBCLK = 48 MHz (8 MHz * 8) --> USB NG
  RCC_OscInitStruct.PLL.PLLState        = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource       = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL          = RCC_PLL_MUL8;
  RCC_OscInitStruct.PLL.PLLDIV          = RCC_PLL_DIV2;
#endif


<New Information (May 20th, 2015)>
Current problem
(1) Two System Clock Freq. 24MHz (base HSE) or 32MHz(base HSI) -> change performance without intention
(2) USB Clock is out of range (current setting cannot create 48MHz USB clock)

I found one important information in DM00098321.pdf page 22/134 as below.
/media/uploads/kenjiArai/l152_pll.png
PLL VCO must be set 96MHz!!

Followings are latest setting result.

------------------------------------------------
1) current setting (mbed rev.99) / Use HSE ->PLL VCO  = 8 x 6 = 48MHz

Use PLL with Mul=6, Div=2
Use HSE(not Xtal but External Clock)=8000000Hz
PLL freq=24000000Hz

SYSCLK clock freq. =24000000Hz
HCLK   clock freq. =24000000Hz
PCLK1  clock freq. =24000000Hz
PCLK2  clock freq. =24000000Hz

------------------------------------------------
2) current setting (mbed rev.99) / Use HSI ->PLL VCO  = 16 x 4 = 64MHz

Use PLL with Mul=4, Div=2
Use HSI(internal RC/High speed), RC=16000000Hz
PLL freq=32000000Hz

SYSCLK clock freq. =32000000Hz
HCLK   clock freq. =32000000Hz
PCLK1  clock freq. =32000000Hz
PCLK2  clock freq. =32000000Hz

------------------------------------------------
3) Best solution / Use HSE  ->PLL VCO  = 8 x 12 = 96MHz

Use PLL with Mul=12, Div=3
Use HSE(not Xtal but External Clock)=8000000Hz
PLL freq=32000000Hz

SYSCLK clock freq. =32000000Hz
HCLK   clock freq. =32000000Hz
PCLK1  clock freq. =32000000Hz
PCLK2  clock freq. =32000000Hz

------------------------------------------------
4) Best solution / Use HSI ->PLL VCO  = 16 x 6 = 96MHz

Use PLL with Mul=6, Div=3
Use HSI(internal RC/High speed), RC=16000000Hz
PLL freq=32000000Hz

SYSCLK clock freq. =32000000Hz
HCLK   clock freq. =32000000Hz
PCLK1  clock freq. =32000000Hz
PCLK2  clock freq. =32000000Hz

b) System clock modification / F411RE Case

/mbed-rtos/mbed-rtos/rtx/TARGET_CORTEX_M/RTX_Conf_CM.c

#if 1
#     define OS_CLOCK      96000000
#else
#     define OS_CLOCK     100000000
#endif

c) RTC related issue

If you don't need to use RTC function, you don't need any modification.

4) Check the setting condition

In the monitor screen on PC side, enter 'x' for HW monitor then enter "sf" then you can see following screen.
/media/uploads/kenjiArai/fs_cmd.png

5) Software

CAUTION!

Please read "modification_notice.h".
You can change System clock definition and RTC related issue.

Import programNucleo_rtos_sample

This is sample program for Nucleo L152RE (and F401RE & F411RE) mbed-rtos. You need to modify mbed-src and mbed-rtos before compile it.


Please log in to post comments.