implemented write syscall for printf, added float-support for printf, serial tx does not need an interrupt anymore, replaced consoleLog and consoleScope with printf, changed debug output: every comment starts with "# " now, added lots of debug messages, added welcome message with gcc version and build date
parent
ad8c2a552a
commit
c57e1a0e4e
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the hoverboard-firmware-hack project.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2017-2018 Rene Hopf <renehopf@mac.com>
|
|
||||||
* Copyright (C) 2017-2018 Nico Stute <crinq@crinq.de>
|
|
||||||
* Copyright (C) 2017-2018 Niklas Fauth <niklas.fauth@kit.fail>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Define to prevent recursive inclusion
|
|
||||||
#ifndef COMMS_H
|
|
||||||
#define COMMS_H
|
|
||||||
|
|
||||||
#include "stm32f1xx_hal.h"
|
|
||||||
|
|
||||||
void setScopeChannel(uint8_t ch, int16_t val);
|
|
||||||
void consoleScope(void);
|
|
||||||
void consoleLog(char *message);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@ -1,81 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "stm32f1xx_hal.h"
|
|
||||||
#include "defines.h"
|
|
||||||
#include "setup.h"
|
|
||||||
#include "config.h"
|
|
||||||
#include "comms.h"
|
|
||||||
|
|
||||||
extern UART_HandleTypeDef huart2;
|
|
||||||
extern UART_HandleTypeDef huart3;
|
|
||||||
|
|
||||||
static volatile uint8_t uart_buf[100];
|
|
||||||
static volatile int16_t ch_buf[8];
|
|
||||||
//volatile char char_buf[300];
|
|
||||||
|
|
||||||
void setScopeChannel(uint8_t ch, int16_t val) {
|
|
||||||
ch_buf[ch] = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
void consoleScope(void) {
|
|
||||||
#if defined DEBUG_SERIAL_SERVOTERM && (defined DEBUG_SERIAL_USART2 || defined DEBUG_SERIAL_USART3)
|
|
||||||
uart_buf[0] = 0xff;
|
|
||||||
uart_buf[1] = CLAMP(ch_buf[0]+127, 0, 255);
|
|
||||||
uart_buf[2] = CLAMP(ch_buf[1]+127, 0, 255);
|
|
||||||
uart_buf[3] = CLAMP(ch_buf[2]+127, 0, 255);
|
|
||||||
uart_buf[4] = CLAMP(ch_buf[3]+127, 0, 255);
|
|
||||||
uart_buf[5] = CLAMP(ch_buf[4]+127, 0, 255);
|
|
||||||
uart_buf[6] = CLAMP(ch_buf[5]+127, 0, 255);
|
|
||||||
uart_buf[7] = CLAMP(ch_buf[6]+127, 0, 255);
|
|
||||||
uart_buf[8] = CLAMP(ch_buf[7]+127, 0, 255);
|
|
||||||
uart_buf[9] = '\n';
|
|
||||||
|
|
||||||
#ifdef DEBUG_SERIAL_USART2
|
|
||||||
if(__HAL_DMA_GET_COUNTER(huart2.hdmatx) == 0) {
|
|
||||||
HAL_UART_Transmit_DMA(&huart2, (uint8_t *)uart_buf, strLength);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#ifdef DEBUG_SERIAL_USART3
|
|
||||||
if(__HAL_DMA_GET_COUNTER(huart3.hdmatx) == 0) {
|
|
||||||
HAL_UART_Transmit_DMA(&huart3, (uint8_t *)uart_buf, strLength);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined DEBUG_SERIAL_ASCII && (defined DEBUG_SERIAL_USART2 || defined DEBUG_SERIAL_USART3)
|
|
||||||
// memset((void *)(uintptr_t)uart_buf, 0, sizeof(uart_buf));
|
|
||||||
int strLength;
|
|
||||||
strLength = sprintf((char *)(uintptr_t)uart_buf,
|
|
||||||
"1:%i 2:%i 3:%i 4:%i 5:%i 6:%i 7:%i 8:%i\r\n",
|
|
||||||
ch_buf[0], ch_buf[1], ch_buf[2], ch_buf[3], ch_buf[4], ch_buf[5], ch_buf[6], ch_buf[7]);
|
|
||||||
|
|
||||||
#ifdef DEBUG_SERIAL_USART2
|
|
||||||
if(__HAL_DMA_GET_COUNTER(huart2.hdmatx) == 0) {
|
|
||||||
HAL_UART_Transmit_DMA(&huart2, (uint8_t *)uart_buf, strLength);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#ifdef DEBUG_SERIAL_USART3
|
|
||||||
if(__HAL_DMA_GET_COUNTER(huart3.hdmatx) == 0) {
|
|
||||||
HAL_UART_Transmit_DMA(&huart3, (uint8_t *)uart_buf, strLength);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void consoleLog(char *message)
|
|
||||||
{
|
|
||||||
#if defined DEBUG_SERIAL_ASCII && (defined DEBUG_SERIAL_USART2 || defined DEBUG_SERIAL_USART3)
|
|
||||||
#ifdef DEBUG_SERIAL_USART2
|
|
||||||
if(__HAL_DMA_GET_COUNTER(huart2.hdmatx) == 0) {
|
|
||||||
HAL_UART_Transmit_DMA(&huart2, (uint8_t *)message, strlen((char *)(uintptr_t)message));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#ifdef DEBUG_SERIAL_USART3
|
|
||||||
if(__HAL_DMA_GET_COUNTER(huart3.hdmatx) == 0) {
|
|
||||||
HAL_UART_Transmit_DMA(&huart3, (uint8_t *)message, strlen((char *)(uintptr_t)message));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
#include <reent.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "stm32f1xx_hal.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
extern volatile uint8_t uart_buf[200];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* printf sends its output to this function, this function sends it to the uart dma output buffer
|
||||||
|
*/
|
||||||
|
__attribute__((__used__)) int _write(int fd, const char *ptr, int len){
|
||||||
|
#if defined DEBUG_SERIAL_ASCII && (defined DEBUG_SERIAL_USART2 || defined DEBUG_SERIAL_USART3)
|
||||||
|
#ifdef DEBUG_SERIAL_USART2
|
||||||
|
while(DMA1_Channel7->CNDTR != 0); // wait
|
||||||
|
memcpy(uart_buf,ptr,len); // copy to buffer
|
||||||
|
DMA1_Channel7->CCR &= ~DMA_CCR_EN;
|
||||||
|
DMA1_Channel7->CNDTR = len; // set number of bytes to read
|
||||||
|
DMA1_Channel7->CMAR = (uint32_t)uart_buf; // set buffer to read from
|
||||||
|
DMA1_Channel7->CCR |= DMA_CCR_EN;
|
||||||
|
#endif
|
||||||
|
#ifdef DEBUG_SERIAL_USART3
|
||||||
|
while(DMA1_Channel2->CNDTR != 0); // wait
|
||||||
|
memcpy(uart_buf,ptr,len); // copy to buffer
|
||||||
|
DMA1_Channel2->CCR &= ~DMA_CCR_EN;
|
||||||
|
DMA1_Channel2->CNDTR = len; // set number of bytes to read
|
||||||
|
DMA1_Channel2->CMAR = (uint32_t)uart_buf; // set buffer to read from
|
||||||
|
DMA1_Channel2->CCR |= DMA_CCR_EN;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
return len;
|
||||||
|
}
|
||||||
Loading…
Reference in new issue