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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /**********************************************************************
  2. * $Id$ debug_frmwrk.c 2010-05-21
  3. *
  4. * @file debug_frmwrk.c
  5. * @brief Contains some utilities that used for debugging through UART
  6. * @version 2.0
  7. * @date 21. May. 2010
  8. * @author NXP MCU SW Application Team
  9. *
  10. * Copyright(C) 2010, NXP Semiconductor
  11. * All rights reserved.
  12. *
  13. ***********************************************************************
  14. * Software that is described herein is for illustrative purposes only
  15. * which provides customers with programming information regarding the
  16. * products. This software is supplied "AS IS" without any warranties.
  17. * NXP Semiconductors assumes no responsibility or liability for the
  18. * use of the software, conveys no license or title under any patent,
  19. * copyright, or mask work right to the product. NXP Semiconductors
  20. * reserves the right to make changes in the software without
  21. * notification. NXP Semiconductors also make no representation or
  22. * warranty that such application will be suitable for the specified
  23. * use without further testing or modification.
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors'
  26. * relevant copyright in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. **********************************************************************/
  31. #include "debug_frmwrk.h"
  32. #include "lpc17xx_pinsel.h"
  33. /* If this source file built with example, the LPC17xx FW library configuration
  34. * file in each example directory ("lpc17xx_libcfg.h") must be included,
  35. * otherwise the default FW library configuration file must be included instead
  36. */
  37. #ifdef __BUILD_WITH_EXAMPLE__
  38. #include "lpc17xx_libcfg.h"
  39. #else
  40. #include "lpc17xx_libcfg_default.h"
  41. #endif
  42. #ifdef _DBGFWK
  43. /* Debug framework */
  44. static Bool debug_frmwrk_initialized = FALSE;
  45. void (*_db_msg)(LPC_UART_TypeDef *UARTx, const void *s) = UARTPuts;
  46. void (*_db_msg_)(LPC_UART_TypeDef *UARTx, const void *s) = UARTPuts_;
  47. void (*_db_char)(LPC_UART_TypeDef *UARTx, uint8_t ch) = UARTPutChar;
  48. void (*_db_dec)(LPC_UART_TypeDef *UARTx, uint8_t decn) = UARTPutHex;
  49. void (*_db_dec_16)(LPC_UART_TypeDef *UARTx, uint16_t decn) = UARTPutHex16;
  50. void (*_db_dec_32)(LPC_UART_TypeDef *UARTx, uint32_t decn) = UARTPutHex32;
  51. void (*_db_hex)(LPC_UART_TypeDef *UARTx, uint8_t hexn) = UARTPutDec;
  52. void (*_db_hex_16)(LPC_UART_TypeDef *UARTx, uint16_t hexn) = UARTPutDec16;
  53. void (*_db_hex_32)(LPC_UART_TypeDef *UARTx, uint32_t hexn) = UARTPutDec32;
  54. uint8_t (*_db_get_char)(LPC_UART_TypeDef *UARTx) = UARTGetChar;
  55. /*********************************************************************//**
  56. * @brief Puts a character to UART port
  57. * @param[in] UARTx Pointer to UART peripheral
  58. * @param[in] ch Character to put
  59. * @return None
  60. **********************************************************************/
  61. void UARTPutChar(LPC_UART_TypeDef *UARTx, uint8_t ch) {
  62. if (debug_frmwrk_initialized)
  63. UART_Send(UARTx, &ch, 1, BLOCKING);
  64. }
  65. /*********************************************************************//**
  66. * @brief Get a character to UART port
  67. * @param[in] UARTx Pointer to UART peripheral
  68. * @return character value that returned
  69. **********************************************************************/
  70. uint8_t UARTGetChar(LPC_UART_TypeDef *UARTx) {
  71. uint8_t tmp = 0;
  72. if (debug_frmwrk_initialized)
  73. UART_Receive(UARTx, &tmp, 1, BLOCKING);
  74. return(tmp);
  75. }
  76. /*********************************************************************//**
  77. * @brief Puts a string to UART port
  78. * @param[in] UARTx Pointer to UART peripheral
  79. * @param[in] str string to put
  80. * @return None
  81. **********************************************************************/
  82. void UARTPuts(LPC_UART_TypeDef *UARTx, const void *str) {
  83. if (!debug_frmwrk_initialized) return;
  84. uint8_t *s = (uint8_t*)str;
  85. while (*s) UARTPutChar(UARTx, *s++);
  86. }
  87. /*********************************************************************//**
  88. * @brief Puts a string to UART port and print new line
  89. * @param[in] UARTx Pointer to UART peripheral
  90. * @param[in] str String to put
  91. * @return None
  92. **********************************************************************/
  93. void UARTPuts_(LPC_UART_TypeDef *UARTx, const void *str) {
  94. if (!debug_frmwrk_initialized) return;
  95. UARTPuts (UARTx, str);
  96. UARTPuts (UARTx, "\n\r");
  97. }
  98. /*********************************************************************//**
  99. * @brief Puts a decimal number to UART port
  100. * @param[in] UARTx Pointer to UART peripheral
  101. * @param[in] decnum Decimal number (8-bit long)
  102. * @return None
  103. **********************************************************************/
  104. void UARTPutDec(LPC_UART_TypeDef *UARTx, uint8_t decnum) {
  105. if (!debug_frmwrk_initialized) return;
  106. uint8_t c1 = decnum%10;
  107. uint8_t c2 = (decnum / 10) % 10;
  108. uint8_t c3 = (decnum / 100) % 10;
  109. UARTPutChar(UARTx, '0'+c3);
  110. UARTPutChar(UARTx, '0'+c2);
  111. UARTPutChar(UARTx, '0'+c1);
  112. }
  113. /*********************************************************************//**
  114. * @brief Puts a decimal number to UART port
  115. * @param[in] UARTx Pointer to UART peripheral
  116. * @param[in] decnum Decimal number (8-bit long)
  117. * @return None
  118. **********************************************************************/
  119. void UARTPutDec16(LPC_UART_TypeDef *UARTx, uint16_t decnum) {
  120. if (!debug_frmwrk_initialized) return;
  121. uint8_t c1 = decnum%10;
  122. uint8_t c2 = (decnum / 10) % 10;
  123. uint8_t c3 = (decnum / 100) % 10;
  124. uint8_t c4 = (decnum / 1000) % 10;
  125. uint8_t c5 = (decnum / 10000) % 10;
  126. UARTPutChar(UARTx, '0'+c5);
  127. UARTPutChar(UARTx, '0'+c4);
  128. UARTPutChar(UARTx, '0'+c3);
  129. UARTPutChar(UARTx, '0'+c2);
  130. UARTPutChar(UARTx, '0'+c1);
  131. }
  132. /*********************************************************************//**
  133. * @brief Puts a decimal number to UART port
  134. * @param[in] UARTx Pointer to UART peripheral
  135. * @param[in] decnum Decimal number (8-bit long)
  136. * @return None
  137. **********************************************************************/
  138. void UARTPutDec32(LPC_UART_TypeDef *UARTx, uint32_t decnum) {
  139. if (!debug_frmwrk_initialized) return;
  140. const uint8_t c1 = decnum % 10,
  141. c2 = (decnum / 10) % 10,
  142. c3 = (decnum / 100) % 10,
  143. c4 = (decnum / 1000) % 10,
  144. c5 = (decnum / 10000) % 10,
  145. c6 = (decnum / 100000) % 10,
  146. c7 = (decnum / 1000000) % 10,
  147. c8 = (decnum / 10000000) % 10,
  148. c9 = (decnum / 100000000) % 10,
  149. c10 = (decnum / 1000000000) % 10;
  150. UARTPutChar(UARTx, '0' + c10);
  151. UARTPutChar(UARTx, '0' + c9);
  152. UARTPutChar(UARTx, '0' + c8);
  153. UARTPutChar(UARTx, '0' + c7);
  154. UARTPutChar(UARTx, '0' + c6);
  155. UARTPutChar(UARTx, '0' + c5);
  156. UARTPutChar(UARTx, '0' + c4);
  157. UARTPutChar(UARTx, '0' + c3);
  158. UARTPutChar(UARTx, '0' + c2);
  159. UARTPutChar(UARTx, '0' + c1);
  160. }
  161. /*********************************************************************//**
  162. * @brief Puts a hex number to UART port
  163. * @param[in] UARTx Pointer to UART peripheral
  164. * @param[in] hexnum Hex number (8-bit long)
  165. * @return None
  166. **********************************************************************/
  167. void UARTPutHex(LPC_UART_TypeDef *UARTx, uint8_t hexnum) {
  168. if (!debug_frmwrk_initialized) return;
  169. UARTPuts(UARTx, "0x");
  170. uint8_t nibble, i = 1;
  171. do {
  172. nibble = (hexnum >> (4 * i)) & 0x0F;
  173. UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
  174. } while (i--);
  175. }
  176. /*********************************************************************//**
  177. * @brief Puts a hex number to UART port
  178. * @param[in] UARTx Pointer to UART peripheral
  179. * @param[in] hexnum Hex number (16-bit long)
  180. * @return None
  181. **********************************************************************/
  182. void UARTPutHex16(LPC_UART_TypeDef *UARTx, uint16_t hexnum) {
  183. if (!debug_frmwrk_initialized) return;
  184. UARTPuts(UARTx, "0x");
  185. uint8_t nibble, i = 3;
  186. do {
  187. nibble = (hexnum >> (4 * i)) & 0x0F;
  188. UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
  189. } while (i--);
  190. }
  191. /*********************************************************************//**
  192. * @brief Puts a hex number to UART port
  193. * @param[in] UARTx Pointer to UART peripheral
  194. * @param[in] hexnum Hex number (32-bit long)
  195. * @return None
  196. **********************************************************************/
  197. void UARTPutHex32(LPC_UART_TypeDef *UARTx, uint32_t hexnum) {
  198. if (!debug_frmwrk_initialized) return;
  199. UARTPuts(UARTx, "0x");
  200. uint8_t nibble, i = 7;
  201. do {
  202. nibble = (hexnum >> (4 * i)) & 0x0F;
  203. UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
  204. } while (i--);
  205. }
  206. /*********************************************************************//**
  207. * @brief print function that supports format as same as printf()
  208. * function of <stdio.h> library
  209. * @param[in] None
  210. * @return None
  211. **********************************************************************/
  212. //void _printf (const char *format, ...) {
  213. // static char buffer[512 + 1];
  214. // va_list vArgs;
  215. // char *tmp;
  216. // va_start(vArgs, format);
  217. // vsprintf((char *)buffer, (char const *)format, vArgs);
  218. // va_end(vArgs);
  219. //
  220. // _DBG(buffer);
  221. //}
  222. /*********************************************************************//**
  223. * @brief Initialize Debug frame work through initializing UART port
  224. * @param[in] None
  225. * @return None
  226. **********************************************************************/
  227. void debug_frmwrk_init(void) {
  228. UART_CFG_Type UARTConfigStruct;
  229. PINSEL_CFG_Type PinCfg;
  230. #if (USED_UART_DEBUG_PORT==0)
  231. /*
  232. * Initialize UART0 pin connect
  233. */
  234. PinCfg.Funcnum = 1;
  235. PinCfg.OpenDrain = 0;
  236. PinCfg.Pinmode = 0;
  237. PinCfg.Pinnum = 2;
  238. PinCfg.Portnum = 0;
  239. PINSEL_ConfigPin(&PinCfg);
  240. PinCfg.Pinnum = 3;
  241. PINSEL_ConfigPin(&PinCfg);
  242. #elif (USED_UART_DEBUG_PORT==1)
  243. /*
  244. * Initialize UART1 pin connect
  245. */
  246. PinCfg.Funcnum = 1;
  247. PinCfg.OpenDrain = 0;
  248. PinCfg.Pinmode = 0;
  249. PinCfg.Pinnum = 15;
  250. PinCfg.Portnum = 0;
  251. PINSEL_ConfigPin(&PinCfg);
  252. PinCfg.Pinnum = 16;
  253. PINSEL_ConfigPin(&PinCfg);
  254. #endif
  255. /* Initialize UART Configuration parameter structure to default state:
  256. * Baudrate = 9600bps
  257. * 8 data bit
  258. * 1 Stop bit
  259. * None parity
  260. */
  261. UART_ConfigStructInit(&UARTConfigStruct);
  262. // Re-configure baudrate to 115200bps
  263. UARTConfigStruct.Baud_rate = 115200;
  264. // Initialize DEBUG_UART_PORT peripheral with given to corresponding parameter
  265. UART_Init((LPC_UART_TypeDef *)DEBUG_UART_PORT, &UARTConfigStruct);
  266. // Enable UART Transmit
  267. UART_TxCmd((LPC_UART_TypeDef *)DEBUG_UART_PORT, ENABLE);
  268. debug_frmwrk_initialized = TRUE;
  269. }
  270. #endif // _DBGFWK