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.
Fork of DISCO-L072CZ-LRWAN1_LoRa_PingPong by
main.cpp
00001 /* 00002 * Copyright (c) 2017 Helmut Tschemernjak 00003 * 30826 Garbsen (Hannover) Germany 00004 * Licensed under the Apache License, Version 2.0); 00005 */ 00006 #include "main.h" 00007 00008 DigitalOut myled(LED1); 00009 BufferedSerial *ser; 00010 00011 int main() { 00012 SystemClock_Config(); 00013 ser = new BufferedSerial(USBTX, USBRX); 00014 ser->baud(115200*2); 00015 ser->format(8); 00016 myled = 1; 00017 00018 Receiver(); 00019 } 00020 00021 00022 00023 00024 void SystemClock_Config(void) 00025 { 00026 #ifdef B_L072Z_LRWAN1_LORA 00027 /* 00028 * The L072Z_LRWAN1_LORA clock setup is somewhat differnt from the Nucleo board. 00029 * It has no LSE. 00030 */ 00031 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 00032 RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 00033 00034 /* Enable HSE Oscillator and Activate PLL with HSE as source */ 00035 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 00036 RCC_OscInitStruct.HSEState = RCC_HSE_OFF; 00037 RCC_OscInitStruct.HSIState = RCC_HSI_ON; 00038 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 00039 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 00040 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; 00041 RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_6; 00042 RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_3; 00043 00044 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { 00045 // Error_Handler(); 00046 } 00047 00048 /* Set Voltage scale1 as MCU will run at 32MHz */ 00049 __HAL_RCC_PWR_CLK_ENABLE(); 00050 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); 00051 00052 /* Poll VOSF bit of in PWR_CSR. Wait until it is reset to 0 */ 00053 while (__HAL_PWR_GET_FLAG(PWR_FLAG_VOS) != RESET) {}; 00054 00055 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 00056 clocks dividers */ 00057 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); 00058 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 00059 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 00060 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 00061 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 00062 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) { 00063 // Error_Handler(); 00064 } 00065 #endif 00066 } 00067 00068 void dump(const char *title, const void *data, int len, bool dwords) 00069 { 00070 dprintf("dump(\"%s\", 0x%x, %d bytes)", title, data, len); 00071 00072 int i, j, cnt; 00073 unsigned char *u; 00074 const int width = 16; 00075 const int seppos = 7; 00076 00077 cnt = 0; 00078 u = (unsigned char *)data; 00079 while (len > 0) { 00080 ser->printf("%08x: ", (unsigned int)data + cnt); 00081 if (dwords) { 00082 unsigned int *ip = ( unsigned int *)u; 00083 ser->printf(" 0x%08x\r\n", *ip); 00084 u+= 4; 00085 len -= 4; 00086 cnt += 4; 00087 continue; 00088 } 00089 cnt += width; 00090 j = len < width ? len : width; 00091 for (i = 0; i < j; i++) { 00092 ser->printf("%2.2x ", *(u + i)); 00093 if (i == seppos) 00094 ser->putc(' '); 00095 } 00096 ser->putc(' '); 00097 if (j < width) { 00098 i = width - j; 00099 if (i > seppos + 1) 00100 ser->putc(' '); 00101 while (i--) { 00102 printf("%s", " "); 00103 } 00104 } 00105 for (i = 0; i < j; i++) { 00106 int c = *(u + i); 00107 if (c >= ' ' && c <= '~') 00108 ser->putc(c); 00109 else 00110 ser->putc('.'); 00111 if (i == seppos) 00112 ser->putc(' '); 00113 } 00114 len -= width; 00115 u += width; 00116 ser->printf("\r\n"); 00117 } 00118 ser->printf("--\r\n"); 00119 }
Generated on Thu Jul 14 2022 18:25:31 by
1.7.2
