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