1
0
forked from me/IronOS

Pinecil uart (#830)

* Creating uart debug handler

* Simpler get raw uV tip

* Update Setup.cpp

* Debug out working. Moved Logo

Need to update docs around logos before merging this in

* Add in current pwm level + fix signed int

* Update moving logo page for pinecil by 64k

* Update TipThermoModel.h
This commit is contained in:
Ben V. Brown
2021-02-02 19:53:19 +11:00
committed by GitHub
parent 15e51f9faa
commit 1f6a3ad167
17 changed files with 136 additions and 17 deletions

View File

@@ -71,6 +71,9 @@ int16_t getRawHallEffect();
// Returns true if power is from dumb "DC" input rather than "smart" QC or PD
bool getIsPoweredByDCIN();
// Logs the system state to a debug interface if supported
void log_system_state(int32_t PWMWattsx10);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,47 @@
/*
* Debug.cpp
*
* Created on: 26 Jan. 2021
* Author: Ralim
*/
#include "Debug.h"
#include "Pins.h"
extern "C" {
#include "gd32vf103_usart.h"
}
char uartOutputBuffer[uartOutputBufferLength];
volatile uint32_t currentOutputPos = 0xFF;
volatile uint32_t outputLength = 0;
extern volatile uint8_t pendingPWM;
void log_system_state(int32_t PWMWattsx10) {
if (currentOutputPos == 0xFF) {
// Want to print a CSV log out the uart
// Tip_Temp_C,Handle_Temp_C,Output_Power_Wattx10,PWM,Tip_Raw\r\n
// 3+1+3+1+3+1+3+1+5+2 = 23, so sizing at 32 for now
outputLength = snprintf(uartOutputBuffer, uartOutputBufferLength, "%lu,%u,%li,%u,%lu\r\n", //
TipThermoModel::getTipInC(false), // Tip temp in C
getHandleTemperature(), // Handle temp in C X10
PWMWattsx10, // Output Wattage
pendingPWM, // PWM
TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true) // Tip temp in uV
);
// Now print this out the uart via IRQ (DMA cant be used as oled has it)
currentOutputPos = 0;
/* enable USART1 Transmit Buffer Empty interrupt */
usart_interrupt_enable(UART_PERIF, USART_INT_TBE);
}
}
void USART1_IRQHandler(void) {
if (RESET != usart_interrupt_flag_get(UART_PERIF, USART_INT_FLAG_TBE)) {
/* write one byte to the transmit data register */
usart_data_transmit(UART_PERIF, uartOutputBuffer[currentOutputPos++]);
if (currentOutputPos >= outputLength) {
currentOutputPos = 0xFF; // Mark done
usart_interrupt_disable(UART_PERIF, USART_INT_TBE);
}
}
}

View File

@@ -0,0 +1,22 @@
/*
* Debug.h
*
* Created on: 26 Jan. 2021
* Author: Ralim
*/
#ifndef CORE_BSP_PINE64_DEBUG_H_
#define CORE_BSP_PINE64_DEBUG_H_
#include "BSP.h"
#include "TipThermoModel.h"
#include <stdio.h>
#include <string.h>
const unsigned int uartOutputBufferLength = 32;
extern char uartOutputBuffer[uartOutputBufferLength];
extern "C" {
void USART1_IRQHandler(void);
}
#endif /* CORE_BSP_PINE64_DEBUG_H_ */

View File

@@ -27,6 +27,7 @@
#define HALL_SENSOR
#define HALL_SI7210
#define BATTFILTERDEPTH 32
#define DEBUG_UART_OUTPUT
#endif
#endif /* BSP_PINE64_MODEL_CONFIG_H_ */

View File

@@ -50,4 +50,11 @@
#define FUSB302_IRQ_Pin BIT(5)
#define FUSB302_IRQ_GPIO_Port GPIOB
// uart
#define UART_TX_Pin BIT(2)
#define UART_TX_GPIO_Port GPIOA
#define UART_RX_Pin BIT(3)
#define UART_RX_GPIO_Port GPIOA
#define UART_PERIF USART1
#endif /* BSP_PINE64_PINS_H_ */

View File

