My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

boards_setup.cpp 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /******************************************************************************
  2. * The MIT License
  3. *
  4. * Copyright (c) 2012 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. * @file wirish/stm32f1/boards_setup.cpp
  28. * @author Marti Bolivar <mbolivar@leaflabs.com>
  29. * @brief STM32F1 chip setup.
  30. *
  31. * This file controls how init() behaves on the STM32F1. Be very
  32. * careful when changing anything here. Many of these values depend
  33. * upon each other.
  34. */
  35. #include "boards_private.h"
  36. #include <libmaple/gpio.h>
  37. #include <libmaple/timer.h>
  38. #include <boards.h>
  39. #include <usb_serial.h>
  40. // Allow boards to provide a PLL multiplier. This is useful for
  41. // e.g. STM32F100 value line MCUs, which use slower multipliers.
  42. // (We're leaving the default to RCC_PLLMUL_9 for now, since that
  43. // works for F103 performance line MCUs, which is all that LeafLabs
  44. // currently officially supports).
  45. #ifndef BOARD_RCC_PLLMUL
  46. #if !USE_HSI_CLOCK
  47. #if F_CPU==128000000
  48. #define BOARD_RCC_PLLMUL RCC_PLLMUL_16
  49. #elif F_CPU==72000000
  50. #define BOARD_RCC_PLLMUL RCC_PLLMUL_9
  51. #elif F_CPU==48000000
  52. #define BOARD_RCC_PLLMUL RCC_PLLMUL_6
  53. #elif F_CPU==16000000
  54. #define BOARD_RCC_PLLMUL RCC_PLLMUL_2
  55. #endif
  56. #else
  57. #define BOARD_RCC_PLLMUL RCC_PLLMUL_16
  58. #endif
  59. #endif
  60. namespace wirish {
  61. namespace priv {
  62. static stm32f1_rcc_pll_data pll_data = {BOARD_RCC_PLLMUL};
  63. #if !USE_HSI_CLOCK
  64. __weak rcc_pll_cfg w_board_pll_cfg = {RCC_PLLSRC_HSE, &pll_data};
  65. #else
  66. __weak rcc_pll_cfg w_board_pll_cfg = {RCC_PLLSRC_HSI_DIV_2, &pll_data};
  67. #endif
  68. __weak adc_prescaler w_adc_pre = ADC_PRE_PCLK2_DIV_6;
  69. __weak adc_smp_rate w_adc_smp = ADC_SMPR_55_5;
  70. __weak void board_reset_pll(void) {
  71. // TODO
  72. }
  73. __weak void board_setup_clock_prescalers(void) {
  74. rcc_set_prescaler(RCC_PRESCALER_AHB, RCC_AHB_SYSCLK_DIV_1);
  75. rcc_set_prescaler(RCC_PRESCALER_APB1, RCC_APB1_HCLK_DIV_2);
  76. rcc_set_prescaler(RCC_PRESCALER_APB2, RCC_APB2_HCLK_DIV_1);
  77. rcc_clk_disable(RCC_USB);
  78. #if F_CPU == 72000000
  79. rcc_set_prescaler(RCC_PRESCALER_USB, RCC_USB_SYSCLK_DIV_1_5);
  80. #elif F_CPU == 48000000
  81. rcc_set_prescaler(RCC_PRESCALER_USB, RCC_USB_SYSCLK_DIV_1);
  82. #endif
  83. }
  84. __weak void board_setup_gpio(void) {
  85. /**
  86. * PA14 is a pull up pin. But, some V5 boards it start with LOW state! And just behave properly when the Z- PROBE is actived at least once.
  87. * So, if the sensor isnt actived, the PA14 pin will be forever in LOW state, telling Marlin the probe IS ALWAYS ACTIVE, that isnt the case!
  88. * Chitu original firmware seems to start with every pullup PIN with HIGH to workaround this.
  89. * So we are doing the same here.
  90. * This hack only works if applied *before* the GPIO Init, it's the reason I did it here.
  91. */
  92. #ifdef CHITU_V5_Z_MIN_BUGFIX
  93. GPIOA->regs->BSRR = (1U << PA14);
  94. #endif
  95. gpio_init_all();
  96. }
  97. __weak void board_setup_usb(void) {
  98. #ifdef SERIAL_USB
  99. #ifdef GENERIC_BOOTLOADER
  100. // Reset the USB interface on generic boards - developed by Victor PV
  101. gpio_set_mode(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit, GPIO_OUTPUT_PP);
  102. gpio_write_bit(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit,0);
  103. for (volatile unsigned int i = 0; i < 512; i++); // Only small delay seems to be needed, and USB pins will get configured in Serial.begin
  104. gpio_set_mode(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit, GPIO_INPUT_FLOATING);
  105. #endif
  106. Serial.begin(); // Roger Clark. Changed SerialUSB to Serial for Arduino sketch compatibility
  107. #endif
  108. }
  109. __weak void series_init(void) {
  110. // Initialize AFIO here, too, so peripheral remaps and external
  111. // interrupts work out of the box.
  112. afio_init();
  113. }
  114. }
  115. }