board.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <stdint.h>
  35. #include "fsl_common.h"
  36. #include "clock_config.h"
  37. #include "board.h"
  38. #include "fsl_debug_console.h"
  39. #ifdef SDK_PRIMARY_CORE
  40. /* Address of RAM, where the image for core1 should be copied */
  41. #define CORE1_BOOT_ADDRESS (void *)0x20010000
  42. #if defined(__CC_ARM)
  43. extern uint32_t Image$$CORE1_REGION$$Base;
  44. extern uint32_t Image$$CORE1_REGION$$Length;
  45. #define CORE1_IMAGE_START &Image$$CORE1_REGION$$Base
  46. #elif defined(__ICCARM__)
  47. extern unsigned char core1_image_start[];
  48. #define CORE1_IMAGE_START core1_image_start
  49. #endif
  50. #endif
  51. /*******************************************************************************
  52. * Variables
  53. ******************************************************************************/
  54. /* Clock rate on the CLKIN pin */
  55. const uint32_t ExtClockIn = BOARD_EXTCLKINRATE;
  56. /*******************************************************************************
  57. * Code
  58. ******************************************************************************/
  59. /* Initialize debug console. */
  60. status_t BOARD_InitDebugConsole(void)
  61. {
  62. status_t result;
  63. /* attach 12 MHz clock to FLEXCOMM0 (debug console) */
  64. CLOCK_AttachClk(kFRO12M_to_FLEXCOMM0);
  65. RESET_PeripheralReset(BOARD_DEBUG_UART_RST);
  66. result = DbgConsole_Init(BOARD_DEBUG_UART_BASEADDR, BOARD_DEBUG_UART_BAUDRATE, DEBUG_CONSOLE_DEVICE_TYPE_FLEXCOMM,
  67. BOARD_DEBUG_UART_CLK_FREQ);
  68. assert(kStatus_Success == result);
  69. return result;
  70. }
  71. #ifdef SDK_PRIMARY_CORE
  72. /* Start the secondary core. */
  73. void BOARD_StartSecondaryCore(void)
  74. {
  75. /* Calculate size of the secondary core image - not required on MCUXpresso. MCUXpresso copies the image to RAM during
  76. * startup
  77. * automatically */
  78. #if (defined(__CC_ARM) || defined(__ICCARM__))
  79. #if defined(__CC_ARM)
  80. uint32_t core1_image_size = (uint32_t)&Image$$CORE1_REGION$$Length;
  81. #elif defined(__ICCARM__)
  82. #pragma section = "__sec_core"
  83. uint32_t core1_image_size = (uint32_t)__section_end("__sec_core") - (uint32_t)&core1_image_start;
  84. #endif
  85. /* Copy core1 application from FLASH to RAM. Primary core code is executed from FLASH, Secondary from RAM
  86. * for maximal effectivity.*/
  87. memcpy(CORE1_BOOT_ADDRESS, (void *)CORE1_IMAGE_START, core1_image_size);
  88. #endif
  89. /* Boot source for Core 1 from RAM */
  90. SYSCON->CPBOOT = SYSCON_CPBOOT_BOOTADDR(*(uint32_t *)((uint8_t *)CORE1_BOOT_ADDRESS + 0x4));
  91. SYSCON->CPSTACK = SYSCON_CPSTACK_STACKADDR(*(uint32_t *)CORE1_BOOT_ADDRESS);
  92. uint32_t temp = SYSCON->CPUCTRL;
  93. temp |= 0xc0c48000U;
  94. SYSCON->CPUCTRL = temp | SYSCON_CPUCTRL_CM0RSTEN_MASK | SYSCON_CPUCTRL_CM0CLKEN_MASK;
  95. SYSCON->CPUCTRL = (temp | SYSCON_CPUCTRL_CM0CLKEN_MASK) & (~SYSCON_CPUCTRL_CM0RSTEN_MASK);
  96. }
  97. #endif