My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

start_c.c 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /******************************************************************************
  2. * The MIT License
  3. *
  4. * Copyright (c) 2011 LeafLabs, LLC.
  5. *
  6. * Permission is hereby granted, free of charge, to any person
  7. * obtaining a copy of this software and associated documentation
  8. * files (the "Software"), to deal in the Software without
  9. * restriction, including without limitation the rights to use, copy,
  10. * modify, merge, publish, distribute, sublicense, and/or sell copies
  11. * of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  21. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  22. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  23. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. * SOFTWARE.
  25. *****************************************************************************/
  26. /*
  27. * This file is a modified version of a file obtained from
  28. * CodeSourcery Inc. (now part of Mentor Graphics Corp.), in which the
  29. * following text appeared:
  30. *
  31. * Copyright (c) 2006, 2007 CodeSourcery Inc
  32. *
  33. * The authors hereby grant permission to use, copy, modify, distribute,
  34. * and license this software and its documentation for any purpose, provided
  35. * that existing copyright notices are retained in all copies and that this
  36. * notice is included verbatim in any distributions. No written agreement,
  37. * license, or royalty fee is required for any of the authorized uses.
  38. * Modifications to this software may be copyrighted by their authors
  39. * and need not follow the licensing terms described here, provided that
  40. * the new terms are clearly indicated on the first page of each file where
  41. * they apply.
  42. */
  43. #include <stddef.h>
  44. #include <libmaple/rcc.h>
  45. #include <libmaple/libmaple.h>
  46. #include <libmaple/bitband.h>
  47. #include "rcc_private.h"
  48. #include <libmaple/usart.h>
  49. #include <libmaple/gpio.h>
  50. #include "usart_private.h"
  51. #include <libmaple/sdio.h>
  52. #include <string.h>
  53. extern void __libc_init_array(void);
  54. extern int main(int, char**, char**);
  55. extern void exit(int) __attribute__((noreturn, weak));
  56. /* The linker must ensure that these are at least 4-byte aligned. */
  57. extern char __data_start__, __data_end__;
  58. extern char __bss_start__, __bss_end__;
  59. struct rom_img_cfg {
  60. int *img_start;
  61. };
  62. extern char _lm_rom_img_cfgp;
  63. extern void __lm_error();
  64. extern void timer_disable_all();
  65. /* Turn off ADC */
  66. extern void adc_disable_all();
  67. /* Turn off all USARTs */
  68. extern void usart_disable_all();
  69. extern void DisableEverything();
  70. void __attribute__((noreturn)) start_c(void) {
  71. struct rom_img_cfg *img_cfg = (struct rom_img_cfg*)&_lm_rom_img_cfgp;
  72. int *src = img_cfg->img_start;
  73. int *dst = (int*)&__data_start__;
  74. int exit_code;
  75. asm("CPSID I");
  76. /* Reset the RCC clock configuration to the default reset state(for debug purpose) */
  77. /* Set HSION bit */
  78. RCC_BASE->CR |= 0x00000001U;
  79. /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
  80. RCC_BASE->CFGR &= 0xF0FF0000U;
  81. /* Reset HSEON, CSSON and PLLON bits */
  82. RCC_BASE->CR &= 0xFEF6FFFFU;
  83. /* Reset HSEBYP bit */
  84. RCC_BASE->CR &= 0xFFFBFFFFU;
  85. /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */
  86. RCC_BASE->CFGR &= 0xFF80FFFFU;
  87. /* Disable all interrupts and clear pending bits */
  88. RCC_BASE->CIR = 0x009F0000U;
  89. USART1_BASE->CR1 = 0;
  90. USART1_BASE->CR2 = 0;
  91. USART1_BASE->CR3 = 0;
  92. memset(SDIO_BASE, 0, sizeof(sdio_reg_map));
  93. asm("CPSIE I");
  94. /* Initialize .data, if necessary. */
  95. if (src != dst) {
  96. int *end = (int*)&__data_end__;
  97. while (dst < end) {
  98. *dst++ = *src++;
  99. }
  100. }
  101. /* Zero .bss. */
  102. dst = (int*)&__bss_start__;
  103. while (dst < (int*)&__bss_end__) {
  104. *dst++ = 0;
  105. }
  106. /* Run initializers. */
  107. __libc_init_array();
  108. /* Jump to main. */
  109. exit_code = main(0, 0, 0);
  110. if (exit) {
  111. exit(exit_code);
  112. }
  113. /* If exit is NULL, make sure we don't return. */
  114. for (;;)
  115. continue;
  116. }