tm4c123_config.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-06-27 AHTYDHD the first version
  9. * 2024-04-11 Astrozen add i2c support
  10. */
  11. #include <rtthread.h>
  12. #include <stdbool.h>
  13. #include <stdint.h>
  14. #include "inc/hw_memmap.h"
  15. #include "driverlib/rom.h"
  16. #include "driverlib/pin_map.h"
  17. #include "driverlib/sysctl.h"
  18. #include "driverlib/gpio.h"
  19. #include "tm4c123_config.h"
  20. #ifdef RT_USING_SERIAL
  21. #include "driverlib/uart.h"
  22. #endif /* RT_USING_SERIAL */
  23. #ifdef RT_USING_ADC
  24. #include "driverlib/adc.h"
  25. #endif /* RT_USING_ADC */
  26. #ifdef RT_USING_PWM
  27. #include "driverlib/pwm.h"
  28. #endif /* RT_USING_PWM */
  29. #ifdef RT_USING_SPI
  30. #include "driverlib/ssi.h"
  31. #endif /* RT_USING_SPI */
  32. #ifdef RT_USING_I2C
  33. #include "driverlib/i2c.h"
  34. #endif /* RT_USING_I2C */
  35. #ifdef RT_USING_SERIAL
  36. void uart_hw_config(void)
  37. {
  38. /* UART0 */
  39. SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
  40. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  41. GPIOPinConfigure(GPIO_PA0_U0RX);
  42. GPIOPinConfigure(GPIO_PA1_U0TX);
  43. GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
  44. /* UART1 */
  45. SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
  46. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
  47. GPIOPinConfigure(GPIO_PC4_U1RX);
  48. GPIOPinConfigure(GPIO_PC5_U1TX);
  49. GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5);
  50. }
  51. #endif /* RT_USING_SERIAL */
  52. #ifdef RT_USING_ADC
  53. void adc_hw_config(void)
  54. {
  55. /* ADC0 */
  56. SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
  57. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
  58. GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
  59. }
  60. #endif /* RT_USING_ADC */
  61. #ifdef RT_USING_PWM
  62. void pwm_hw_config(void)
  63. {
  64. /* PWM7 (PWM1 module,M1PWM6 and M1PWM7) */
  65. SysCtlPWMClockSet(SYSCTL_PWMDIV_2);
  66. SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
  67. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  68. GPIOPinConfigure(GPIO_PF2_M1PWM6);
  69. GPIOPinConfigure(GPIO_PF3_M1PWM7);
  70. GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3);
  71. }
  72. #endif /* RT_USING_PWM */
  73. #ifdef RT_USING_SPI
  74. void spi_hw_config(void)
  75. {
  76. /* SPI0 */
  77. SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
  78. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  79. GPIOPinConfigure(GPIO_PA2_SSI0CLK);
  80. GPIOPinConfigure(GPIO_PA4_SSI0RX);
  81. GPIOPinConfigure(GPIO_PA5_SSI0TX);
  82. GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_2);
  83. }
  84. #endif /* RT_USING_SPI */
  85. #ifdef RT_USING_I2C
  86. void i2c_hw_config(void)
  87. {
  88. /* I2C0 */
  89. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
  90. ROM_GPIOPinConfigure(GPIO_PB2_I2C0SCL);
  91. ROM_GPIOPinConfigure(GPIO_PB3_I2C0SDA);
  92. ROM_GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
  93. ROM_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
  94. ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_I2C0);
  95. ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0);
  96. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
  97. while (!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C0));
  98. // timeout:5ms
  99. ROM_I2CMasterTimeoutSet(I2C0_BASE, 0x7d);
  100. }
  101. #endif /* RT_USING_I2C */
  102. /************************** end of file ******************/