WIP target lo
custom debug stream run docker with project dir, specify dir to makefile remove unused includes fix broken F1
This commit is contained in:
3
target_lo/Inc/cmsis_os.h
Normal file
3
target_lo/Inc/cmsis_os.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "main.h"
|
||||
|
||||
void osDelay(uint32_t ms);
|
61
target_lo/Inc/flipper_hal.h
Normal file
61
target_lo/Inc/flipper_hal.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Flipper devices inc.
|
||||
|
||||
GPIO and HAL implementations
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "main.h"
|
||||
|
||||
typedef enum {
|
||||
GpioModeInput,
|
||||
GpioModeOutput,
|
||||
GpioModeOpenDrain
|
||||
} GpioMode;
|
||||
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t pin;
|
||||
GpioMode mode;
|
||||
} GpioPin;
|
||||
|
||||
void app_gpio_init(GpioPin gpio, GpioMode mode);
|
||||
|
||||
inline void app_gpio_write(GpioPin gpio, bool state) {
|
||||
if(gpio.pin != 0) {
|
||||
if(state) {
|
||||
printf("[GPIO] %d:%d on\n", gpio.port, gpio.pin);
|
||||
} else {
|
||||
printf("[GPIO] %d:%d off\n", gpio.port, gpio.pin);
|
||||
}
|
||||
} else {
|
||||
printf("[GPIO] no pin\n");
|
||||
}
|
||||
}
|
||||
|
||||
inline bool app_gpio_read(GpioPin gpio) {
|
||||
// TODO emulate pin state?
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void delay_us(uint32_t time);
|
||||
|
||||
void pwm_set(float value, float freq, TIM_HandleTypeDef* tim, uint32_t channel);
|
||||
|
||||
extern TIM_HandleTypeDef htim8;
|
||||
|
||||
inline void app_tim_ic_init(bool both) {
|
||||
printf("[TIM] init\n");
|
||||
}
|
||||
|
||||
inline void app_tim_pulse(uint32_t width) {
|
||||
printf("[TIM] pulse %d\n", width);
|
||||
}
|
||||
|
||||
inline void app_tim_stop() {
|
||||
printf("[TIM] stop\n");
|
||||
}
|
18
target_lo/Inc/main.h
Normal file
18
target_lo/Inc/main.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define HAL_MAX_DELAY INT_MAX
|
||||
|
||||
typedef uint32_t UART_HandleTypeDef;
|
||||
uint16_t HAL_UART_Transmit(
|
||||
UART_HandleTypeDef* handle,
|
||||
uint8_t* bufer,
|
||||
uint16_t size,
|
||||
uint32_t wait_ms
|
||||
);
|
||||
|
||||
typedef uint32_t TIM_HandleTypeDef;
|
||||
|
||||
#define LED_RED_GPIO_Port 1
|
||||
#define LED_RED_Pin 1
|
121
target_lo/Makefile
Normal file
121
target_lo/Makefile
Normal file
@@ -0,0 +1,121 @@
|
||||
TARGET = target_lo
|
||||
|
||||
|
||||
######################################
|
||||
# building variables
|
||||
######################################
|
||||
# debug build?
|
||||
DEBUG = 1
|
||||
# optimization
|
||||
OPT = -Og
|
||||
|
||||
|
||||
#######################################
|
||||
# paths
|
||||
#######################################
|
||||
# Build path
|
||||
BUILD_DIR = build
|
||||
|
||||
######################################
|
||||
# source
|
||||
######################################
|
||||
# C sources
|
||||
C_SOURCES = \
|
||||
Src/main.c
|
||||
|
||||
CPP_SOURCES = ../app/app.cpp
|
||||
|
||||
C_SOURCES += ../app/write.c
|
||||
C_SOURCES += Src/flipper_hal.c
|
||||
C_SOURCES += Src/lo_os.c
|
||||
C_SOURCES += Src/lo_hal.c
|
||||
|
||||
#######################################
|
||||
# binaries
|
||||
#######################################
|
||||
|
||||
CC = gcc
|
||||
CPP = g++
|
||||
AS =
|
||||
CP = objcopy
|
||||
SZ = size
|
||||
HEX = $(CP) -O ihex
|
||||
BIN = $(CP) -O binary -S
|
||||
|
||||
#######################################
|
||||
# CFLAGS
|
||||
#######################################
|
||||
|
||||
# C defines
|
||||
C_DEFS = \
|
||||
-DUSE_HAL_DRIVER \
|
||||
-DSTM32L476xx \
|
||||
-DBUTON_INVERT=false \
|
||||
-DDEBUG_UART=huart1
|
||||
|
||||
# C includes
|
||||
C_INCLUDES = \
|
||||
-IInc \
|
||||
-I../app
|
||||
|
||||
# compile gcc flags
|
||||
CFLAGS = $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -g -gdwarf-2
|
||||
endif
|
||||
|
||||
|
||||
# Generate dependency information
|
||||
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
|
||||
|
||||
CPPFLAGS = -fno-threadsafe-statics
|
||||
|
||||
#######################################
|
||||
# LDFLAGS
|
||||
#######################################
|
||||
|
||||
# libraries
|
||||
LIBS = -lc -lm
|
||||
LIBDIR =
|
||||
LDFLAGS = $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
|
||||
|
||||
# default action: build all
|
||||
all: $(BUILD_DIR)/$(TARGET)
|
||||
|
||||
|
||||
#######################################
|
||||
# build the application
|
||||
#######################################
|
||||
# list of objects
|
||||
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
|
||||
vpath %.c $(sort $(dir $(C_SOURCES)))
|
||||
|
||||
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cpp=.o)))
|
||||
vpath %.cpp $(sort $(dir $(CPP_SOURCES)))
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
|
||||
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR)
|
||||
$(CPP) -c $(CFLAGS) $(CPPFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
|
||||
|
||||
$(BUILD_DIR)/$(TARGET): $(OBJECTS) Makefile
|
||||
$(CPP) $(OBJECTS) $(LDFLAGS) -o $@
|
||||
$(SZ) $@
|
||||
|
||||
$(BUILD_DIR):
|
||||
mkdir $@
|
||||
|
||||
#######################################
|
||||
# clean up
|
||||
#######################################
|
||||
clean:
|
||||
-rm -fR $(BUILD_DIR)
|
||||
|
||||
#######################################
|
||||
# dependencies
|
||||
#######################################
|
||||
-include $(wildcard $(BUILD_DIR)/*.d)
|
||||
|
||||
# *** EOF ***
|
41
target_lo/Src/flipper_hal.c
Normal file
41
target_lo/Src/flipper_hal.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
Flipper devices inc.
|
||||
|
||||
GPIO and HAL implementations
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "flipper_hal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void app_gpio_init(GpioPin gpio, GpioMode mode) {
|
||||
if(gpio.pin != 0) {
|
||||
|
||||
switch(mode) {
|
||||
case GpioModeInput:
|
||||
printf("[GPIO] %d:%d input\n", gpio.port, gpio.pin);
|
||||
break;
|
||||
|
||||
case GpioModeOutput:
|
||||
printf("[GPIO] %d:%d push pull\n", gpio.port, gpio.pin);
|
||||
break;
|
||||
|
||||
case GpioModeOpenDrain:
|
||||
printf("[GPIO] %d:%d open drain\n", gpio.port, gpio.pin);
|
||||
break;
|
||||
}
|
||||
|
||||
gpio.mode = mode;
|
||||
} else {
|
||||
printf("[GPIO] no pin\n");
|
||||
}
|
||||
}
|
||||
|
||||
void delay_us(uint32_t time) {
|
||||
// How to deal with it
|
||||
printf("[DELAY] %d us\n", time);
|
||||
}
|
||||
|
||||
void pwm_set(float value, float freq, TIM_HandleTypeDef* tim, uint32_t channel) {
|
||||
printf("[TIM] set pwm %d:%d %f Hz, %f%%\n", *tim, channel, freq, value * 100.);
|
||||
}
|
21
target_lo/Src/lo_hal.c
Normal file
21
target_lo/Src/lo_hal.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
Flipper devices inc.
|
||||
|
||||
Dummy hal for local fw build
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "main.h"
|
||||
#include <unistd.h>
|
||||
|
||||
UART_HandleTypeDef DEBUG_UART = 0;
|
||||
|
||||
uint16_t HAL_UART_Transmit(
|
||||
UART_HandleTypeDef* handle,
|
||||
uint8_t* bufer,
|
||||
uint16_t size,
|
||||
uint32_t wait_ms
|
||||
) {
|
||||
uint16_t res = write(1, (const char*)bufer, size);
|
||||
return res;
|
||||
}
|
8
target_lo/Src/lo_os.c
Normal file
8
target_lo/Src/lo_os.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "cmsis_os.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void osDelay(uint32_t ms) {
|
||||
usleep(ms * 1000);
|
||||
printf("[DELAY] %d ms\n", ms);
|
||||
}
|
13
target_lo/Src/main.c
Normal file
13
target_lo/Src/main.c
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
Flipper devices inc.
|
||||
|
||||
Local fw build entry point.
|
||||
*/
|
||||
|
||||
void app();
|
||||
|
||||
int main() {
|
||||
app();
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user