board_init.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
  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. /******************************************************************************
  17. * @file board_init.c
  18. * @brief CSI Source File for board init
  19. * @version V1.0
  20. * @date 02. June 2017
  21. ******************************************************************************/
  22. #include <stdio.h>
  23. #include <stdint.h>
  24. #include <csi_config.h>
  25. #include <csi_core.h>
  26. #include "wm_regs.h"
  27. #define UART_TXEN_BIT (0x40)
  28. #define UART_RXEN_BIT (0x80)
  29. #define UART_PARITYEN_BIT (0x08)
  30. #define UART_PARITYODD_BIT (0x10)
  31. #define UART_BITSTOP_VAL (0x03) /// 1 stop-bit; no crc; 8 data-bits
  32. extern void set_printf_port(unsigned char port);
  33. static void uart0Init (int bandrate)
  34. {
  35. unsigned int bd;
  36. NVIC_DisableIRQ(UART0_IRQn);
  37. NVIC_ClearPendingIRQ(UART0_IRQn);
  38. bd = (APB_CLK/(16*bandrate) - 1)|(((APB_CLK%(bandrate*16))*16/(bandrate*16))<<16);
  39. tls_reg_write32(HR_UART0_BAUD_RATE_CTRL, bd);
  40. tls_reg_write32(HR_UART0_LINE_CTRL, UART_BITSTOP_VAL | UART_TXEN_BIT | UART_RXEN_BIT);
  41. tls_reg_write32(HR_UART0_FLOW_CTRL, 0x00); /* Disable afc */
  42. tls_reg_write32(HR_UART0_DMA_CTRL, 0x00); /* Disable DMA */
  43. tls_reg_write32(HR_UART0_FIFO_CTRL, 0x00); /* one byte TX/RX */
  44. // tls_reg_write32(HR_UART0_INT_MASK, 0x00); /* Disable INT */
  45. }
  46. #include "luat_conf_bsp.h"
  47. #ifdef LUAT_CONF_LOG_UART1
  48. static void uart1_io_init(void)
  49. {
  50. uint32_t temp;
  51. /* PB6.7 AF Close */
  52. temp = tls_reg_read32(HR_GPIOB_AFSEL);
  53. temp &= ~0xC0;
  54. tls_reg_write32(HR_GPIOB_AFSEL, temp);
  55. /* PB6.7 AF Open opt1 */
  56. temp = tls_reg_read32(HR_GPIOB_AFSEL);
  57. temp |= 0xC0;
  58. tls_reg_write32(HR_GPIOB_AFSEL, temp);
  59. temp = tls_reg_read32(HR_GPIOB_AFS0);
  60. temp &= ~0xC0;
  61. tls_reg_write32(HR_GPIOB_AFS0, temp);
  62. temp = tls_reg_read32(HR_GPIOB_AFS1);
  63. temp &= ~0xC0;
  64. tls_reg_write32(HR_GPIOB_AFS1, temp);
  65. }
  66. static void uart1Init (int bandrate)
  67. {
  68. unsigned int bd;
  69. NVIC_DisableIRQ(UART1_IRQn);
  70. NVIC_ClearPendingIRQ(UART1_IRQn);
  71. bd = (APB_CLK/(16*bandrate) - 1)|(((APB_CLK%(bandrate*16))*16/(bandrate*16))<<16);
  72. tls_reg_write32(HR_UART1_BAUD_RATE_CTRL, bd);
  73. tls_reg_write32(HR_UART1_LINE_CTRL, UART_BITSTOP_VAL | UART_TXEN_BIT | UART_RXEN_BIT);
  74. tls_reg_write32(HR_UART1_FLOW_CTRL, 0x00); /* Disable afc */
  75. tls_reg_write32(HR_UART1_DMA_CTRL, 0x00); /* Disable DMA */
  76. tls_reg_write32(HR_UART1_FIFO_CTRL, 0x00); /* one byte TX/RX */
  77. tls_reg_write32(HR_UART1_INT_MASK, 0x00); /* Disable INT */
  78. }
  79. #endif
  80. void board_init(void)
  81. {
  82. #ifndef LUAT_CONF_LOG_UART1
  83. /* use uart0 as log output io */
  84. uart0Init(2000000);
  85. #else
  86. // uart1_io_init();
  87. /* use uart1 as log output io */
  88. // uart1Init(2000000);
  89. set_printf_port(0xff);
  90. #endif
  91. }