implemented fallback to physical usart and basis for wireless support in the future

This commit is contained in:
2018-03-23 18:54:25 +01:00
parent 1797f179b4
commit 102d5f5a4c
17 changed files with 513 additions and 49 deletions
+36
View File
@@ -7,6 +7,7 @@
#include "debug_uart.h"
#include "plat_compat.h"
#include "hw_utils.h"
#include "framework/system_settings.h"
#if USE_DEBUG_UART
@@ -52,18 +53,26 @@
#endif
static bool debug_uart_inited = false;
static bool debug_uart_preinited = false;
/** Init the submodule. */
void DebugUart_Init(void)
{
if (debug_uart_inited) return;
if (!debug_uart_preinited) DebugUart_PreInit();
// Debug UART
assert_param(E_SUCCESS == rsc_claim(&UNIT_SYSTEM, DEBUG_USART_RSC));
assert_param(E_SUCCESS == rsc_claim_pin(&UNIT_SYSTEM, DEBUG_USART_PORT, DEBUG_USART_PIN));
debug_uart_inited = true;
}
/** Init the hardware peripheral - this is called early in the boot process */
void DebugUart_PreInit(void)
{
debug_uart_preinited = true;
// configure AF only if platform uses AF numbers
#if !PLAT_NO_AFNUM
#pragma GCC diagnostic push
@@ -89,8 +98,35 @@ void DebugUart_PreInit(void)
LL_USART_Enable(DEBUG_USART);
}
void DebugUart_Teardown(void)
{
if (!debug_uart_inited) return;
dbg("Disabling debug UART!");
// TODO wait for Tx (after debug print DMA is implemented)
LL_USART_Disable(DEBUG_USART);
rsc_free(&UNIT_SYSTEM, DEBUG_USART_RSC);
hw_periph_clock_disable(DEBUG_USART);
bool suc = true;
Resource r = rsc_portpin2rsc(DEBUG_USART_PORT, DEBUG_USART_PIN, &suc);
rsc_free(&UNIT_SYSTEM, r);
hw_deinit_pin_rsc(r);
debug_uart_preinited = false;
debug_uart_inited = false;
assert_param(suc);
}
void debug_write(const char *buf, uint16_t len)
{
if (!SystemSettings.enable_debug_uart) return;
// TODO wait for DMA complete
// TODO use DMA
for (uint16_t i = 0; i < len; i++) {
while (!LL_USART_IsActiveFlag_TC(DEBUG_USART));
LL_USART_TransmitData8(DEBUG_USART, (uint8_t) *buf++);
+9 -1
View File
@@ -8,6 +8,8 @@
#ifndef GEX_DEBUG_UART_H
#define GEX_DEBUG_UART_H
#include "platform.h"
/**
* Pre-init the debug uart
*
@@ -17,7 +19,13 @@
void DebugUart_PreInit(void);
/**
* Finalize the init (claim resources)
* Release the peripheral and deinit pin
*/
void DebugUart_Teardown(void);
/**
* Finalize the init (claim resources).
* If not pre-inited (i.e. Teardown was called before), also pre-init.
*/
void DebugUart_Init(void);
+9 -4
View File
@@ -99,14 +99,19 @@ void hw_deinit_unit_pins(Unit *unit)
{
for (uint32_t rsc = R_PA0; rsc <= R_PF15; rsc++) {
if (RSC_IS_HELD(unit->resources, (Resource)rsc)) {
rsc_dbg("Freeing pin %s", rsc_get_name((Resource)rsc));
GPIO_TypeDef *port = GPIO_PERIPHS[(rsc-R_PA0) / 16];
uint32_t ll_pin = LL_GPIO_PINS[(rsc-R_PA0)%16];
LL_GPIO_SetPinMode(port, ll_pin, LL_GPIO_MODE_ANALOG);
hw_deinit_pin_rsc((Resource)rsc);
}
}
}
void hw_deinit_pin_rsc(Resource rsc)
{
rsc_dbg("Freeing pin %s", rsc_get_name((Resource)rsc));
GPIO_TypeDef *port = GPIO_PERIPHS[(rsc-R_PA0) / 16];
uint32_t ll_pin = LL_GPIO_PINS[(rsc-R_PA0)%16];
LL_GPIO_SetPinMode(port, ll_pin, LL_GPIO_MODE_ANALOG);
}
/** Configure a pin to alternate function */
error_t hw_configure_gpio_af(char port_name, uint8_t pin_num, uint32_t ll_af)
{
+2
View File
@@ -40,6 +40,8 @@ GPIO_TypeDef *hw_port2periph(char port_name, bool *suc);
*/
bool hw_pinrsc2ll(Resource rsc, GPIO_TypeDef **port, uint32_t *llpin) __attribute__((warn_unused_result));
void hw_deinit_pin_rsc(Resource rsc);
/**
* Spread packed port pins using a mask
*
+3 -3
View File
@@ -56,9 +56,9 @@
#define IWBUFFER_LEN 80 // Ini writer buffer for sprintf
// -------- Timeouts ------------
#define TF_PARSER_TIMEOUT_TICKS 300 // Timeout for receiving & parsing a frame
#define BULK_LST_TIMEOUT_MS 500 // timeout for the bulk transaction to expire
#define MSG_QUE_POST_TIMEOUT 100 // Time to post to the messages / jobs queue
#define TF_PARSER_TIMEOUT_TICKS 100 // Timeout for receiving & parsing a frame
#define BULK_LST_TIMEOUT_MS 2000 // timeout for the bulk transaction to expire
#define MSG_QUE_POST_TIMEOUT 200 // Time to post to the messages / jobs queue
// -------- Platform specific includes and defines ---------
+4 -1
View File
@@ -2,7 +2,6 @@
// Created by MightyPork on 2017/11/26.
//
#include <units/dac/unit_dac.h>
#include "platform.h"
#include "usbd_core.h"
#include "USB/usb_device.h"
@@ -22,6 +21,8 @@
#include "units/fcap/unit_fcap.h"
#include "units/touch/unit_touch.h"
#include "units/simple_pwm/unit_pwmdim.h"
#include "units/dac/unit_dac.h"
#include "comm/interfaces.h"
#include "hw_utils.h"
void plat_init_resources(void)
@@ -258,6 +259,8 @@ void plat_init_resources(void)
*/
void plat_usb_reconnect(void)
{
if (gActiveComport != COMPORT_USB) return;
// TODO add better reset methods available on different chips
USBD_LL_Reset(&hUsbDeviceFS);