Skip to content

Commit

Permalink
DAQ Redesign (#79)
Browse files Browse the repository at this point in the history
* sd, udp, tcp

* logging 30 mins on car
  • Loading branch information
LukeOxley authored Mar 14, 2024
1 parent dffbe1f commit 5ff2e93
Show file tree
Hide file tree
Showing 38 changed files with 28,928 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "common/STM32CubeF7"]
path = common/STM32CubeF7
url = https://github.com/STMicroelectronics/STM32CubeF7.git
[submodule "common/modules/Wiznet/W5500"]
path = common/modules/Wiznet/W5500
url = https://github.com/Wiznet/ioLibrary_Driver.git
39 changes: 39 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,45 @@
"preLaunchTask": "build",
"runToEntryPoint": "main"
},
{ "name": "daq",
"cwd": "${workspaceRoot}",
"executable": "./output/daq/daq.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device:": "STM32F407VG",
"svdFile": "${workspaceRoot}/common/svd/STM32F407.svd",
"configFiles": [
"interface/stlink.cfg",
"target/stm32f4x.cfg",
"${workspaceRoot}/common/openocd/openocd-gdb.cfg"
],
"debuggerArgs": [
"-d",
"${workspaceFolder}/source/daq"
],
"preLaunchTask": "build",
"runToEntryPoint": "main",
},
{ "name": "daq_attach",
"cwd": "${workspaceRoot}",
"executable": "./output/daq/daq.elf",
"request": "attach",
"type": "cortex-debug",
"servertype": "openocd",
"device:": "STM32F407VG",
"svdFile": "${workspaceRoot}/common/svd/STM32F407.svd",
"configFiles": [
"interface/stlink.cfg",
"target/stm32f4x.cfg",
"${workspaceRoot}/common/openocd/openocd-gdb.cfg"
],
"debuggerArgs": [
"-d",
"${workspaceFolder}/source/daq"
],
"runToEntryPoint": "main",
},
{ "name": "l4_testing",
"cwd": "${workspaceRoot}",
"executable": "./output/l4_testing/l4_testing.elf",
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ add_subdirectory(common/psched)
add_subdirectory(common/bootloader)
add_subdirectory(common/queue)
add_subdirectory(common/common_defs)
add_subdirectory(common/log)
add_subdirectory(common/faults)
add_subdirectory(common/daq)
add_subdirectory(common/plettenberg)
add_subdirectory(common/modules/wheel_speeds)
add_subdirectory(common/modules/Wiznet)

# Properties that are set for each firmware component
# Used to generate the .elf and other files for each project
Expand Down Expand Up @@ -91,6 +93,7 @@ add_subdirectory(source/a_box)
add_subdirectory(source/torque_vector)
add_subdirectory(source/dashboard)
add_subdirectory(source/pdu)
add_subdirectory(source/daq)


# Deprecated Components
Expand Down
2 changes: 2 additions & 0 deletions cmake/common_component.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ MACRO(COMMON_FIRMWARE_COMPONENT TARGET_NAME)

# Find all .c sources in project, recursive search starting at component root
file(GLOB_RECURSE glob_sources ${_COMPONENT_DIR}/*.c)
# Exclude if it is a test file
list(FILTER glob_sources EXCLUDE REGEX "test_.*")
target_sources(${TARGET_NAME} PUBLIC ${glob_sources})

# Find directories for '#include'
Expand Down
13 changes: 12 additions & 1 deletion cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,15 @@ MACRO(SUBDIRLIST curdir result)
ENDIF()
ENDFOREACH()
SET(${result} ${dirlist})
ENDMACRO()
ENDMACRO()

MACRO(RECURSE_DIRECTORIES curdir search_term return_list)
FILE(GLOB_RECURSE new_list RELATIVE ${curdir} ${search_term})
SET(dir_list "")
FOREACH(file_path ${new_list})
GET_FILENAME_COMPONENT(dir_path ${file_path} PATH)
SET(dir_list ${dir_list} ${dir_path})
ENDFOREACH()
LIST(REMOVE_DUPLICATES dir_list)
SET(${return_list} ${dir_list})
ENDMACRO()
6 changes: 6 additions & 0 deletions common/log/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.13)

add_library(log INTERFACE)

# Find directories for '#include', this directroy for the simple lib
target_include_directories(log INTERFACE .)
61 changes: 61 additions & 0 deletions common/log/log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef __LOG_H__
#define __LOG_H__

#include <stdio.h>
#include <stdbool.h>

extern void _log_str(char* data);
extern char log_buffer[];

#define log_printf(...) do { \
sprintf(log_buffer, __VA_ARGS__); \
_log_str(log_buffer); \
} while(false)
// #define log_printf(...) sprintf(log_buffer, __VA_ARGS__)


#define ANSI_RED "\x1b[31m"
#define ANSI_GREEN "\x1b[32m"
#define ANSI_YELLOW "\x1b[33m"
#define ANSI_BLUE "\x1b[34m"
#define ANSI_MAGENTA "\x1b[35m"
#define ANSI_CYAN "\x1b[36m"
#define ANSI_RESET "\x1b[37m"

#define __mu_log_color(color, ...) do { \
log_printf("%s", color); \
log_printf(__VA_ARGS__); \
log_printf("%s", ANSI_RESET); \
} while(false)

#ifdef DEBUG_LOG

# define log_msg(...) log_printf(__VA_ARGS__)
# define log_int(n) (log_printf("%s == %d\n", (#n), (n)))
# define log_str(s) (log_printf("%s == %s\n", (#s), (s)))
# define log_char(c) (log_printf("%s == '%c'\n", (#c), (c)))
# define log_addr(addr) (log_printf("%s == %p\n", (#addr), (void*)(addr)))
# define log_red(...) __mu_log_color(ANSI_RED, __VA_ARGS__)
# define log_green(...) __mu_log_color(ANSI_GREEN, __VA_ARGS__)
# define log_yellow(...) __mu_log_color(ANSI_YELLOW, __VA_ARGS__)
# define log_blue(...) __mu_log_color(ANSI_BLUE, __VA_ARGS__)
# define log_magenta(...) __mu_log_color(ANSI_MAGENTA, __VA_ARGS__)
# define log_cyan(...) __mu_log_color(ANSI_CYAN, __VA_ARGS__)

#else

# define log_msg(...)
# define log_int(n)
# define log_str(s)
# define log_char(c)
# define log_addr(addr)
# define log_red(...)
# define log_green(...)
# define log_yellow(...)
# define log_blue(...)
# define log_magenta(...)
# define log_cyan(...)

#endif

#endif
16 changes: 16 additions & 0 deletions common/modules/Wiznet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
set(TARGET_NAME W5500)
add_library(${TARGET_NAME})

set(LIB_DIR ${CMAKE_SOURCE_DIR}/common/modules/Wiznet)

# Find all .c sources in project
# Only using Ethernet for now
file(GLOB_RECURSE glob_sources ${LIB_DIR}/W5500/Ethernet/*.c)
target_sources(${TARGET_NAME} PRIVATE ${glob_sources})

# Find directories for '#include'
# Only using Ethernet for now
RECURSE_DIRECTORIES(${LIB_DIR} "W5500/Ethernet/*.h" include_dirs)
message("${include_dirs}")

target_include_directories(${TARGET_NAME} PUBLIC ${include_dirs})
1 change: 1 addition & 0 deletions common/modules/Wiznet/W5500
Submodule W5500 added at 3847fb
3 changes: 3 additions & 0 deletions common/openocd/openocd-gdb.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$_TARGETNAME configure -event gdb-detach {
resume
}
16 changes: 16 additions & 0 deletions common/phal_F4_F7/gpio/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ typedef struct
#define GPIO_INIT_SPI2_MISO_PB14 GPIO_INIT_AF(GPIOB, 14, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)
#define GPIO_INIT_SPI2_MOSI_PB15 GPIO_INIT_AF(GPIOB, 15, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_DOWN)

#define GPIO_INIT_SPI2_MISO_PC2 GPIO_INIT_AF(GPIOC, 2, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)
#define GPIO_INIT_SPI2_MOSI_PC3 GPIO_INIT_AF(GPIOC, 3, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_DOWN)
#define GPIO_INIT_SPI1_SCK_PB3 GPIO_INIT_AF(GPIOB, 3, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_DOWN)
#define GPIO_INIT_SPI2_MISO_PB4 GPIO_INIT_AF(GPIOB, 4, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)
#define GPIO_INIT_SPI1_MOSI_PB5 GPIO_INIT_AF(GPIOB, 5, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_DOWN)

#define GPIO_INIT_SPI1_SCK_PA5 GPIO_INIT_AF(GPIOA, 5, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_DOWN)
Expand All @@ -210,8 +213,21 @@ typedef struct

#define GPIO_INIT_USART1TX_PA9 GPIO_INIT_AF(GPIOA, 9, 7, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN)
#define GPIO_INIT_USART1RX_PA10 GPIO_INIT_AF(GPIOA, 10, 7, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)

#define GPIO_INIT_USART2TX_PD5 GPIO_INIT_AF(GPIOD, 5, 7, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN)
#define GPIO_INIT_USART2RX_PD6 GPIO_INIT_AF(GPIOD, 6, 7, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)
#define GPIO_INIT_USART3TX_PC10 GPIO_INIT_AF(GPIOC, 10, 7, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_OPEN_DRAIN)
#define GPIO_INIT_USART3RX_PC11 GPIO_INIT_AF(GPIOC, 11, 7, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)
#endif

// SDIO
#define GPIO_INIT_SDIO_CLK GPIO_INIT_AF(GPIOC, 12, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)
#define GPIO_INIT_SDIO_CMD GPIO_INIT_AF(GPIOD, 2, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)
#define GPIO_INIT_SDIO_DT0 GPIO_INIT_AF(GPIOC, 8, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)
#define GPIO_INIT_SDIO_DT1 GPIO_INIT_AF(GPIOC, 9, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)
#define GPIO_INIT_SDIO_DT2 GPIO_INIT_AF(GPIOC, 10, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)
#define GPIO_INIT_SDIO_DT3 GPIO_INIT_AF(GPIOC, 11, 12, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_UP)

#ifdef STM32F732xx
//CAN
#define GPIO_INIT_CANRX_PA11 GPIO_INIT_AF(GPIOA, 11, 9, GPIO_OUTPUT_ULTRA_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN)
Expand Down
11 changes: 9 additions & 2 deletions common/phal_F4_F7/rcc/rcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,16 @@ bool PHAL_configurePLLSystemClock(uint32_t system_clock_target_hz)
return false;
}

// Set the PLLP divisor
RCC->PLLCFGR &= ~RCC_PLLCFGR_PLLP_Msk;
uint8_t pll_q_divisor = PLLClockRateHz/48000000;
if(pll_q_divisor <= 1 || pll_q_divisor > 15)
{
return false;
}

// Set the PLLP and PLLQ divisors
RCC->PLLCFGR &= ~(RCC_PLLCFGR_PLLP_Msk | RCC_PLLCFGR_PLLQ_Msk);
RCC->PLLCFGR |= (((pll_p_divisor / 2) - 1) << RCC_PLLCFGR_PLLP_Pos) & RCC_PLLCFGR_PLLP_Msk; // Divisor value to PLLP bits (Pg. 227)
RCC->PLLCFGR |= (pll_q_divisor << RCC_PLLCFGR_PLLQ_Pos) & RCC_PLLCFGR_PLLQ_Msk;

__DSB(); // Wait for explicit memory accesses to finish

Expand Down
Loading

0 comments on commit 5ff2e93

Please sign in to comment.