GlobLib
HAL and API libraries for MCUs and hardware.
stm32f103cb_debug.c
Go to the documentation of this file.
1 /*!**************************************************************************
2  @file stm32f103cb_debug.c
3  @brief Source file for stm32f103cb DEBUG
4  @author Stuart Ianna
5  @version 0.1
6  @date May 2018
7  @copyright GNU GPLv3
8  @warning None
9  @bug
10 
11  @details
12 
13 
14  @par Compilers
15  - arm-none-eabi-gcc (15:4.9.3+svn231177-1) 4.9.3 20150529 (prerelease)
16 ******************************************************************************/
17 
18 #include "stm32f103cb_debug.h"
19 
20 //Debug function pointer, this should automatically be assigned to NULL, as it is file-static
21 static void (*debug_out)(uint8_t byte);
22 
23 static const struct error_desc{
24 
25  uint8_t code;
26  char *message;
27 }errordesc[] = {
28 
29  { E_MCU_UNDEFINED, "Error MCU: Unknown error code\n\r" },
30 
31  { E_GPIO_NOERROR, "Error GPIO: No Error\n\r" },
32  { E_GPIO_PORT, "Error GPIO: Port doesn't exist\n\r" },
33  { E_GPIO_PIN, "Error GPIO: Pin doesnt' exist\n\r" },
34  { E_GPIO_ISR, "Error GPIO: ISR EXTI line in use\n\r" },
35  { E_GPIO_TRIGGER, "Error GPIO: ISR trigger doesn't exist\n\r" },
36 
37  { E_USART_NOERROR, "Error USART: No Error\n\r" },
38  { E_USART_NOPORT, "Error USART: Port doesn't exist\n\r" },
39  { E_USART_NOBAUD, "Error USART: Baud rate not available\n\r" },
40  { E_USART_NOSTOP, "Error USART: Stop bits don't exist\n\r" },
41  { E_USART_NODATA, "Error USART: Data frame not available\n\r" },
42  { E_USART_NOPARITY, "Error USART: Parity option not available\n\r" },
43  { E_USART_NOINT, "Error USART: Interrupt option doesn't exist\n\r" },
44 
45  { E_I2C_NOERROR, "Error I2C: No error\n\r" },
46  { E_I2C_PORT, "Error I2C: Port doesn't exist\n\r" },
47  { E_I2C_WRITE, "Error I2C: Write transmission timeout\n\r" },
48  { E_I2C_READ, "Error I2C: Read transmission timeout\n\r" },
49  { E_I2C_START, "Error I2C: Start transmission timeout\n\r" },
50  { E_I2C_STOP, "Error I2C: Stop transmission timeout\n\r" },
51 
52  { E_CLOCK_NOERROR, "Error CLOCK: No error\n\r" },
53  { E_CLOCK_NOSPEED, "Error CLOCK: Clock speed doesn't exist\n\r" },
54 
55  { E_SYSTICK_NOERROR, "Error SYSTICK: No error\n\r" },
56  { E_SYSTICK_TOOLONG, "Error SYSTICK: Timeour value is too long\n\r" },
57 
58  { E_TIMER_NOERROR, "Error TIMER: No error\n\r" },
59  { E_TIMER_NOTIMER, "Error TIMER: Timer doesn't exist\n\r" },
60  { E_TIMER_NOCHANNEL, "Error TIMER: Channel doesn't exist\n\r" },
61  { E_TIMER_PERIOD, "Error TIMER: Period long/frequency high\n\r" },
62  { E_TIMER_PULSE, "Error TIMER: Pulse too long\n\r" },
63 
64  { E_ADC_NOERROR, "Error ADC: No error\n\r" },
65  { E_ADC_PORT, "Error ADC: Port doesn't exist with ADC\n\r" },
66  { E_ADC_PIN, "Error ADC: No ADC on pin\n\r" },
67 
68  { E_IWDG_NOERROR, "Error IWDG: No error\n\r" },
69  { E_IWDG_PERIOD, "Error IWDG: Period too long\n\r" },
70 
71  { E_FLASH_NOERROR, "Error FLASH: No error\n\r" },
72  { E_FLASH_PAGE, "Error FLASH: Page number out of bounds\n\r" },
73 
74  { E_RTC_NOERROR, "Error RTC: No Error \n\r" },
75  { E_RTC_PRELOAD, "Error RTC: Invalid preload value \n\r" },
76 
77  { E_SPI_NOERROR, "Error SPI: No Error \n\r" },
78  { E_SPI_PORT, "Error SPI: Port doesn't exist \n\r" }
79 };
80 
81 
82 void MCU_debugEnable(void (*output_handle)(uint8_t)){
83 
84  //Set that static function pointer to the output function, so error messages have a place to go
85  debug_out = output_handle;
86 }
87 
88 void MCU_debugDisable(void){
89 
90  //Set the function pointer to null, so no errors can be outputted
91  //This also means error enable can be tested using the NULL value
92  debug_out = NULL;
93 }
94 uint8_t MCU_debugIsEnabled(void){
95 
96  if(debug_out == NULL){
97 
98  return 0;
99 
100  }
101 
102  return 1;
103 }
104 //Print the error character by character to the error_out function pointer
105 void MCU_printError(mcu_error errorNum){
106 
107  if(debug_out == NULL){
108 
109  return;
110  }
111 
112  uint8_t index;
113  uint8_t pos = 0;
114 
115  //Find the position of the error code in errodesc
116  for(index = 0; index < (sizeof(errordesc) / sizeof(errordesc[0])); index++){
117 
118  if(errorNum == errordesc[index].code){
119 
120  break;
121  }
122  }
123 
124  //Set index to default if unknown error if can't be found
125  if(index == (sizeof(errordesc) / sizeof(errordesc[0]))){
126 
127  index = 0;
128  }
129 
130  //Print the error using the message value
131  while(errordesc[index].message[pos] != '\0'){
132 
133  debug_out(errordesc[index].message[pos]);
134  pos++;
135  }
136 }
137 
Error timer: Pulse too long.
Header file for stm32f103cb DEBUG.
void MCU_debugEnable(void(*output_handle)(uint8_t))
Enables the debug feature.
Error clock: No error.
Error timer: Timer doesn&#39;t exist.
Error clock: Clock speed doesn&#39;t exist.
ERROR GPIO: Port doesn&#39;t exist.
ERROR I2C: Port doesn&#39;t exist.
Error IWDG: Period too long.
void MCU_printError(mcu_error errorNum)
Print a given error number as a character stream.
Error SPI: No error.
ERROR I2C: No Error.
uint8_t MCU_debugIsEnabled(void)
Checks if debug is enabled.
Error FLASH: Page number out of bounds.
Error RTC: Invalid period specified.
ERROR GPIO: Pin doesn&#39;t exist.
Error RTC: No error.
Error USART: Baud rate not available.
ERROR GPIO: ISR EXTI line in use.
Error FLASH: No error.
ERROR I2C: Timeout during get()
Error SPI: Port doesn&#39;t exist.
ERROR I2C: Timeout during stop()
Error USART: Port doesn&#39;t exist.
Error ADC: Port doesn&#39;t exist with ADC.
ERROR I2C: Timeout during start()
ERROR I2C: Timeout during put()
Error USART: Parity option not available.
Error ADC: No ADC on pin.
Error ADC: No error.
ERROR MCU: Unknown error code.
ERROR GPIO: ISR trigger doesn&#39;t exist.
Error systick: No error.
Error USART: Interrupt option doesn&#39;t exist.
Error timer: Period too long / frequency too high.
Error systick: Timeout value is too short.
void MCU_debugDisable(void)
Disables the debug feature.
ERROR GPIO: No Error.
Error USART: Stop bits don&#39;t exist.
Error timer: No error.
Error timer: Channel doesn&#39;t exist.
Error IWDG: No error.
Error USART: Data frame not available.
Error USART: No Error.
mcu_error
Error enumerators for the Debug peripheral.