board.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2006-2024, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-11-07 RealThread first version
  9. */
  10. #include <rtthread.h>
  11. #include <board.h>
  12. #include <drv_common.h>
  13. RT_WEAK void rt_hw_board_init()
  14. {
  15. extern void hw_board_init(char *clock_src, int32_t clock_src_freq, int32_t clock_target_freq);
  16. /* Heap initialization */
  17. #if defined(RT_USING_HEAP)
  18. rt_system_heap_init((void *) HEAP_BEGIN, (void *) HEAP_END);
  19. #endif
  20. hw_board_init(BSP_CLOCK_SOURCE, BSP_CLOCK_SOURCE_FREQ_MHZ, BSP_CLOCK_SYSTEM_FREQ_MHZ);
  21. /* Set the shell console output device */
  22. #if defined(RT_USING_DEVICE) && defined(RT_USING_CONSOLE)
  23. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  24. #endif
  25. /* Board underlying hardware initialization */
  26. #ifdef RT_USING_COMPONENTS_INIT
  27. rt_components_board_init();
  28. #endif
  29. }
  30. SPI_HandleTypeDef hspi2;
  31. void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
  32. {
  33. GPIO_InitTypeDef GPIO_InitStruct = {0};
  34. if(spiHandle->Instance==SPI2)
  35. {
  36. /* USER CODE BEGIN SPI2_MspInit 0 */
  37. /* USER CODE END SPI2_MspInit 0 */
  38. /* SPI2 clock enable */
  39. __HAL_RCC_SPI2_CLK_ENABLE();
  40. __HAL_RCC_GPIOB_CLK_ENABLE();
  41. /**SPI2 GPIO Configuration
  42. PB13 ------> SPI2_SCK
  43. PB14 ------> SPI2_MISO
  44. PB15 ------> SPI2_MOSI
  45. */
  46. GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  47. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  48. GPIO_InitStruct.Pull = GPIO_NOPULL;
  49. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  50. GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  51. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  52. /* USER CODE BEGIN SPI2_MspInit 1 */
  53. /*Configure GPIO pin Output Level */
  54. // HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
  55. //
  56. // /*Configure GPIO pin : PtPin */
  57. // GPIO_InitStruct.Pin = GPIO_PIN_12;
  58. // GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  59. // GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  60. // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  61. // HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  62. /* USER CODE END SPI2_MspInit 1 */
  63. }
  64. }
  65. static int SPI2_INIT(void)
  66. {
  67. HAL_SPI_MspInit(&hspi2);
  68. return RT_EOK;
  69. }
  70. INIT_BOARD_EXPORT(SPI2_INIT);