Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
3c0e0cc
add firmware to propogate sync signal
mohamed-dek1 Mar 11, 2026
bf488ed
add first attempt at implementing queue
mohamed-dek1 Mar 11, 2026
617b21d
add new partial DMA implementation
mohamed-dek1 Mar 12, 2026
8a08789
add all code for dma useage
mohamed-dek1 Mar 13, 2026
ee54329
add currently working daisy chain firmware
mohamed-dek1 Mar 18, 2026
98303b5
add transmit firmware for channels 97 through 9B
mohamed-dek1 Mar 24, 2026
becf30a
add current transmit implementation
mohamed-dek1 Mar 27, 2026
bad7012
add queue and buffers for uart2 and 3
mohamed-dek1 Mar 27, 2026
e7e1201
add immediate transmit in adc.c
mohamed-dek1 Apr 3, 2026
65e6e41
add none dma transfer of sampled data
mohamed-dek1 Apr 5, 2026
0e58045
add updated process singly byte function
mohamed-dek1 Apr 5, 2026
824bb43
add more changes to the tranmission firmware
mohamed-dek1 Apr 7, 2026
e1c0630
add ifs between transmission
mohamed-dek1 Apr 10, 2026
ec6dca6
add boolean for second if
mohamed-dek1 Apr 10, 2026
8744f6d
add fastest version of personal data transmit
mohamed-dek1 Apr 10, 2026
8b208ae
remove FE
mohamed-dek1 Apr 10, 2026
275b668
turn process single byte into static inline
mohamed-dek1 Apr 14, 2026
2a126aa
remove process_routing from main and place after interrupt
mohamed-dek1 Apr 15, 2026
9d5b3e5
add synchronous single byte function
mohamed-dek1 Apr 16, 2026
7e08bf4
remove state machine
mohamed-dek1 Apr 17, 2026
df568e7
Optimize DMA routing time for ST MCU
elsevers Apr 18, 2026
5760dba
swap toggle and reset lines
mohamed-dek1 Apr 20, 2026
bc9c05e
Merge pull request #107 from Severson-Group/user/elsevers/optimize-ro…
mohamed-dek1 Apr 20, 2026
8568428
Optimize process_routing
elsevers Apr 20, 2026
07e7e44
Restore helpful comments
elsevers Apr 20, 2026
c73b9aa
Refactor UART dual-stream and single-stream processing
elsevers Apr 20, 2026
0a76fb4
add initial changes to syncing fbc and amds firmware
mohamed-dek1 Apr 21, 2026
6ad38e8
Update header file for benchmark code
elsevers Apr 21, 2026
646a62a
Add benchmarking code to the two adc and uart driver
elsevers Apr 21, 2026
f66c75b
add faster initial transmit
mohamed-dek1 Apr 21, 2026
afcbc5f
Optimize the send data in the ext irq function
elsevers Apr 21, 2026
9745611
Go back to using loops for IRQ handler
elsevers Apr 21, 2026
8deab07
remove benchmark flag
mohamed-dek1 Apr 21, 2026
9025979
Merge branch 'feature/dcp-amds-firmware-improved-transmit' into user/…
mohamed-dek1 Apr 21, 2026
73c1051
Merge pull request #108 from Severson-Group/user/elsevers/optimize-ro…
elsevers Apr 21, 2026
19e56c8
Merge pull request #106 from Severson-Group/feature/dcp-amds-firmware…
elsevers Apr 21, 2026
dc7626b
Merge branch 'feature/dcp-amds-firmware' into feature/dcp-amds-firmwa…
mohamed-dek1 Apr 21, 2026
399b6a7
add the rest of uart6 and 1 implementation
mohamed-dek1 Apr 21, 2026
ea7813e
fix daisy chain transmit function
mohamed-dek1 Apr 21, 2026
c7a1640
Make main only use process_routing when data is available
elsevers Apr 23, 2026
8cf05d5
add conditionals and custom build config
mohamed-dek1 Apr 23, 2026
03315fb
switch back to debug build config
mohamed-dek1 Apr 24, 2026
2db129a
Make main only use process_routing when data is available (#113)
mohamed-dek1 Apr 24, 2026
16ea7a9
add conditional process in main
mohamed-dek1 Apr 24, 2026
cabe28d
Merge branch 'feature/dcp-amds-firmware' into feature/dcp-amds-firmwa…
mohamed-dek1 Apr 24, 2026
71e9c2c
add more conditional defines
mohamed-dek1 Apr 24, 2026
3f54153
add new build configs to gitignore
mohamed-dek1 Apr 24, 2026
01ac644
remove conditional from default configuration
mohamed-dek1 Apr 24, 2026
8ce8032
add interleaved transmit function and modified irq handler
mohamed-dek1 Apr 24, 2026
99bf81e
enable counter
mohamed-dek1 Apr 24, 2026
c14bc13
Merge pull request #110 from Severson-Group/feature/dcp-amds-firmware…
mohamed-dek1 Apr 24, 2026
8cfb676
comment certain sections in order to get a baseline
mohamed-dek1 Apr 24, 2026
9511f46
add firmware used to get a benchmark
mohamed-dek1 Apr 27, 2026
414d644
move header transmit to avoid timeout
mohamed-dek1 Apr 27, 2026
d939be5
remove uneccasry counter firmware'
mohamed-dek1 Apr 27, 2026
e4cf2f5
remove second wait state
mohamed-dek1 Apr 28, 2026
53b62d7
add reset to sample-transmit function
mohamed-dek1 Apr 28, 2026
b345641
add more profiling code
mohamed-dek1 Apr 28, 2026
63b3d2c
add bad modified sample-transmit
mohamed-dek1 Apr 29, 2026
c9be271
add cleaned up version of sample-transmit function
mohamed-dek1 Apr 29, 2026
ba4e273
add benchmark code to I3 handler
mohamed-dek1 Apr 29, 2026
b479358
Merge branch 'feature/dcp-amds-firmware' into feature/dcp-amds-firmwa…
mohamed-dek1 Apr 29, 2026
804a807
add interleaved transmit for FBC
mohamed-dek1 Apr 29, 2026
5951f32
update active mask comment to be accurate
mohamed-dek1 Apr 29, 2026
cedddda
update I15_10 interrupt handler to actually use the fast path sample-…
mohamed-dek1 Apr 29, 2026
b2ef876
Merge pull request #116 from Severson-Group/feature/dcp-amds-firmware…
mohamed-dek1 Apr 30, 2026
207d8d3
cleanup comments and remove old and unused code
mohamed-dek1 Apr 30, 2026
86b9cf8
Merge pull request #119 from Severson-Group/feature/dcp-amds-firmware…
mohamed-dek1 May 1, 2026
4b66c69
add delays to transmission
mohamed-dek1 May 5, 2026
d9d065b
add docs changes to readme
mohamed-dek1 May 5, 2026
264615f
add debugging logic and delays
mohamed-dek1 May 6, 2026
de9a3ce
replace delays with timeouts
mohamed-dek1 May 6, 2026
e3584b4
add conditional to handler and switch led control in main
mohamed-dek1 May 6, 2026
8aa489d
cleanup the code
mohamed-dek1 May 6, 2026
161bdd5
add more debugging logic
mohamed-dek1 May 7, 2026
2356cc2
fix indexing for timeout conditions
mohamed-dek1 May 8, 2026
dc23745
add more debugging logic
mohamed-dek1 May 8, 2026
4bfae7b
add logic for testing with AMDS
mohamed-dek1 May 11, 2026
82dcef9
reduce baudrate to 20Mbps
mohamed-dek1 May 12, 2026
6fd24a0
clean up code to get a baseline for the FBC
mohamed-dek1 May 12, 2026
e83dc37
clean up code to prepare for release
mohamed-dek1 May 12, 2026
3edd4b4
Merge pull request #122 from Severson-Group/feature/dcp-amds-firmware…
mohamed-dek1 May 13, 2026
c4bb429
rename motherboard_v1 project and files and mainboard
mohamed-dek1 May 13, 2026
c66ad62
Merge pull request #124 from Severson-Group/feature/dcp-amds-firmware…
mohamed-dek1 May 13, 2026
818233e
Enhance comments on DMA data handling
elsevers May 17, 2026
380d370
Merge remote-tracking branch 'origin/develop' into feature/dcp-amds-f…
Jun 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions Mainboard/Firmware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,20 @@ This tool is analogous to the Xilinx SDK tool (for the AMDC). It is effectively

To develop code for STM32 processors:

#### Generating New Projects
### Testing / Debugging Code

1. Use the STM32CubeIDE to generate a new project
2. When configuring this project, select the exact MCU device which you are targetting (the mainboard uses `STM32F765ZGT6`)
3. Open the CubeMX perspective (i.e. `*.ioc` file) and configure all desired peripherals (SPIs, UARTs, ETH, etc)
4. Change to the clock configuration tab and use the GUI to configure the PLL settings
5. Generate initialization code to boot-strap your project. This will configure the clock and peripherals like you specified.
1. Use the IDE to compile your code and ensure there are no errors.
2. To flash the hardware, plug in a SWD debugger device to your PC + board (highly recommend [`STLINK-V3SET`](https://www.digikey.com/product-detail/en/stmicroelectronics/STLINK-V3SET/497-18216-ND/9636028))
3. Configure a debug session in the IDE
4. Run the debug sessions. This will flash the MCU and start the code (probably breakpoint at `main()`)

#### Writing Code

6. Now that you have a base project, write all your application-specific code...

#### Testing / Debugging Code

7. Use the IDE to compile your code and ensure there are no errors.
8. To flash the hardware, plug in a SWD debugger device to your PC + board (highly recommend [`STLINK-V3SET`](https://www.digikey.com/product-detail/en/stmicroelectronics/STLINK-V3SET/497-18216-ND/9636028))
9. Configure a debug session in the IDE
10. Run the debug sessions. This will flash the MCU and start the code (probably breakpoint at `main()`)
For more detailed instructions on programming the AMDS, please refer to the [AMDS Documentation](https://docs.amdc.dev/accessories/amds/index.html).

NOTE: The STM32 devices are typically programmed into non-volatile memory. Therefore, there is no seperate "flashing" step. Every time you upload code, it is permanantely stored on the processor. You can power cycle the device and your code will start running again.

## Mainboard Firmware Design

The mainboard firmware is fairly simple, yet very specialized for the application. Before changing *anything* in the code, make sure you understand how it works. Practically every line of the code is optimized for speed and efficiency! Using a multi-channel logic analyzer / oscilloscope is absolutely required when updating the mainboard firmware to validate code timing.
The mainboard firmware is fairly simple, yet very specialized for the application. Before changing *anything* in the code, make sure you understand how it works. Practically every line of the code is optimized for speed and efficiency! Using a multi-channel logic analyzer / oscilloscope is absolutely required when updating the mainboard firmware to validate code timing. Please refer to the [Firmware Architecture Documentation](https://docs.amdc.dev/accessories/amds/firmware/index.html) for more information.

**Do not blindly change the code.**

Expand Down
379 changes: 379 additions & 0 deletions Mainboard/Firmware/mainboard/.cproject

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.settings/language.settings.xml
Debug/
Release/
AMDS/
2S/
scripts/__pycache__/
*.o
*.d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ CDefines=USE_HAL_DRIVER;STM32F765xx;USE_HAL_DRIVER;USE_HAL_DRIVER;
[PreviousGenFiles]
AdvancedFolderStructure=true
HeaderFileListSize=7
HeaderFiles#0=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Inc/gpio.h
HeaderFiles#1=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Inc/i2c.h
HeaderFiles#2=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Inc/spi.h
HeaderFiles#3=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Inc/usart.h
HeaderFiles#4=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Inc/stm32f7xx_it.h
HeaderFiles#5=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Inc/stm32f7xx_hal_conf.h
HeaderFiles#6=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Inc/main.h
HeaderFiles#0=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Inc/gpio.h
HeaderFiles#1=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Inc/i2c.h
HeaderFiles#2=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Inc/spi.h
HeaderFiles#3=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Inc/usart.h
HeaderFiles#4=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Inc/stm32f7xx_it.h
HeaderFiles#5=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Inc/stm32f7xx_hal_conf.h
HeaderFiles#6=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Inc/main.h
HeaderFolderListSize=1
HeaderPath#0=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Inc
HeaderPath#0=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Inc
HeaderFiles=;
SourceFileListSize=7
SourceFiles#0=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Src/gpio.c
SourceFiles#1=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Src/i2c.c
SourceFiles#2=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Src/spi.c
SourceFiles#3=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Src/usart.c
SourceFiles#4=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Src/stm32f7xx_it.c
SourceFiles#5=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Src/stm32f7xx_hal_msp.c
SourceFiles#6=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Src/main.c
SourceFiles#0=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Src/gpio.c
SourceFiles#1=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Src/i2c.c
SourceFiles#2=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Src/spi.c
SourceFiles#3=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Src/usart.c
SourceFiles#4=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Src/stm32f7xx_it.c
SourceFiles#5=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Src/stm32f7xx_hal_msp.c
SourceFiles#6=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Src/main.c
SourceFolderListSize=1
SourcePath#0=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/motherboard_v1/Core/Src
SourcePath#0=C:/Users/npetersen2/STM32CubeIDE/workspace_1.3.0/mainboard/Core/Src
SourceFiles=;

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>motherboard_v1</name>
<name>mainboard</name>
<comment></comment>
<projects>
</projects>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
sfrviewstate={"fFavorites"\:{"fLists"\:{}},"fProperties"\:{"fNodeProperties"\:{}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
2F62501ED4689FB349E356AB974DBE57=DB4D67F16CA069769A3F87733D593AF2
8DF89ED150041C4CBC7CB9A9CAA90856=DB4D67F16CA069769A3F87733D593AF2
DC22A860405A8BF2F2C095E5B6529F12=D1E96F3EE32E2AB2CF91940507FB3624
eclipse.preferences.version=1
9 changes: 9 additions & 0 deletions Mainboard/Firmware/mainboard/Core/Inc/adc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef ADC_H
#define ADC_H

#include <stdint.h>

void adc_init(void);


#endif // ADC_H
151 changes: 151 additions & 0 deletions Mainboard/Firmware/mainboard/Core/Inc/drv_uart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#ifndef DRV_UART_H
#define DRV_UART_H

// BENCHMARK MODE FLAG for DMA
//#define BENCHMARK_MODE

#include "platform.h"
#include <stdint.h>
#include <stdbool.h>

void drv_uart_init(void);

extern UART_HandleTypeDef huart2;
extern UART_HandleTypeDef huart3;

extern UART_HandleTypeDef DAISY_RX1_UART;
extern UART_HandleTypeDef DAISY_RX2_UART;

extern DMA_HandleTypeDef hdma_uart4_rx;
extern DMA_HandleTypeDef hdma_uart5_rx;

extern DMA_HandleTypeDef hdma_uart6_rx;
extern DMA_HandleTypeDef hdma_uart1_rx;

typedef enum {
STATE_IDLE,
STATE_GOT_HEADER,
STATE_GOT_MSB
} rx_state_t;

typedef struct {
rx_state_t state;
uint8_t header;
uint8_t data[2];
uint8_t read_index;
} uart_rx_tracker_t;

extern uart_rx_tracker_t tracker1;
extern uart_rx_tracker_t tracker2;

#define AMDS_RX_BUF_SIZE 256 // Must be 256 for uint8_t indexing and wrap-around logic to work correctly
extern uint8_t DAISY_RX1_Pool[AMDS_RX_BUF_SIZE];
extern uint8_t DAISY_RX2_Pool[AMDS_RX_BUF_SIZE];

#ifdef BENCHMARK_MODE
extern volatile uint8_t mock_dma_write_head;
#endif

// Declare the global flag so all .c files know it exists
extern volatile bool is_routing_active;

bool drv_uart_has_dma_data(void);

#define GPIO_TOGGLE_PIN(port, pin) ((port)->BSRR = ((port)->ODR & (pin)) ? ((pin) << 16) : (pin))

void process_routing(void);

/**
* Thread-safe, non-blocking wrapper for process_routing().
* Uses an atomic try-lock to prevent reentrancy without
* stalling the CPU or blinding interrupts for too long.
*/
static inline void try_process_routing(void) {
// 1. Enter brief critical section (approx. 3 CPU cycles)
__disable_irq();

// 2. Check if the lock is already claimed
if (is_routing_active) {
// Someone else is already routing. Safely abort.
__enable_irq();
return;
}

// 3. Claim the lock
is_routing_active = true;

// 4. Exit critical section BEFORE the heavy lifting
__enable_irq();

// 5. Perform the actual routing with interrupts perfectly active
process_routing();

// 6. Release the lock when finished
// (This single write is inherently atomic on a 32-bit ARM core,
// so we don't need to disable interrupts just to clear it).
is_routing_active = false;
}

/**
* Attempt to instantly reset the routing state machine and flush buffers.
* To be called ONLY from the very beginning of EXTI3_IRQHandler.
*/
static inline void try_reset_routing_state(void) {
// Because we are inside an IRQ, we preempted main().
// We do NOT need to disable interrupts here to check the flag safely.
if (!is_routing_active) {

// 1. Reset state machines to gracefully await the next packet
tracker1.state = STATE_IDLE;
tracker2.state = STATE_IDLE;

// 2. Soft-flush the DMA buffers.
// We advance our read pointers to exactly where the DMA hardware
// is currently writing. All old, unprocessed bytes are instantly discarded.
#ifdef BENCHMARK_MODE
tracker1.read_index = mock_dma_write_head;
tracker2.read_index = mock_dma_write_head;
#else
tracker1.read_index = (uint8_t)(AMDS_RX_BUF_SIZE - __HAL_DMA_GET_COUNTER(DAISY_RX1_UART.hdmarx));
tracker2.read_index = (uint8_t)(AMDS_RX_BUF_SIZE - __HAL_DMA_GET_COUNTER(DAISY_RX2_UART.hdmarx));
#endif
}
}

static inline void drv_uart_putc_fast(USART_TypeDef *uart, uint8_t data)
{
// Wait until UART is ready to accept next character
while (!(uart->ISR & UART_FLAG_TXE)) {
asm("nop");
}

// Load the TDR register to send a character
uart->TDR = data;
}

static inline void drv_uart_wait_TC(USART_TypeDef *uart)
{
// ONLY USE THIS IF DISABLING THE UART OR GOING TO SLEEP!
// This function waits for all data to be sent from the USART
// (it waits for both the TDR and the Shift Register to be
// completely empty)
//
// Do NOT USE THIS during normal continuous data transmission
// as it will add significant delays
while (!(uart->ISR & UART_FLAG_TC)) {
asm("nop");
}
}

static inline void drv_uart_send_fast(USART_TypeDef *uart, uint8_t *data, uint16_t len)
{
while (len > 0) {
drv_uart_putc_fast(uart, *data);
data++;
len--;
}

drv_uart_wait_TC(uart);
}

#endif // DRV_UART_H
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
#define USE_RTOS 0U
#define PREFETCH_ENABLE 0U
#define ART_ACCLERATOR_ENABLE 0U /* To enable instruction cache and prefetch */
#define USE_HAL_UART_REGISTER_CALLBACKS 1U /* UART register callback disabled */

/* ########################## Assert Selection ############################## */
/**
Expand Down
Loading
Loading