update Chapter07

This commit is contained in:
Amar Mahmutbegovic
2024-07-02 14:59:34 +02:00
parent 8a82226c0c
commit 3c0ac106d0
4 changed files with 101 additions and 31 deletions

View File

@@ -83,6 +83,8 @@ include_directories(
${CMAKE_SOURCE_DIR}/cstdlib_support
)
set(MAIN_CPP_PATH "${CMAKE_SOURCE_DIR}/app/src/")
set(MAIN_CPP_FILE_NAME "main_assert.cpp" CACHE STRING "main")
set(EXECUTABLE ${PROJECT_NAME}.elf)
@@ -98,9 +100,9 @@ add_executable(
platform/src/stm32f0xx_hal_msp.c
platform/src/stm32f0xx_it.c
platform/src/system_stm32f0xx.c
app/src/main.cpp
hal/uart/src/uart_stm32.cpp
cstdlib_support/retarget.cpp
${MAIN_CPP_PATH}/${MAIN_CPP_FILE_NAME}
)
target_link_libraries(${EXECUTABLE} PUBLIC)

View File

@@ -1,30 +0,0 @@
#include <cstdint>
#include <cstdio>
#include <stm32f072xb.h>
#include <hal.hpp>
#include <uart_stm32.hpp>
#include <retarget.hpp>
int main()
{
hal::init();
hal::uart_stm32 uart(USART2);
uart.init();
uart.write("Hi from main function!\r\n");
retarget::set_stdio_uart(&uart);
printf("Printing using printf\r\n");
printf("PC: 0x%08lX\r\n", hal::get_pc());
while(true)
{
}
}

View File

@@ -0,0 +1,50 @@
#include <cstdint>
#include <cstdio>
#include <stm32f072xb.h>
#include <hal.hpp>
#include <uart_stm32.hpp>
#include <retarget.hpp>
void log_pc_and_halt(std::uint32_t pc) {
printf("Assert at 0x%08lX\r\n", pc);
while(true) {}
}
#define light_assert(expr) \
(static_cast<bool> (expr) \
? void (0) \
: log_pc_and_halt(hal::get_pc()) \
)
enum class option : std::uint8_t {
Option1 = 0,
Option2,
Option3,
Last
};
option uint8_to_option(uint8_t num) {
light_assert(num < static_cast<uint8_t>(option::Last));
return static_cast<option>(num);
}
int main()
{
hal::init();
hal::uart_stm32 uart(USART2);
uart.init();
retarget::set_stdio_uart(&uart);
printf("Assert example\r\n");
const option opt = uint8_to_option(3);
while(true)
{
}
}

View File

@@ -0,0 +1,48 @@
#include <cstdint>
#include <cstdio>
#include <stm32f072xb.h>
#include <hal.hpp>
#include <uart_stm32.hpp>
#include <retarget.hpp>
void log_pc_and_halt(std::uint32_t pc) {
printf("Assert at 0x%08lX\r\n", pc);
while(true) {}
}
#define light_assert(expr) \
(static_cast<bool> (expr) \
? void (0) \
: log_pc_and_halt(hal::get_pc()) \
)
enum class option : std::uint8_t {
Option1 = 0,
Option2,
Option3,
Last
};
option uint8_to_option(uint8_t num) {
light_assert(num < static_cast<uint8_t>(option::Last));
return static_cast<option>(num);
}
int main()
{
hal::init();
hal::uart_stm32 uart(USART2);
uart.init();
retarget::set_stdio_uart(&uart);
printf("Exceptions example\r\n");
while(true)
{
}
}