Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
1.7 KiB

  1. /*
  2. * More info here:
  3. * https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill.html
  4. *
  5. * And resistor fix:
  6. * https://amitesh-singh.github.io/stm32/2017/05/27/Overcoming-wrong-pullup-in-blue-pill.html
  7. *
  8. * Note: I didn't have to do this fix, and things seem to work fine.
  9. */
  10. #include <stm32f1xx_hal_flash.h>
  11. #include <stm32f1xx_hal_rcc.h>
  12. #include <sysinit.h>
  13. /*
  14. * Referenced from:
  15. * Projects/STM32F103RB-Nucleo/Applications/USB_Device/HID_Standalone/Src/main.c
  16. */
  17. static void
  18. oscconfig(const void *none)
  19. {
  20. RCC_ClkInitTypeDef clkinitstruct;
  21. RCC_OscInitTypeDef oscinitstruct;
  22. RCC_PeriphCLKInitTypeDef rccperiphclkinit;
  23. __HAL_RCC_PWR_CLK_ENABLE();
  24. oscinitstruct = (RCC_OscInitTypeDef){
  25. .OscillatorType = RCC_OSCILLATORTYPE_HSE,
  26. .HSEState = RCC_HSE_ON,
  27. .HSEPredivValue = RCC_HSE_PREDIV_DIV1,
  28. .PLL.PLLMUL = RCC_PLL_MUL9,
  29. .PLL.PLLState = RCC_PLL_ON,
  30. .PLL.PLLSource = RCC_PLLSOURCE_HSE,
  31. };
  32. HAL_RCC_OscConfig(&oscinitstruct);
  33. /* USB clock selection */
  34. rccperiphclkinit = (RCC_PeriphCLKInitTypeDef){
  35. .PeriphClockSelection = RCC_PERIPHCLK_USB,
  36. .UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5,
  37. };
  38. HAL_RCCEx_PeriphCLKConfig(&rccperiphclkinit);
  39. /*
  40. * Select PLL as system clock source and configure the HCLK,
  41. * PCLK1 and PCLK2 clocks dividers
  42. */
  43. clkinitstruct = (RCC_ClkInitTypeDef){
  44. .ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |
  45. RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2),
  46. .SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK,
  47. .AHBCLKDivider = RCC_SYSCLK_DIV1,
  48. .APB1CLKDivider = RCC_HCLK_DIV2,
  49. .APB2CLKDivider = RCC_HCLK_DIV1,
  50. };
  51. HAL_RCC_ClockConfig(&clkinitstruct, FLASH_LATENCY_2);
  52. }
  53. SYSINIT(oscconfig, SI_SUB_HAL, SI_ORDER_THIRD, oscconfig, NULL);