Skip to content

Commit 62a0f0a

Browse files
committed
Merge pull request #234 from bcostm/master
[NUCLEO_F302R8] Use mbed_sdk_init() to update the SystemCoreClock variab...
2 parents e2ab4b9 + 8f523da commit 62a0f0a

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_NUCLEO_F302R8/TOOLCHAIN_ARM_MICRO/stm32f302x8.sct

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ LR_IROM1 0x08000000 0x10000 { ; load region size_region
3737
}
3838

3939
; 98 vectors (16 core + 82 peripheral) * 4 bytes = 392 bytes to reserve (0x188)
40-
; + 4 more bytes reserved for the SystemCoreClock variable
41-
RW_IRAM1 (0x20000000+(0x188+4)) (0x4000-(0x188+4)) { ; RW data
40+
RW_IRAM1 (0x20000000+0x188) (0x4000-0x188) { ; RW data
4241
.ANY (+RW +ZI)
4342
}
4443

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_NUCLEO_F302R8/TOOLCHAIN_ARM_STD/stm32f302x8.sct

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ LR_IROM1 0x08000000 0x10000 { ; load region size_region
3737
}
3838

3939
; 98 vectors (16 core + 82 peripheral) * 4 bytes = 392 bytes to reserve (0x188)
40-
; + 4 more bytes reserved for the SystemCoreClock variable
41-
RW_IRAM1 (0x20000000+(0x188+4)) (0x4000-(0x188+4)) { ; RW data
40+
RW_IRAM1 (0x20000000+0x188) (0x4000-0x188) { ; RW data
4241
.ANY (+RW +ZI)
4342
}
4443

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_NUCLEO_F302R8/system_stm32f30x.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,7 @@
141141
* @{
142142
*/
143143

144-
// [TODO] Do the same for other compilers
145-
// Warning: the RAM is initialized AFTER the SetSysClock function is called.
146-
// This variable must be placed outside the initialized section (see scatter file).
147-
uint32_t SystemCoreClock __attribute__((at(0x20000188))) = 64000000; /* Default with HSI. Will be updated if HSE is used */
144+
uint32_t SystemCoreClock = 64000000; /* Default with HSI. Will be updated if HSE is used */
148145

149146
__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
150147

@@ -361,11 +358,15 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
361358
__IO uint32_t HSEStatus = 0;
362359

363360
/* Bypass HSE: can be done only if HSE is OFF */
361+
RCC->CR &= ((uint32_t)~RCC_CR_HSEON); /* To be sure HSE is OFF */
364362
if (bypass != 0)
365363
{
366-
RCC->CR &= ((uint32_t)~RCC_CR_HSEON); /* To be sure HSE is OFF */
367364
RCC->CR |= ((uint32_t)RCC_CR_HSEBYP);
368365
}
366+
else
367+
{
368+
RCC->CR &= ((uint32_t)~RCC_CR_HSEBYP);
369+
}
369370

370371
/* Enable HSE */
371372
RCC->CR |= ((uint32_t)RCC_CR_HSEON);
@@ -412,7 +413,6 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
412413
{
413414
}
414415

415-
SystemCoreClock = 72000000;
416416
return 1; // OK
417417
}
418418
else
@@ -460,7 +460,6 @@ uint8_t SetSysClock_PLL_HSI(void)
460460
{
461461
}
462462

463-
SystemCoreClock = 64000000;
464463
return 1; // OK
465464
}
466465

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2014, STMicroelectronics
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
14+
* may be used to endorse or promote products derived from this software
15+
* without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
extern void SystemCoreClockUpdate(void);
30+
31+
// This function is called after RAM initialization and before main.
32+
void mbed_sdk_init() {
33+
// Update the SystemCoreClock variable.
34+
SystemCoreClockUpdate();
35+
}

0 commit comments

Comments
 (0)