Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed LoRaWAN-lib SX1276Lib
Revision 11:876331d64e0e, committed 2018-12-31
- Comitter:
- a22zsolutions
- Date:
- Mon Dec 31 04:11:05 2018 +0000
- Parent:
- 10:4e528716aa7a
- Commit message:
- use hse clock
Changed in this revision
| app/main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/app/main.cpp Thu Dec 27 18:37:04 2018 +0000
+++ b/app/main.cpp Mon Dec 31 04:11:05 2018 +0000
@@ -717,8 +717,78 @@
/**
* Main application entry point.
*/
+Serial pc(SERIAL_TX, SERIAL_RX,115200);
+int MY_SetSysClock_PLL_HSE(void)
+{
+ RCC_ClkInitTypeDef RCC_ClkInitStruct;
+ RCC_OscInitTypeDef RCC_OscInitStruct;
+
+ /* Enable HSE and activate PLL with HSE as source */
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
+ RCC_OscInitStruct.HSEState = RCC_HSE_ON; /* External 8 MHz xtal on OSC_IN/OSC_OUT */
+
+ // PLLCLK = (8 MHz * 8)/2 = 32 MHz
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+ RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
+ RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_8;
+ RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2;
+ if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
+ return (-1); // FAIL
+ }
+
+ /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
+ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
+ RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; // 32 MHz
+ RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; // 32 MHz
+ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; // 32 MHz
+ RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // 32 MHz
+ if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
+ return (-2); // FAIL
+ }
+
+ /* Enable HSE and activate PLL with HSE as source */
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_MSI;
+ RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
+ RCC_OscInitStruct.MSIState = RCC_MSI_OFF;
+ RCC_OscInitStruct.HSI48State = RCC_HSI48_OFF;
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
+ if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
+ return (-3); // FAIL
+ }
+
+ return 0; // OK
+}
+
+void my_patch(void)
+{
+ int retVal;
+
+ HAL_RCC_DeInit();
+ retVal = MY_SetSysClock_PLL_HSE();
+ if(retVal< 0)
+ {
+ // fail
+ pc.printf("Failed to start HSE, ERR= %d\r\n", retVal);
+
+ // indicate error
+ while(1)
+ {
+ myled = 1;
+ wait(0.2);
+ myled = 0;
+ wait(0.5);
+ }
+ }
+}
+
int main( void )
{
+ pc.printf("mbed-os-rev: %d.%d.%d lib-rev: %d\r\n", \
+ MBED_MAJOR_VERSION, MBED_MINOR_VERSION,MBED_PATCH_VERSION,MBED_LIBRARY_VERSION);
+ pc.printf("BUILD= %s, SysClock= %d, RCC= %0X\r\n", __TIME__, SystemCoreClock, RCC->CR);
+ my_patch();
+ pc.printf("NEW SysClock= %d, NEW RCC= %0X\r\n", SystemCoreClock, RCC->CR);
+
flash_builtin();
flash_builtin();
flash_builtin();