Skip to content

Commit

Permalink
wip main: fixed large amount of DMA data transfer. code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
thegabriele97 committed Dec 20, 2021
1 parent 1ada0a3 commit 56122ca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 30 deletions.
4 changes: 3 additions & 1 deletion serialInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import serial
from sys import argv
from datetime import datetime
import time

if __name__ == "__main__":
ser = serial.Serial(port= argv[1], baudrate=argv[2])
Expand All @@ -13,7 +14,8 @@
entry = ser.read(5)

totb = 0
while 1:
time.sleep(1)
while ser.inWaiting() > 5:
entry = ser.read(6)
totb += 6
# print(entry.hex())
Expand Down
12 changes: 3 additions & 9 deletions src/comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ static uint8_t buf[0x20];
static uint8_t send_etx = 0;
static uint8_t buf_cnt = 0;
static volatile uint32_t setValue = 0;
static uint32_t rem;

static void txCpltCback(UART_HandleTypeDef *huart) {
static uint8_t ts;

if (send_etx > 1) {
send_etx--;
rem = phcomm->SrcMemory.size - 0x400;
ts = rem <= 0x400 ? 1 : (rem / 0x400 + 1);
GAL_UART_Transmit_DMA(phcomm->SrcMemory.basePtr, ts == 1 ? rem : 0x400);
GAL_UART_Transmit_DMA(phcomm->SrcMemory.basePtr, send_etx == 1 ? phcomm->SrcMemory.size : 0xffff);
} else if (send_etx == 1) {
INVOKE_CB(phcomm->Callback.onUARTDownload, true);
buf[0] = '\n';
Expand Down Expand Up @@ -103,10 +99,8 @@ static void rxCpltCback(UART_HandleTypeDef *huart) {
INVOKE_CB(phcomm->Callback.onUARTDownload, false);
GAL_UART_Transmit(buf + buf_cnt + 1, 1);

send_etx = phcomm->SrcMemory.size <= 0x400 ? 1 : (phcomm->SrcMemory.size / 0x400 + 1);
rem = phcomm->SrcMemory.size - 0x400;
// send_etx = phcomm->SrcMemory.size / 0x400;
GAL_UART_Transmit_DMA(phcomm->SrcMemory.basePtr, send_etx == 1 ? phcomm->SrcMemory.size : 0x400);
send_etx = (phcomm->SrcMemory.size >> 16) + 1;
GAL_UART_Transmit_DMA(phcomm->SrcMemory.basePtr, send_etx == 1 ? phcomm->SrcMemory.size : 0xffff);
len = -2;
}

Expand Down
20 changes: 0 additions & 20 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@

// Static reference for I2C
static I2C_HandleTypeDef hi2c1;
static UART_HandleTypeDef huart1;
static RTC_HandleTypeDef hrtc;

void SystemClock_Config(void);
static void MX_I2C1_Init(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_RTC_Init(void);
static void update_interface();
static void disable_IRQ();
Expand All @@ -38,7 +36,6 @@ static RTC_TimeTypeDef gTime;
static struct COMM_Handle hcomm;

int main(void) {
uint8_t datestamp[23];

SystemInit();
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
Expand All @@ -48,10 +45,7 @@ int main(void) {
MX_GPIO_Init();
// Setup I2C
MX_I2C1_Init();
// MX_USART1_UART_Init(); // TODO: to remove
MX_RTC_Init();
// log_rtc_setup(&hrtc, &gTime, &gDate, "20/12/2021 16/04/00");


// Initilization of the counters
number_people = 0;
Expand Down Expand Up @@ -138,20 +132,6 @@ ONUART_DOWNLOAD_CB(onUartDownload, xferDone) {
}
}

static void MX_USART1_UART_Init(void) {
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK) {
Error_Handler();
}
}

static void MX_I2C1_Init(void) {
hi2c1.Instance = I2C1;
hi2c1.Init.ClockSpeed = 100000;
Expand Down

0 comments on commit 56122ca

Please sign in to comment.