fpu_init.c 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * @brief FPU init code
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2012
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #if defined(CORE_M4)
  32. #include "sys_config.h"
  33. #include "cmsis.h"
  34. #include "stdint.h"
  35. /*****************************************************************************
  36. * Private types/enumerations/variables
  37. ****************************************************************************/
  38. #define LPC_CPACR 0xE000ED88
  39. #define SCB_MVFR0 0xE000EF40
  40. #define SCB_MVFR0_RESET 0x10110021
  41. #define SCB_MVFR1 0xE000EF44
  42. #define SCB_MVFR1_RESET 0x11000011
  43. /*****************************************************************************
  44. * Public types/enumerations/variables
  45. ****************************************************************************/
  46. /*****************************************************************************
  47. * Private functions
  48. ****************************************************************************/
  49. /*****************************************************************************
  50. * Public functions
  51. ****************************************************************************/
  52. /* Early initialization of the FPU */
  53. void fpuInit(void)
  54. {
  55. #if __FPU_PRESENT != 0
  56. // from arm trm manual:
  57. // ; CPACR is located at address 0xE000ED88
  58. // LDR.W R0, =0xE000ED88
  59. // ; Read CPACR
  60. // LDR R1, [R0]
  61. // ; Set bits 20-23 to enable CP10 and CP11 coprocessors
  62. // ORR R1, R1, #(0xF << 20)
  63. // ; Write back the modified value to the CPACR
  64. // STR R1, [R0]
  65. volatile uint32_t *regCpacr = (uint32_t *) LPC_CPACR;
  66. volatile uint32_t *regMvfr0 = (uint32_t *) SCB_MVFR0;
  67. volatile uint32_t *regMvfr1 = (uint32_t *) SCB_MVFR1;
  68. volatile uint32_t Cpacr;
  69. volatile uint32_t Mvfr0;
  70. volatile uint32_t Mvfr1;
  71. char vfpPresent = 0;
  72. Mvfr0 = *regMvfr0;
  73. Mvfr1 = *regMvfr1;
  74. vfpPresent = ((SCB_MVFR0_RESET == Mvfr0) && (SCB_MVFR1_RESET == Mvfr1));
  75. if (vfpPresent) {
  76. Cpacr = *regCpacr;
  77. Cpacr |= (0xF << 20);
  78. *regCpacr = Cpacr; // enable CP10 and CP11 for full access
  79. }
  80. #endif /* __FPU_PRESENT != 0 */
  81. }
  82. #endif /* defined(CORE_M4 */