diff options
Diffstat (limited to 'uart')
-rw-r--r-- | uart/SConscript | 21 | ||||
-rw-r--r-- | uart/stm32_uart.h | 33 | ||||
-rw-r--r-- | uart/uart.h | 12 |
3 files changed, 66 insertions, 0 deletions
diff --git a/uart/SConscript b/uart/SConscript new file mode 100644 index 0000000..dcf6d3e --- /dev/null +++ b/uart/SConscript @@ -0,0 +1,21 @@ +Import('env') + +headers = [] +instances = [] +sources = [] +aliases = {} + +periph = env['PLATFORM_SPEC'].get('periph', {}) + +if 'stm32_uart' in periph: + headers.append('stm32_uart.h') + for name, data in periph['stm32_uart'].items(): + instances.append({ + 'type': 'STM32_UART_t<STM32_UART_reg_%s_t>' % data['type'], + 'name': name, + 'args': [data['offset']], + }) + +env.Jinja2('uart.h', '../templates/periph_instances.h.j2', headers = headers, instances = instances, aliases = aliases) + +Return('sources') diff --git a/uart/stm32_uart.h b/uart/stm32_uart.h new file mode 100644 index 0000000..e4902a5 --- /dev/null +++ b/uart/stm32_uart.h @@ -0,0 +1,33 @@ +#pragma once + +#include <mmio/mmio.h> + +struct STM32_UART_reg_v1_t { + volatile uint32_t SR; + volatile uint32_t DR; + volatile uint32_t BRR; + volatile uint32_t CR1; + volatile uint32_t CR2; + volatile uint32_t CR3; + volatile uint32_t GTPR; +}; + +struct STM32_UART_reg_v2_t { + volatile uint32_t CR1; + volatile uint32_t CR2; + volatile uint32_t CR3; + volatile uint32_t BRR; + volatile uint32_t GTPR; + volatile uint32_t RTOR; + volatile uint32_t RQR; + volatile uint32_t ISR; + volatile uint32_t ICR; + volatile uint32_t RDR; + volatile uint32_t TDR; +}; + +template <typename T> +class STM32_UART_t : public mmio_ptr<T> { + public: + using mmio_ptr<T>::ptr; +}; diff --git a/uart/uart.h b/uart/uart.h new file mode 100644 index 0000000..ed680ea --- /dev/null +++ b/uart/uart.h @@ -0,0 +1,12 @@ +#pragma once + +#include "stm32_uart.h" + +constexpr STM32_UART_t<STM32_UART_reg_v1_t> USART1{ + 0x40011000, +}; +constexpr STM32_UART_t<STM32_UART_reg_v1_t> USART2{ + 0x40004400, +}; + + |