rt_low_level_init.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * File : rt_low_level_init.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2018-02-08 RT-Thread the first version
  23. */
  24. void rt_low_level_init(void)
  25. {
  26. volatile unsigned int *addr;
  27. volatile unsigned int time;
  28. int i;
  29. //change cpu clk source to 24M
  30. addr = (unsigned int *)(0x01c20000 + 0x050);
  31. *addr = 0x10000;
  32. //init cpu pll clk 408M
  33. addr = (unsigned int *)(0x01c20000 + 0x000);
  34. *addr = 0x80001000;
  35. time = 0xffff;
  36. while ((!(*addr & (0x1 << 28))) && (time--));
  37. //change cpu clk source to pll
  38. if (time > 0)
  39. {
  40. addr = (unsigned int *)(0x01c20000 + 0x050);
  41. *addr = 0x20000;
  42. }
  43. //init periph pll clk:600M
  44. //init ahb pll clk:200M
  45. //init apb pll clk:100M
  46. addr = (unsigned int *)(0x01c20000 + 0x028);
  47. if (*addr & (0x1 << 31))
  48. return;
  49. addr = (unsigned int *)(0x01c20000 + 0x200);
  50. *addr = 0x1ff;
  51. addr = (unsigned int *)(0x01c20000 + 0x204);
  52. *addr = 0x1ff;
  53. addr = (unsigned int *)(0x01c20000 + 0x028);
  54. *addr |= (0x1 << 31);
  55. while (!(*addr & (0x1 << 28)));
  56. addr = (unsigned int *)(0x01c20000 + 0x054);
  57. *addr = (0x0 << 16) | (0x3 << 12) | (0x0 << 8) | (0x2 << 6) | (0x0 << 4);
  58. //init gpio config
  59. for (i = 0; i < 6; i++)
  60. {
  61. if (i == 1)
  62. continue;// not config gpio B
  63. addr = (unsigned int *)(0x01c20800 + i * 0x24 + 0x00);
  64. *addr = 0x77777777;
  65. addr = (unsigned int *)(0x01c20800 + i * 0x24 + 0x04);
  66. *addr = 0x77777777;
  67. addr = (unsigned int *)(0x01c20800 + i * 0x24 + 0x08);
  68. *addr = 0x77777777;
  69. addr = (unsigned int *)(0x01c20800 + i * 0x24 + 0x0C);
  70. *addr = 0x77777777;
  71. }
  72. }