working receive
This commit is contained in:
@@ -6,7 +6,7 @@ set(MAIN_SOURCE_FILE main.cpp)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
|
||||
|
||||
set(HAL_COMP_LIST RCC GPIO CORTEX UART SPI)
|
||||
set(HAL_COMP_LIST RCC GPIO CORTEX UART SPI DMA)
|
||||
set(CMSIS_COMP_LIST "")
|
||||
|
||||
list(APPEND CMSIS_COMP_LIST STM32F1)
|
||||
@@ -31,6 +31,7 @@ add_executable(stm32-blinky-f1
|
||||
uart_handler.cpp
|
||||
spi.cpp
|
||||
rfm95.cpp
|
||||
stm32f1xx_it.c
|
||||
stm32f1xx_hal_conf.h
|
||||
)
|
||||
|
||||
@@ -42,6 +43,7 @@ target_link_libraries(stm32-blinky-f1
|
||||
HAL::STM32::F1::GPIO
|
||||
HAL::STM32::F1::CORTEX
|
||||
HAL::STM32::F1::SPI
|
||||
HAL::STM32::F1::DMA
|
||||
CMSIS::STM32::F100RB
|
||||
STM32::NoSys
|
||||
)
|
||||
@@ -62,5 +64,3 @@ stm32_print_size_of_target(stm32-blinky-f1)
|
||||
# STM32::NoSys
|
||||
#)
|
||||
#stm32_print_size_of_target(stm32-blinky-f1)
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ inline std::string_view get_loglevel_string(LogLevel level) {
|
||||
|
||||
class logging_adapter {
|
||||
public:
|
||||
virtual bool init(){}
|
||||
virtual bool init() { return true; }
|
||||
virtual void log(std::string_view message) const = 0;
|
||||
};
|
||||
|
||||
@@ -79,8 +79,8 @@ class log {
|
||||
return;
|
||||
}
|
||||
|
||||
//std::stringstream msg;
|
||||
//msg << get_loglevel_string(level) << ": " << message;
|
||||
// std::stringstream msg;
|
||||
// msg << get_loglevel_string(level) << ": " << message;
|
||||
logger->log(get_loglevel_string(level));
|
||||
logger->log(": ");
|
||||
logger->log(message);
|
||||
|
||||
19
main.cpp
19
main.cpp
@@ -1,4 +1,5 @@
|
||||
#include <stm32f1xx_hal.h>
|
||||
#include <stm32f1xx_hal_uart.h>
|
||||
|
||||
#include "logging.hpp"
|
||||
#include "spi.hpp"
|
||||
@@ -27,6 +28,22 @@ void SysTick_Handler(void) {
|
||||
HAL_IncTick();
|
||||
HAL_SYSTICK_IRQHandler();
|
||||
}
|
||||
|
||||
void USART1_IRQHandler(void) {
|
||||
HAL_UART_IRQHandler(&uart_interface::s_UARTHandle);
|
||||
HAL_UART_Receive_IT(&uart_interface::s_UARTHandle, uart_interface::get_buf(),
|
||||
1);
|
||||
}
|
||||
|
||||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
const char value = *reinterpret_cast<const char *>(uart_interface::get_buf());
|
||||
|
||||
if (value == '\r') {
|
||||
HAL_GPIO_TogglePin(LED_PORT, LED2_PIN);
|
||||
}
|
||||
|
||||
log::debug({&value, 1});
|
||||
}
|
||||
}
|
||||
|
||||
void initGPIO() {
|
||||
@@ -105,11 +122,9 @@ int main(void) {
|
||||
while (1) {
|
||||
// RF95_setModeRx_Continuous();
|
||||
HAL_GPIO_WritePin(LED_PORT, LED1_PIN, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(LED_PORT, LED2_PIN, GPIO_PIN_RESET);
|
||||
// RF95_receive(LoRa_buff);
|
||||
HAL_Delay(500);
|
||||
HAL_GPIO_WritePin(LED_PORT, LED1_PIN, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(LED_PORT, LED2_PIN, GPIO_PIN_SET);
|
||||
HAL_Delay(500);
|
||||
|
||||
// std::string_view msg{reinterpret_cast<char *>(LoRa_buff)};
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
#include "uart_handler.hpp"
|
||||
|
||||
template <>
|
||||
// uint8_t* uart_interface::rx_buff = new uint8_t[10];
|
||||
uint8_t uart_interface::rx_buff = 0;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "stm32f1xx_it.h"
|
||||
|
||||
constexpr auto UART_PORT = GPIOA_BASE;
|
||||
#define UARTPORT GPIOA
|
||||
#define UARTTX_PIN GPIO_PIN_9
|
||||
@@ -37,8 +39,8 @@ struct uart_handler {
|
||||
HAL_GPIO_Init(reinterpret_cast<GPIO_TypeDef*>(port), &ua_rx);
|
||||
|
||||
/* USART1 interrupt Init */
|
||||
// HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
|
||||
// HAL_NVIC_EnableIRQ(USART1_IRQn);
|
||||
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(USART1_IRQn);
|
||||
}
|
||||
|
||||
static bool enable_oscillators() {
|
||||
@@ -87,7 +89,7 @@ struct uart_handler {
|
||||
return false;
|
||||
}
|
||||
|
||||
// result = HAL_UART_Receive_IT(&s_UARTHandle, rx_buff, rx_buff_size);
|
||||
result = HAL_UART_Receive_IT(&s_UARTHandle, &rx_buff, rx_buff_size);
|
||||
|
||||
return result == HAL_OK;
|
||||
}
|
||||
@@ -122,15 +124,16 @@ struct uart_handler {
|
||||
|
||||
static UART_HandleTypeDef s_UARTHandle;
|
||||
|
||||
static uint8_t* get_buf() { return rx_buff; }
|
||||
static uint8_t* get_buf() { return &rx_buff; }
|
||||
static const uint8_t* get_buf_c() { return &rx_buff; }
|
||||
|
||||
private:
|
||||
static constexpr auto pin_tx = PinTX;
|
||||
static constexpr auto pin_rx = PinRX;
|
||||
static constexpr auto port = Port;
|
||||
static constexpr auto usart_base = UsartBase;
|
||||
static constexpr size_t rx_buff_size = 10;
|
||||
static inline uint8_t* rx_buff;
|
||||
static constexpr size_t rx_buff_size = 1;
|
||||
static uint8_t rx_buff;
|
||||
};
|
||||
|
||||
template <uint16_t PinTX, uint16_t PinRX, uint32_t Port, uint32_t UsartBase>
|
||||
@@ -139,12 +142,3 @@ UART_HandleTypeDef uart_handler<PinTX, PinRX, Port, UsartBase>::s_UARTHandle =
|
||||
|
||||
using uart_interface =
|
||||
uart_handler<UARTTX_PIN, UARTRX_PIN, UART_PORT, USART1_BASE>;
|
||||
|
||||
template <>
|
||||
uint8_t* uart_interface::rx_buff = new uint8_t[10];
|
||||
|
||||
// inline void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) {
|
||||
// static int count = 0;
|
||||
// count++;
|
||||
// HAL_UART_Receive_IT(huart, uart_interface::get_buf(), 10);
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user