@@ -6,6 +6,7 @@
*/
#include "Setup.h"
#include "BSP.h"
#include "Debug.h"
#include "Pins.h"
#include "gd32vf103.h"
#include <string.h>
@@ -20,6 +21,7 @@ void setup_i2c();
void setup_adc();
void setup_timers();
void setup_iwdg();
void setup_uart();
void hardware_init() {
// GPIO
@@ -35,6 +37,8 @@ void hardware_init() {
// Watchdog
setup_iwdg();
// uart for debugging
setup_uart();
/* enable TIMER1 - PWM control timing*/
timer_enable(TIMER1);
timer_enable(TIMER2);
@@ -47,6 +51,32 @@ uint16_t getADC(uint8_t channel) {
return sum >> 2;
}
void setup_uart() {
// Setup the uart pins as a uart with dma
/* enable USART clock */
rcu_periph_clock_enable(RCU_USART1);
/* connect port to USARTx_Tx */
gpio_init(UART_TX_GPIO_Port, GPIO_MODE_AF_PP, GPIO_OSPEED_10MHZ, UART_TX_Pin);
/* connect port to USARTx_Rx */
gpio_init(UART_RX_GPIO_Port, GPIO_MODE_IPU, GPIO_OSPEED_10MHZ, UART_RX_Pin);
/* USART configure */
usart_deinit(UART_PERIF);
usart_baudrate_set(UART_PERIF, 2 * 1000 * 1000U);
usart_word_length_set(UART_PERIF, USART_WL_8BIT);
usart_stop_bit_set(UART_PERIF, USART_STB_1BIT);
usart_parity_config(UART_PERIF, USART_PM_NONE);
usart_hardware_flow_rts_config(UART_PERIF, USART_RTS_DISABLE);
usart_hardware_flow_cts_config(UART_PERIF, USART_CTS_DISABLE);
usart_receive_config(UART_PERIF, USART_RECEIVE_DISABLE); // Dont use rx for now
usart_transmit_config(UART_PERIF, USART_TRANSMIT_ENABLE);
eclic_irq_enable(USART1_IRQn, 15, 15);
usart_enable(UART_PERIF);
}
void setup_gpio() {
/* enable GPIOB clock */
rcu_periph_clock_enable(RCU_GPIOA);

View File

@@ -32,7 +32,7 @@ OUTPUT_ARCH( "riscv" )
* </h>
*/
__ROM_BASE = 0x08000000;
__ROM_SIZE = 0x00020000;
__ROM_SIZE = 0x0001F400;
/*--------------------- ILM RAM Configuration ---------------------------
* <h> ILM RAM Configuration

View File

@@ -38,7 +38,9 @@ OF SUCH DAMAGE.
#include "gd32vf103.h"
#include "gd32vf103_dbg.h"
#include "gd32vf103_rcu.h"
#ifdef _cplusplus
extern "C" {
#endif
/* DMA definitions */
#define DMA0 (DMA_BASE) /*!< DMA0 base address */
#define DMA1 (DMA_BASE + 0x0400U) /*!< DMA1 base address */
@@ -277,5 +279,8 @@ void dma_interrupt_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, ui
void dma_interrupt_enable(uint32_t dma_periph, dma_channel_enum channelx, uint32_t source);
/* disable DMA interrupt */
void dma_interrupt_disable(uint32_t dma_periph, dma_channel_enum channelx, uint32_t source);
#ifdef _cplusplus
}
#endif
#endif /* GD32VF103_DMA_H */

View File

@@ -38,6 +38,9 @@ OF SUCH DAMAGE.
#include "gd32vf103.h"
#include "gd32vf103_dbg.h"
#include "gd32vf103_rcu.h"
#ifdef _cplusplus
extern "C" {
#endif
/* USARTx(x=0,1,2)/UARTx(x=3,4) definitions */
#define USART1 USART_BASE /*!< USART1 base address */
@@ -371,4 +374,8 @@ FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, uint32_t int_flag);
void usart_interrupt_flag_clear(uint32_t usart_periph, uint32_t flag);
int usart_write(uint32_t usart_periph, int ch);
uint8_t usart_read(uint32_t usart_periph);
#ifdef _cplusplus
}
#endif
#endif /* GD32VF103_USART_H */

View File

@@ -8,7 +8,7 @@
#include "BSP.h"
#include "OLED.hpp"
// Second last page of flash set aside for logo image.
#define FLASH_LOGOADDR (0x8000000 | 0xF800)
#define FLASH_LOGOADDR (0x08000000 + (126 * 1024))
// Logo header signature.
#define LOGO_HEADER_VALUE 0xF00DAA55