[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311)

* FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started.
* Furi record, stdglue: check mutex allocation
* remove unused test
* Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state.
* Interrupt manager: explicitly init list.
* Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options.
* BLE: call debug uart callback on transmission complete
* FreeRTOS: add configUSE_NEWLIB_REENTRANT
* API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib.
* F4: update stack protection CFLAGS to match used compiller
* F4: disable compiller stack protection because of incompatibility with current compiller
* Makefile: return openocd logs to gdb
* BLE: fixed pin, moar power, ble trace info.
* Prevent sleep when connection is active
* Makefile: return serial port to upload rule, add workaround for mac os
* Furi: prevent usage of stack for cmsis functions.
* F4: add missing includes, add debugger breakpoints
* Applications: per app stack size.
* Furi: honor kernel state in stdglue
* FreeRTOS: remove unused hooks
* Cleanup and format sources

Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
This commit is contained in:
あく
2021-01-29 03:09:33 +03:00
committed by GitHub
parent fd5f694758
commit 584c0962d8
52 changed files with 517 additions and 389 deletions

View File

@@ -1,5 +1,6 @@
#include <api-hal-power.h>
#include <api-hal-clock.h>
#include <api-hal-bt.h>
#include <stm32wbxx_ll_rcc.h>
#include <stm32wbxx_ll_pwr.h>
@@ -22,6 +23,10 @@ void api_hal_power_init() {
bq25896_init();
}
bool api_hal_power_deep_available() {
return api_hal_bt_is_alive();
}
void api_hal_power_deep_sleep() {
while( LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID));

View File

@@ -69,7 +69,7 @@ static inline bool api_hal_timebase_timer_cmp_is_ok() {
}
static inline uint32_t api_hal_timebase_timer_get_cmp() {
return LL_LPTIM_GetCompare(API_HAL_TIMEBASE_TIMER);;
return LL_LPTIM_GetCompare(API_HAL_TIMEBASE_TIMER);
}
static inline void api_hal_timebase_timer_set_cmp(uint32_t value) {

View File

@@ -96,9 +96,12 @@ static inline uint32_t api_hal_timebase_sleep(TickType_t expected_idle_ticks) {
const uint16_t expected_cnt = (before_tick + expected_idle_ticks - 2) * API_HAL_TIMEBASE_CLK_PER_TICK;
api_hal_timebase_timer_set_cmp(expected_cnt);
HAL_SuspendTick();
// Go to stop2 mode
api_hal_power_deep_sleep();
HAL_ResumeTick();
// Spin till we are in timer safe zone
while(!api_hal_timebase_timer_is_safe()) {}
@@ -124,14 +127,15 @@ static inline uint32_t api_hal_timebase_sleep(TickType_t expected_idle_ticks) {
}
void vPortSuppressTicksAndSleep(TickType_t expected_idle_ticks) {
if (!api_hal_power_deep_available() || api_hal_timebase.insomnia) {
return;
}
// Limit mount of ticks to maximum that timer can count
if (expected_idle_ticks > API_HAL_TIMEBASE_MAX_SLEEP) {
expected_idle_ticks = API_HAL_TIMEBASE_MAX_SLEEP;
}
if (api_hal_timebase.insomnia)
return;
// Stop IRQ handling, no one should disturb us till we finish
__disable_irq();

View File

@@ -12,7 +12,7 @@ typedef struct {
volatile bool underrun;
} ApiHalVcp;
ApiHalVcp api_hal_vcp;
static ApiHalVcp* api_hal_vcp = NULL;
static const uint8_t ascii_soh = 0x01;
static const uint8_t ascii_eot = 0x04;
@@ -24,19 +24,20 @@ void _api_hal_vcp_rx_callback(const uint8_t* buffer, size_t size);
void _api_hal_vcp_tx_complete(size_t size);
void api_hal_vcp_init() {
api_hal_vcp.rx_stream = xStreamBufferCreate(API_HAL_VCP_RX_BUFFER_SIZE, 1);
api_hal_vcp.tx_semaphore = osSemaphoreNew(1, 1, NULL);
api_hal_vcp.alive = false;
api_hal_vcp.underrun = false;
api_hal_vcp = furi_alloc(sizeof(ApiHalVcp));
api_hal_vcp->rx_stream = xStreamBufferCreate(API_HAL_VCP_RX_BUFFER_SIZE, 1);
api_hal_vcp->tx_semaphore = osSemaphoreNew(1, 1, NULL);
api_hal_vcp->alive = false;
api_hal_vcp->underrun = false;
}
void _api_hal_vcp_init() {
osSemaphoreRelease(api_hal_vcp.tx_semaphore);
osSemaphoreRelease(api_hal_vcp->tx_semaphore);
}
void _api_hal_vcp_deinit() {
api_hal_vcp.alive = false;
osSemaphoreRelease(api_hal_vcp.tx_semaphore);
api_hal_vcp->alive = false;
osSemaphoreRelease(api_hal_vcp->tx_semaphore);
}
void _api_hal_vcp_control_line(uint8_t state) {
@@ -45,43 +46,46 @@ void _api_hal_vcp_control_line(uint8_t state) {
bool rts = state & 0b10;
if (rts) {
api_hal_vcp.alive = true;
api_hal_vcp->alive = true;
_api_hal_vcp_rx_callback(&ascii_soh, 1); // SOH
} else {
api_hal_vcp.alive = false;
api_hal_vcp->alive = false;
_api_hal_vcp_rx_callback(&ascii_eot, 1); // EOT
}
osSemaphoreRelease(api_hal_vcp.tx_semaphore);
osSemaphoreRelease(api_hal_vcp->tx_semaphore);
}
void _api_hal_vcp_rx_callback(const uint8_t* buffer, size_t size) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
size_t ret = xStreamBufferSendFromISR(api_hal_vcp.rx_stream, buffer, size, &xHigherPriorityTaskWoken);
size_t ret = xStreamBufferSendFromISR(api_hal_vcp->rx_stream, buffer, size, &xHigherPriorityTaskWoken);
if (ret != size) {
api_hal_vcp.underrun = true;
api_hal_vcp->underrun = true;
}
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
void _api_hal_vcp_tx_complete(size_t size) {
osSemaphoreRelease(api_hal_vcp.tx_semaphore);
osSemaphoreRelease(api_hal_vcp->tx_semaphore);
}
size_t api_hal_vcp_rx(uint8_t* buffer, size_t size) {
return xStreamBufferReceive(api_hal_vcp.rx_stream, buffer, size, portMAX_DELAY);
furi_assert(api_hal_vcp);
return xStreamBufferReceive(api_hal_vcp->rx_stream, buffer, size, portMAX_DELAY);
}
void api_hal_vcp_tx(uint8_t* buffer, size_t size) {
while (size > 0 && api_hal_vcp.alive) {
furi_check(osSemaphoreAcquire(api_hal_vcp.tx_semaphore, osWaitForever) == osOK);
void api_hal_vcp_tx(const uint8_t* buffer, size_t size) {
furi_assert(api_hal_vcp);
while (size > 0 && api_hal_vcp->alive) {
furi_check(osSemaphoreAcquire(api_hal_vcp->tx_semaphore, osWaitForever) == osOK);
size_t batch_size = size;
if (batch_size > APP_TX_DATA_SIZE) {
batch_size = APP_TX_DATA_SIZE;
}
if (CDC_Transmit_FS(buffer, batch_size) == USBD_OK) {
if (CDC_Transmit_FS((uint8_t*)buffer, batch_size) == USBD_OK) {
size -= batch_size;
buffer += batch_size;
} else {