1
0

more hacks

This commit is contained in:
Arti Zirk 2021-07-21 23:04:05 +03:00
parent 8366bbe163
commit 451f477729
7 changed files with 75 additions and 37 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ bin/
generated.*.ld
.idea
build
STM32F103xx.svd

View File

@ -6,28 +6,32 @@ set(CMAKE_C_STANDARD 99)
add_compile_options(
-Wall
-Wextra
-Wconversion
-Wsign-conversion
-Wextra -Wshadow -Wno-unused-variable -Wimplicit-function-declaration
-Wredundant-decls -Wstrict-prototypes -Wmissing-prototypes
-ggdb3
-Os
-O0
)
add_link_options(
)
add_compile_definitions(
STM32F1
STM32F103C8T6
DEBUG
)
add_executable(dht_test main.c)
set_target_properties(dht_test PROPERTIES
SUFFIX .elf
)
target_include_directories(dht_test PRIVATE
${LIBOPENCM3_DIR}/include
RTT
)
set_target_properties(dht_test PROPERTIES SUFFIX .elf)
add_custom_target(libopencm3 make TARGETS=stm32/f1 -j8 WORKING_DIRECTORY ${LIBOPENCM3_DIR})
link_directories(${LIBOPENCM3_DIR}/lib)
#link_directories(${LIBOPENCM3_DIR}/lib)
target_link_libraries(dht_test PUBLIC ${LIBOPENCM3_DIR}/lib/libopencm3_stm32f1.a)
add_subdirectory(RTT)
target_link_libraries(dht_test PUBLIC RTT)
target_include_directories(dht_test PUBLIC
RTT ${LIBOPENCM3_DIR}/include
)

View File

@ -1,5 +1,5 @@
{
"version": 2,
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 19,
@ -11,7 +11,8 @@
"displayName": "Default Config",
"description": "Default build using Ninja generator",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/default"
"binaryDir": "${sourceDir}/build",
"toolchainFile": "toolchain-STM32F1.cmake"
}
],
"buildPresets": [

View File

@ -1,7 +1,22 @@
## Build
0. git submodule update --init (This is only needed once)
1. make -C libopencm3 # (Only needed once)
2. make
First time:
0. `git submodule update --init`
1. `make -C libopencm3`
2. `cmake -S . --preset=default`
or older cmake:
2. `cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=toolchain-STM32F1.cmake`
And then to build an `.elf`
0. `cmake --build build --verbose`
## RTT debug console
run this while `openocd` is running
while true; do telnet localhost 9090; sleep 1; done

8
RTT/CMakeLists.txt Normal file
View File

@ -0,0 +1,8 @@
add_library(RTT
SEGGER_RTT.c
SEGGER_RTT_printf.c
SEGGER_RTT_Syscalls_GCC.c
)
target_include_directories(RTT
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
)

24
main.c
View File

@ -26,6 +26,8 @@
#include <SEGGER_RTT.h>
#define puts(s) SEGGER_RTT_WriteString(0, s);SEGGER_RTT_WriteString(0,"\n")
#define DHT_PORT GPIOB
#define DHT_PIN GPIO0
@ -197,7 +199,7 @@ static void dht_start(void)
}
// Parse received DHT11 bit timing data from g_dht_vals and print out pretty values
static void dht_parse_data(){
static void dht_parse_data(void) {
int8_t data[5] = {0};
uint8_t checksum = 0;
int data_index = 0;
@ -231,16 +233,16 @@ static void dht_parse_data(){
}
// Just toggle the data pin, used only for debugging
static void dht_start_signal(void)
{
gpio_set_mode(DHT_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, DHT_PIN);
gpio_clear(DHT_PORT, DHT_PIN);
delay(100000);
//delay(30000);
gpio_set(DHT_PORT, DHT_PIN);
delay(100);
gpio_set_mode(DHT_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, DHT_PIN);
}
//static void dht_start_signal(void)
//{
// gpio_set_mode(DHT_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, DHT_PIN);
// gpio_clear(DHT_PORT, DHT_PIN);
// delay(100000);
// //delay(30000);
// gpio_set(DHT_PORT, DHT_PIN);
// delay(100);
// gpio_set_mode(DHT_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, DHT_PIN);
//}
int main(void)
{

View File

@ -3,14 +3,12 @@ set(CMAKE_SYSTEM_VERSION Cortex-M3-STM32F1)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(ARM_OPTIONS -mcpu=cortex-m4 -mfloat-abi=soft --specs=nano.specs)
set(ARM_OPTIONS -mcpu=cortex-m3 -mthumb -msoft-float)
add_compile_options(
${ARM_OPTIONS}
-fmessage-length=0
-funsigned-char
-ffunction-sections
-fdata-sections
-MMD
@ -20,12 +18,21 @@ add_compile_options(
add_link_options(
${ARM_OPTIONS}
--specs=rdimon.specs
-u_printf_float
-u_scanf_float
-specs=nano.specs
-specs=nosys.specs # puts does not work.....
#-specs=rdimon.specs
LINKER:-lc
LINKER:-lgcc
LINKER:-lnosys
#-specs=nano.specs
#-u_printf_float
#-u_scanf_float
-nostartfiles
#-Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
LINKER:--gc-sections
LINKER:--build-id
LINKER:-Map=${CMAKE_PROJECT_NAME}.map
-T${CMAKE_SOURCE_DIR}/generated.STM32F103C8T6.ld
)