Rev 8 | Rev 10 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8 | Rev 9 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | * Created on: 4 Jan 2016 |
4 | * Created on: 4 Jan 2016 |
5 | * Author: Mike |
5 | * Author: Mike |
6 | * |
6 | * |
7 | * This (ab)uses the STMCubeMX HAL declarations to implement a generic STM32F1xx |
7 | * This (ab)uses the STMCubeMX HAL declarations to implement a generic STM32F1xx |
8 | * USART driver layer |
8 | * USART driver layer |
- | 9 | * |
|
- | 10 | * Note - this requires the UART interrupt to be globally enabled in STM32CubeMX, |
|
- | 11 | * but not to generate IRQ handler or HAL driver for the UART. |
|
- | 12 | * |
|
- | 13 | * |
|
9 | */ |
14 | */ |
10 | - | ||
11 | #include "libSerial/serial.h" |
15 | #include "libSerial/serial.h" |
12 | 16 | ||
13 | /* workspaces for the USARTS being used */ |
17 | /* workspaces for the USARTS being used */ |
14 | #if defined SERIAL_UART1 |
18 | #if defined SERIAL_UART1 |
15 | usart_ctl uc1; |
19 | usart_ctl uc1; |
Line 30... | Line 34... | ||
30 | /* returns the number of characters received by the Rx USART */ |
34 | /* returns the number of characters received by the Rx USART */ |
31 | uint16_t |
35 | uint16_t |
32 | SerialCharsReceived(usart_ctl *instance) |
36 | SerialCharsReceived(usart_ctl *instance) |
33 | { |
37 | { |
34 | uint16_t result = 0; // assume no characters received yet |
38 | uint16_t result = 0; // assume no characters received yet |
- | 39 | ||
35 | __HAL_UART_DISABLE_IT(instance->Handle, UART_IT_RXNE); |
40 | __HAL_UART_DISABLE_IT(instance->Handle, UART_IT_RXNE); |
36 | 41 | ||
37 | if (instance->rx_usart_buffer_full) |
42 | if (instance->rx_usart_buffer_full) |
38 | { // buffer is full... |
43 | { // buffer is full... |
39 | result = RX_USART_BUFF_SIZ; |
44 | result = RX_USART_BUFF_SIZ; |
Line 58... | Line 63... | ||
58 | 63 | ||
59 | inline uint8_t |
64 | inline uint8_t |
60 | PollSerial(usart_ctl *instance) |
65 | PollSerial(usart_ctl *instance) |
61 | { |
66 | { |
62 | uint8_t rc; |
67 | uint8_t rc; |
63 | - | ||
64 | __HAL_UART_DISABLE_IT(instance->Handle, UART_IT_RXNE); |
68 | __HAL_UART_DISABLE_IT(instance->Handle, UART_IT_RXNE); |
65 | rc = (instance->rx_usart_buffer_full || (instance->rx_usart_in_Ptr != instance->rx_usart_out_Ptr)); |
69 | rc = (instance->rx_usart_buffer_full || (instance->rx_usart_in_Ptr != instance->rx_usart_out_Ptr)); |
66 | __HAL_UART_ENABLE_IT(instance->Handle, UART_IT_RXNE); |
70 | __HAL_UART_ENABLE_IT(instance->Handle, UART_IT_RXNE); |
67 | 71 | ||
68 | return rc; |
72 | return rc; |