mbed_sdk_boot.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* mbed Microcontroller Library
  2. * Copyright (c) 2017 ARM Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "mbed_toolchain.h"
  17. #include <stdlib.h>
  18. #include <stdint.h>
  19. #include "cmsis.h"
  20. /* This startup is for mbed 2 baremetal. There is no config for RTOS for mbed 2,
  21. * therefore we protect this file with MBED_CONF_RTOS_PRESENT
  22. * Note: The new consolidated started for mbed OS is in rtos/mbed_boot code file.
  23. */
  24. #if !defined(MBED_CONF_RTOS_PRESENT)
  25. /* mbed_main is a function that is called before main()
  26. * mbed_sdk_init() is also a function that is called before main(), but unlike
  27. * mbed_main(), it is not meant for user code, but for the SDK itself to perform
  28. * initializations before main() is called.
  29. */
  30. MBED_WEAK void mbed_main(void)
  31. {
  32. }
  33. /* This function can be implemented by the target to perform higher level target initialization
  34. */
  35. MBED_WEAK void mbed_sdk_init(void)
  36. {
  37. }
  38. MBED_WEAK void software_init_hook_rtos()
  39. {
  40. // Nothing by default
  41. }
  42. void mbed_copy_nvic(void)
  43. {
  44. /* If vector address in RAM is defined, copy and switch to dynamic vectors. Exceptions for M0 which doesn't have
  45. VTOR register and for A9 for which CMSIS doesn't define NVIC_SetVector; in both cases target code is
  46. responsible for correctly handling the vectors.
  47. */
  48. #if !defined(__CORTEX_M0) && !defined(__CORTEX_A9)
  49. #ifdef NVIC_RAM_VECTOR_ADDRESS
  50. uint32_t *old_vectors = (uint32_t *)SCB->VTOR;
  51. uint32_t *vectors = (uint32_t *)NVIC_RAM_VECTOR_ADDRESS;
  52. for (int i = 0; i < NVIC_NUM_VECTORS; i++) {
  53. vectors[i] = old_vectors[i];
  54. }
  55. SCB->VTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS;
  56. #endif /* NVIC_RAM_VECTOR_ADDRESS */
  57. #endif /* !defined(__CORTEX_M0) && !defined(__CORTEX_A9) */
  58. }
  59. /* Toolchain specific main code */
  60. #if defined (__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 5010060))
  61. int $Super$$main(void);
  62. int $Sub$$main(void)
  63. {
  64. mbed_main();
  65. return $Super$$main();
  66. }
  67. void _platform_post_stackheap_init(void)
  68. {
  69. mbed_copy_nvic();
  70. mbed_sdk_init();
  71. }
  72. #elif defined (__GNUC__)
  73. extern int __real_main(void);
  74. void software_init_hook(void)
  75. {
  76. mbed_copy_nvic();
  77. mbed_sdk_init();
  78. software_init_hook_rtos();
  79. }
  80. int __wrap_main(void)
  81. {
  82. mbed_main();
  83. return __real_main();
  84. }
  85. #elif defined (__ICCARM__)
  86. int __low_level_init(void)
  87. {
  88. mbed_copy_nvic();
  89. return 1;
  90. }
  91. #endif
  92. #endif