add Chapter04/Dockerfile, Chapter04/bare/.clang-tidy
This commit is contained in:
@@ -12,6 +12,7 @@ RUN apt-get update && apt-get install -y \
|
|||||||
software-properties-common \
|
software-properties-common \
|
||||||
cmake \
|
cmake \
|
||||||
make \
|
make \
|
||||||
|
git \
|
||||||
&& add-apt-repository ppa:deadsnakes/ppa \
|
&& add-apt-repository ppa:deadsnakes/ppa \
|
||||||
&& apt-get update \
|
&& apt-get update \
|
||||||
&& apt-get install -y python3.8 python3.8-distutils \
|
&& apt-get install -y python3.8 python3.8-distutils \
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Chapter04/bare/.cache/clangd/index/hal.hpp.6DADBD8849084F23.idx
Normal file
BIN
Chapter04/bare/.cache/clangd/index/hal.hpp.6DADBD8849084F23.idx
Normal file
Binary file not shown.
BIN
Chapter04/bare/.cache/clangd/index/main.cpp.DADEEDC6E9425266.idx
Normal file
BIN
Chapter04/bare/.cache/clangd/index/main.cpp.DADEEDC6E9425266.idx
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Chapter04/bare/.cache/clangd/index/uart.hpp.422491F9E7AE0BF7.idx
Normal file
BIN
Chapter04/bare/.cache/clangd/index/uart.hpp.422491F9E7AE0BF7.idx
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
22
Chapter04/bare/.clang-tidy
Normal file
22
Chapter04/bare/.clang-tidy
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
Checks: >
|
||||||
|
-*,
|
||||||
|
bugprone-*,
|
||||||
|
misc-*,
|
||||||
|
clang-analyzer-*,
|
||||||
|
modernize-*,
|
||||||
|
-modernize-use-trailing-return-type,
|
||||||
|
performance-*,
|
||||||
|
portability-*,
|
||||||
|
readability-*,
|
||||||
|
readability-identifier-naming
|
||||||
|
|
||||||
|
CheckOptions:
|
||||||
|
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
|
||||||
|
- { key: readability-identifier-naming.ClassCase, value: lower_case }
|
||||||
|
- { key: readability-identifier-naming.StructCase, value: lower_case }
|
||||||
|
- { key: readability-identifier-naming.MethodCase, value: lower_case }
|
||||||
|
- { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase }
|
||||||
|
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
|
||||||
|
- { key: readability-identifier-naming.VariableCase, value: lower_case }
|
||||||
|
- { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
|
||||||
|
- { key: readability-identifier-naming.ConstexprVariablePrefix, value: c_ }
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include <stm32f0xx_hal.h>
|
|
||||||
|
|
||||||
#include <hal.hpp>
|
#include <hal.hpp>
|
||||||
#include <uart_stm32.hpp>
|
#include <uart_stm32.hpp>
|
||||||
|
#include <stm32f072xb.h>
|
||||||
|
|
||||||
extern "C" int main(void)
|
extern "C" int main(void)
|
||||||
{
|
{
|
||||||
@@ -15,14 +14,14 @@ extern "C" int main(void)
|
|||||||
uart.puts("Hello world !\r\n");
|
uart.puts("Hello world !\r\n");
|
||||||
|
|
||||||
std::uint32_t time_prev = hal::time::get_ms();
|
std::uint32_t time_prev = hal::time::get_ms();
|
||||||
while(1)
|
constexpr std::uint32_t c_1000_ms = 1000;
|
||||||
|
while(true)
|
||||||
{
|
{
|
||||||
if(volatile auto time_now = hal::time::get_ms();
|
if(auto time_now = hal::time::get_ms();
|
||||||
time_now - time_prev > 1000)
|
time_now - time_prev > c_1000_ms)
|
||||||
{
|
{
|
||||||
uart.puts("While loop 1000 ms ping ...\r\n");
|
uart.puts("While loop 1000 ms ping ...\r\n");
|
||||||
time_prev = time_now;
|
time_prev = time_now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ inline void init()
|
|||||||
|
|
||||||
struct time
|
struct time
|
||||||
{
|
{
|
||||||
inline static std::uint32_t get_ms()
|
static std::uint32_t get_ms()
|
||||||
{
|
{
|
||||||
return HAL_GetTick();
|
return HAL_GetTick();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,21 +5,23 @@
|
|||||||
#include <uart.hpp>
|
#include <uart.hpp>
|
||||||
|
|
||||||
#include <stm32f0xx_hal.h>
|
#include <stm32f0xx_hal.h>
|
||||||
|
#include <stm32f072xb.h>
|
||||||
|
|
||||||
namespace hal
|
namespace hal
|
||||||
{
|
{
|
||||||
class uart_stm32 : public uart
|
class uart_stm32 : public uart
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uart_stm32(USART_TypeDef *inst, std::uint32_t baud = 115200);
|
uart_stm32(USART_TypeDef *inst, std::uint32_t baud = baudrate_default);
|
||||||
|
|
||||||
void init() override;
|
void init() override;
|
||||||
|
|
||||||
void putchar(char c) override;
|
void putchar(char tx_char) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UART_HandleTypeDef huart;
|
UART_HandleTypeDef huart_;
|
||||||
USART_TypeDef *instance;
|
USART_TypeDef *instance_;
|
||||||
std::uint32_t baudrate;
|
std::uint32_t baudrate_;
|
||||||
|
static constexpr std::uint32_t baudrate_default = 115200;
|
||||||
};
|
};
|
||||||
}; // namespace hal
|
}; // namespace hal
|
||||||
|
|||||||
@@ -1,33 +1,29 @@
|
|||||||
#include <uart_stm32.hpp>
|
#include <uart_stm32.hpp>
|
||||||
|
|
||||||
hal::uart_stm32::uart_stm32(USART_TypeDef *inst, std::uint32_t baud)
|
hal::uart_stm32::uart_stm32(USART_TypeDef *inst, std::uint32_t baud)
|
||||||
: instance(inst), baudrate(baud)
|
: instance_(inst), baudrate_(baud)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void hal::uart_stm32::init()
|
void hal::uart_stm32::init()
|
||||||
{
|
{
|
||||||
huart.Instance = USART2;
|
huart_.Instance = USART2;
|
||||||
huart.Init.BaudRate = 115200;
|
huart_.Init.BaudRate = baudrate_;
|
||||||
huart.Init.WordLength = UART_WORDLENGTH_8B;
|
huart_.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
huart.Init.StopBits = UART_STOPBITS_1;
|
huart_.Init.StopBits = UART_STOPBITS_1;
|
||||||
huart.Init.Parity = UART_PARITY_NONE;
|
huart_.Init.Parity = UART_PARITY_NONE;
|
||||||
huart.Init.Mode = UART_MODE_TX_RX;
|
huart_.Init.Mode = UART_MODE_TX_RX;
|
||||||
huart.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
huart_.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||||
huart.Init.OverSampling = UART_OVERSAMPLING_16;
|
huart_.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||||
huart.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
huart_.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
||||||
huart.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
huart_.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
||||||
|
// TODO: add GPIO initialization for real hardware
|
||||||
// huart.MspInitCallback = mspInitCallback;
|
huart_.MspInitCallback = NULL;
|
||||||
|
HAL_UART_Init(&huart_);
|
||||||
if(HAL_UART_Init(&huart) != HAL_OK)
|
|
||||||
{
|
|
||||||
// Error_Handler();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void hal::uart_stm32::putchar(char c)
|
void hal::uart_stm32::putchar(char tx_char)
|
||||||
{
|
{
|
||||||
HAL_UART_Transmit(&huart, reinterpret_cast<uint8_t *>(&c), 1,
|
HAL_UART_Transmit(&huart_, reinterpret_cast<uint8_t *>(&tx_char), 1,
|
||||||
HAL_MAX_DELAY);
|
HAL_MAX_DELAY);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user