[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep. * Move FreeRTOS ticks to lptim2 * API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source. * API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode. * NFC: support for tickless mode. * API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications. * BLE: prevent sleep while core2 starting * HAL: nap while in insomnia mode * init records work * try to implement record delete * tests and flapp * flapp subsystem * new core functions to get app stat, simplify core code * fix thread termination * add strdup to core * fix tests * Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage * Refactoring: update furi record api usage, cleanup code * Fix broken merge for freertos apps * Core, Target: fix compilation warnings * Drop firmware target local * HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode. * SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial. * delete old app example-ipc * delete old app fatfs list * fix strobe app, add input header * delete old display driver * comment old app qr-code * fix sd-card test, add forced widget update * remove unused new core test * increase heap to 128k * comment and assert old core tests * fix syntax Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
template <unsigned int N> struct STOP_EXTERNING_ME {};
|
||||
#endif
|
||||
|
||||
#include "api-hal-resources.h"
|
||||
#include "api-hal-timebase.h"
|
||||
#include "api-hal-boot.h"
|
||||
#include "api-hal-gpio.h"
|
||||
|
@@ -69,7 +69,7 @@
|
||||
#define configTICK_RATE_HZ ((TickType_t)1024)
|
||||
#define configMAX_PRIORITIES ( 56 )
|
||||
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
|
||||
#define configTOTAL_HEAP_SIZE ((size_t)40960)
|
||||
#define configTOTAL_HEAP_SIZE ((size_t)131072)
|
||||
#define configMAX_TASK_NAME_LEN ( 16 )
|
||||
#define configGENERATE_RUN_TIME_STATS 1
|
||||
#define configUSE_TRACE_FACILITY 1
|
||||
|
@@ -1,66 +1,16 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* File Name : app_freertos.c
|
||||
* Description : Code for freertos applications
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
#include <cmsis_os2.h>
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <main.h>
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Variables */
|
||||
|
||||
/* USER CODE END Variables */
|
||||
/* Definitions for app_main */
|
||||
osThreadId_t app_mainHandle;
|
||||
const osThreadAttr_t app_main_attributes = {
|
||||
.name = "app_main",
|
||||
.priority = (osPriority_t) osPriorityNormal,
|
||||
.stack_size = 1024 * 4
|
||||
osThreadId_t systemdHandle;
|
||||
const osThreadAttr_t systemd_attributes = {
|
||||
.name = "systemd",
|
||||
.priority = (osPriority_t) osPriorityNormal,
|
||||
.stack_size = 1024 * 4
|
||||
};
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN FunctionPrototypes */
|
||||
|
||||
/* USER CODE END FunctionPrototypes */
|
||||
|
||||
void app(void *argument);
|
||||
void systemd(void *argument);
|
||||
|
||||
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
||||
|
||||
@@ -70,107 +20,32 @@ unsigned long getRunTimeCounterValue(void);
|
||||
void vApplicationIdleHook(void);
|
||||
void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName);
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
/* Functions needed when configGENERATE_RUN_TIME_STATS is on */
|
||||
__weak void configureTimerForRunTimeStats(void)
|
||||
{
|
||||
|
||||
__weak void configureTimerForRunTimeStats(void) {
|
||||
}
|
||||
|
||||
__weak unsigned long getRunTimeCounterValue(void)
|
||||
{
|
||||
return 0;
|
||||
__weak unsigned long getRunTimeCounterValue(void) {
|
||||
return 0;
|
||||
}
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
__weak void vApplicationIdleHook( void )
|
||||
{
|
||||
/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
|
||||
to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
|
||||
task. It is essential that code added to this hook function never attempts
|
||||
to block in any way (for example, call xQueueReceive() with a block time
|
||||
specified, or call vTaskDelay()). If the application makes use of the
|
||||
vTaskDelete() API function (as this demo application does) then it is also
|
||||
important that vApplicationIdleHook() is permitted to return to its calling
|
||||
function, because it is the responsibility of the idle task to clean up
|
||||
memory allocated by the kernel to any task that has since been deleted. */
|
||||
__weak void vApplicationIdleHook( void ) {
|
||||
/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
|
||||
to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
|
||||
task. It is essential that code added to this hook function never attempts
|
||||
to block in any way (for example, call xQueueReceive() with a block time
|
||||
specified, or call vTaskDelay()). If the application makes use of the
|
||||
vTaskDelete() API function (as this demo application does) then it is also
|
||||
important that vApplicationIdleHook() is permitted to return to its calling
|
||||
function, because it is the responsibility of the idle task to clean up
|
||||
memory allocated by the kernel to any task that has since been deleted. */
|
||||
}
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
__weak void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName)
|
||||
{
|
||||
/* Run time stack overflow checking is performed if
|
||||
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
|
||||
called if a stack overflow is detected. */
|
||||
__weak void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName) {
|
||||
/* Run time stack overflow checking is performed if
|
||||
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
|
||||
called if a stack overflow is detected. */
|
||||
}
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/* USER CODE BEGIN VPORT_SUPPORT_TICKS_AND_SLEEP */
|
||||
/* USER CODE END VPORT_SUPPORT_TICKS_AND_SLEEP */
|
||||
|
||||
/**
|
||||
* @brief FreeRTOS initialization
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void MX_FREERTOS_Init(void) {
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* USER CODE BEGIN RTOS_MUTEX */
|
||||
/* add mutexes, ... */
|
||||
/* USER CODE END RTOS_MUTEX */
|
||||
|
||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||
/* add semaphores, ... */
|
||||
/* USER CODE END RTOS_SEMAPHORES */
|
||||
|
||||
/* USER CODE BEGIN RTOS_TIMERS */
|
||||
/* start timers, add new ones, ... */
|
||||
/* USER CODE END RTOS_TIMERS */
|
||||
|
||||
/* USER CODE BEGIN RTOS_QUEUES */
|
||||
/* add queues, ... */
|
||||
/* USER CODE END RTOS_QUEUES */
|
||||
|
||||
/* Create the thread(s) */
|
||||
/* creation of app_main */
|
||||
app_mainHandle = osThreadNew(app, NULL, &app_main_attributes);
|
||||
|
||||
/* USER CODE BEGIN RTOS_THREADS */
|
||||
/* add threads, ... */
|
||||
/* USER CODE END RTOS_THREADS */
|
||||
|
||||
/* USER CODE BEGIN RTOS_EVENTS */
|
||||
/* add events, ... */
|
||||
/* USER CODE END RTOS_EVENTS */
|
||||
|
||||
systemdHandle = osThreadNew(systemd, NULL, &systemd_attributes);
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_app */
|
||||
/**
|
||||
* @brief Function implementing the app_main thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_app */
|
||||
__weak void app(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN app */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
osDelay(1);
|
||||
}
|
||||
/* USER CODE END app */
|
||||
}
|
||||
|
||||
/* Private application code --------------------------------------------------*/
|
||||
/* USER CODE BEGIN Application */
|
||||
|
||||
/* USER CODE END Application */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
@@ -19,6 +19,7 @@
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "spi.h"
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
void Enable_SPI(SPI_HandleTypeDef* spi);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include "main.h"
|
||||
#include "flipper_v2.h"
|
||||
#include <furi.h>
|
||||
|
||||
const bool input_invert[GPIO_INPUT_PINS_COUNT] = {
|
||||
true, // {BUTTON_UP_GPIO_Port, BUTTON_UP_Pin},
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include "main.h"
|
||||
#include "flipper_v2.h"
|
||||
#include <furi.h>
|
||||
|
||||
const GpioPin input_gpio[GPIO_INPUT_PINS_COUNT] = {
|
||||
{BUTTON_UP_GPIO_Port, BUTTON_UP_Pin},
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "main.h"
|
||||
#include "flipper_v2.h"
|
||||
#include <furi.h>
|
||||
|
||||
#define DEBOUNCE_TICKS 10
|
||||
#define GPIO_INPUT_PINS_COUNT 6
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include "api-hal-spi.h"
|
||||
#include <cmsis_os.h>
|
||||
#include <cmsis_os2.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@@ -52,8 +52,3 @@
|
||||
bool task_is_isr_context(void) {
|
||||
return IS_IRQ();
|
||||
}
|
||||
|
||||
bool task_equal(TaskHandle_t a, TaskHandle_t b) {
|
||||
if(a == NULL || b == NULL) return false;
|
||||
return a == b;
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "main.h"
|
||||
#include <cmsis_os.h>
|
||||
#include <cmsis_os2.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// Task stack size in bytes
|
||||
@@ -9,5 +9,4 @@
|
||||
// Max system tasks count
|
||||
#define MAX_TASK_COUNT 14
|
||||
|
||||
bool task_equal(TaskHandle_t a, TaskHandle_t b);
|
||||
bool task_is_isr_context(void);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <api-hal-vcp.h>
|
||||
#include <usbd_cdc_if.h>
|
||||
#include <flipper_v2.h>
|
||||
#include <furi.h>
|
||||
#include <stream_buffer.h>
|
||||
|
||||
#define API_HAL_VCP_RX_BUFFER_SIZE 600
|
||||
|
@@ -1,4 +1,7 @@
|
||||
#include "api-hal/api-interrupt-mgr.h"
|
||||
#include <main.h>
|
||||
|
||||
extern void api_interrupt_call(InterruptType type, void* hw);
|
||||
|
||||
/* interrupts */
|
||||
void HAL_COMP_TriggerCallback(COMP_HandleTypeDef* hcomp) {
|
||||
|
@@ -261,7 +261,7 @@
|
||||
* When set to 1, the low power mode is enable
|
||||
* When set to 0, the device stays in RUN mode
|
||||
*/
|
||||
#define CFG_LPM_SUPPORTED 0
|
||||
#define CFG_LPM_SUPPORTED 1
|
||||
|
||||
/******************************************************************************
|
||||
* Timer Server
|
||||
|
@@ -41,14 +41,14 @@ extern UART_HandleTypeDef DEBUG_UART;
|
||||
* The raw data output is the hci binary packet format as specified by the BT specification *
|
||||
*/
|
||||
#define TL_SHCI_CMD_DBG_EN 1 /* Reports System commands sent to CPU2 and the command response */
|
||||
#define TL_SHCI_CMD_DBG_RAW_EN 1 /* Reports raw data System commands sent to CPU2 and the command response */
|
||||
#define TL_SHCI_CMD_DBG_RAW_EN 0 /* Reports raw data System commands sent to CPU2 and the command response */
|
||||
#define TL_SHCI_EVT_DBG_EN 1 /* Reports System Asynchronous Events received from CPU2 */
|
||||
#define TL_SHCI_EVT_DBG_RAW_EN 1 /* Reports raw data System Asynchronous Events received from CPU2 */
|
||||
#define TL_SHCI_EVT_DBG_RAW_EN 0 /* Reports raw data System Asynchronous Events received from CPU2 */
|
||||
|
||||
#define TL_HCI_CMD_DBG_EN 1 /* Reports BLE command sent to CPU2 and the command response */
|
||||
#define TL_HCI_CMD_DBG_RAW_EN 1 /* Reports raw data BLE command sent to CPU2 and the command response */
|
||||
#define TL_HCI_CMD_DBG_RAW_EN 0 /* Reports raw data BLE command sent to CPU2 and the command response */
|
||||
#define TL_HCI_EVT_DBG_EN 1 /* Reports BLE Asynchronous Events received from CPU2 */
|
||||
#define TL_HCI_EVT_DBG_RAW_EN 1 /* Reports raw data BLE Asynchronous Events received from CPU2 */
|
||||
#define TL_HCI_EVT_DBG_RAW_EN 0 /* Reports raw data BLE Asynchronous Events received from CPU2 */
|
||||
|
||||
#define TL_MM_DBG_EN 1 /* Reports the informations of the buffer released to CPU2 */
|
||||
|
||||
|
@@ -1,107 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "main.h"
|
||||
#include <stdbool.h>
|
||||
#include <pthread.h>
|
||||
|
||||
void osDelay(uint32_t ms);
|
||||
|
||||
// some FreeRTOS types
|
||||
typedef void (*TaskFunction_t)(void*);
|
||||
typedef size_t UBaseType_t;
|
||||
typedef uint32_t StackType_t;
|
||||
typedef uint32_t StaticTask_t;
|
||||
typedef pthread_t* TaskHandle_t;
|
||||
|
||||
typedef enum {
|
||||
SemaphoreTypeMutex,
|
||||
SemaphoreTypeCounting,
|
||||
} SemaphoreType;
|
||||
typedef struct {
|
||||
SemaphoreType type;
|
||||
pthread_mutex_t mutex;
|
||||
uint8_t take_counter;
|
||||
uint8_t give_counter;
|
||||
} StaticSemaphore_t;
|
||||
typedef StaticSemaphore_t* SemaphoreHandle_t;
|
||||
|
||||
typedef uint32_t StaticQueue_t;
|
||||
typedef StaticQueue_t* QueueHandle_t;
|
||||
|
||||
#define portMAX_DELAY -1
|
||||
|
||||
typedef enum { pdTRUE = 1, pdFALSE = 0 } BaseType_t;
|
||||
|
||||
typedef int32_t TickType_t;
|
||||
|
||||
#define tskIDLE_PRIORITY 0
|
||||
|
||||
TaskHandle_t xTaskCreateStatic(TaskFunction_t pxTaskCode,
|
||||
const char* const pcName,
|
||||
const uint32_t ulStackDepth,
|
||||
void* const pvParameters,
|
||||
UBaseType_t uxPriority,
|
||||
StackType_t* const puxStackBuffer,
|
||||
StaticTask_t* const pxTaskBuffer);
|
||||
|
||||
void vTaskDelete(TaskHandle_t xTask);
|
||||
TaskHandle_t xTaskGetCurrentTaskHandle(void);
|
||||
SemaphoreHandle_t xSemaphoreCreateMutexStatic(StaticSemaphore_t* pxMutexBuffer);
|
||||
|
||||
QueueHandle_t xQueueCreateStatic(UBaseType_t uxQueueLength,
|
||||
UBaseType_t uxItemSize,
|
||||
uint8_t* pucQueueStorageBuffer,
|
||||
StaticQueue_t* pxQueueBuffer);
|
||||
|
||||
SemaphoreHandle_t xSemaphoreCreateCountingStatic(UBaseType_t uxMaxCount,
|
||||
UBaseType_t uxInitialCount,
|
||||
StaticSemaphore_t* pxSemaphoreBuffer);
|
||||
BaseType_t xSemaphoreTake(SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait);
|
||||
BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore);
|
||||
|
||||
BaseType_t xQueueSend(QueueHandle_t xQueue, const void* pvItemToQueue, TickType_t xTicksToWait);
|
||||
|
||||
BaseType_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait);
|
||||
|
||||
void* pvTaskGetThreadLocalStoragePointer(TaskHandle_t xTaskToQuery, BaseType_t xIndex);
|
||||
void vTaskSetThreadLocalStoragePointer(TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue);
|
||||
|
||||
QueueHandle_t xQueueCreate(UBaseType_t uxQueueLength, UBaseType_t uxItemSize);
|
||||
|
||||
typedef struct {
|
||||
const char *name; ///< name of the mutex
|
||||
uint32_t attr_bits; ///< attribute bits
|
||||
void *cb_mem; ///< memory for control block
|
||||
uint32_t cb_size; ///< size of provided memory for control block
|
||||
} osMutexAttr_t;
|
||||
|
||||
typedef SemaphoreHandle_t osMutexId_t;
|
||||
|
||||
osMutexId_t osMutexNew(const osMutexAttr_t *attr);
|
||||
|
||||
/// Status code values returned by CMSIS-RTOS functions.
|
||||
typedef enum {
|
||||
osOK = 0, ///< Operation completed successfully.
|
||||
osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits.
|
||||
osErrorTimeout = -2, ///< Operation not completed within the timeout period.
|
||||
osErrorResource = -3, ///< Resource not available.
|
||||
osErrorParameter = -4, ///< Parameter error.
|
||||
osErrorNoMemory = -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.
|
||||
osErrorISR = -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
|
||||
osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
|
||||
} osStatus_t;
|
||||
|
||||
osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout);
|
||||
osStatus_t osMutexRelease (osMutexId_t mutex_id);
|
||||
osStatus_t osMutexDelete (osMutexId_t mutex_id);
|
||||
|
||||
#define osWaitForever portMAX_DELAY
|
||||
|
||||
typedef StaticSemaphore_t osSemaphoreDef_t;
|
||||
typedef SemaphoreHandle_t osSemaphoreId_t;
|
||||
typedef struct {} osSemaphoreAttr_t;
|
||||
|
||||
osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr);
|
||||
osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout);
|
||||
osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id);
|
||||
osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id);
|
@@ -1 +0,0 @@
|
||||
#include "cmsis_os.h"
|
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
Flipper devices inc.
|
||||
|
||||
GPIO and HAL implementations
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "main.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define GPIOA "PA"
|
||||
#define GPIOB "PB"
|
||||
#define GPIOC "PC"
|
||||
#define GPIOD "PD"
|
||||
#define GPIOE "PE"
|
||||
|
||||
#define GPIO_PIN_0 0
|
||||
#define GPIO_PIN_1 1
|
||||
#define GPIO_PIN_2 2
|
||||
#define GPIO_PIN_3 3
|
||||
#define GPIO_PIN_4 4
|
||||
#define GPIO_PIN_5 5
|
||||
#define GPIO_PIN_6 6
|
||||
#define GPIO_PIN_7 7
|
||||
#define GPIO_PIN_8 8
|
||||
#define GPIO_PIN_9 9
|
||||
#define GPIO_PIN_10 10
|
||||
#define GPIO_PIN_11 11
|
||||
#define GPIO_PIN_12 12
|
||||
#define GPIO_PIN_13 13
|
||||
#define GPIO_PIN_14 14
|
||||
#define GPIO_PIN_15 15
|
||||
|
||||
#define DISPLAY_RST_GPIO_Port "DISPLAY RST"
|
||||
#define DISPLAY_DI_Pin 0
|
||||
|
||||
#define DISPLAY_DI_GPIO_Port "DISPLAY DI"
|
||||
#define DISPLAY_RST_Pin 0
|
||||
|
||||
#define DISPLAY_CS_GPIO_Port "DISPLAY CS"
|
||||
#define DISPLAY_CS_Pin 0
|
||||
|
||||
#define DISPLAY_BACKLIGHT_GPIO_Port "BACKLIGHT"
|
||||
#define DISPLAY_BACKLIGHT_Pin 0
|
||||
|
||||
typedef const char* SPI_HandleTypeDef;
|
||||
|
||||
typedef uint32_t HAL_StatusTypeDef;
|
||||
|
||||
HAL_StatusTypeDef
|
||||
HAL_SPI_Transmit(SPI_HandleTypeDef* hspi, uint8_t* pData, uint16_t Size, uint32_t Timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -1,37 +0,0 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <cmsis_os.h>
|
||||
|
||||
#define configTOTAL_HEAP_SIZE ((size_t)(8192 * 16))
|
||||
#define configAPPLICATION_ALLOCATED_HEAP 0
|
||||
#define portBYTE_ALIGNMENT 8
|
||||
|
||||
#if portBYTE_ALIGNMENT == 8
|
||||
#define portBYTE_ALIGNMENT_MASK (0x0007)
|
||||
#endif
|
||||
|
||||
/* No test marker by default. */
|
||||
#ifndef mtCOVERAGE_TEST_MARKER
|
||||
#define mtCOVERAGE_TEST_MARKER()
|
||||
#endif
|
||||
|
||||
/* No tracing by default. */
|
||||
#ifndef traceMALLOC
|
||||
#define traceMALLOC(pvReturn, xWantedSize)
|
||||
#endif
|
||||
|
||||
/* No tracing by default. */
|
||||
#ifndef traceFREE
|
||||
#define traceFREE(pvReturn, xBlockSize)
|
||||
#endif
|
||||
|
||||
/* No assert by default. */
|
||||
#ifndef configASSERT
|
||||
#define configASSERT(var)
|
||||
#endif
|
||||
|
||||
bool prvHeapInit(void);
|
||||
|
||||
void acquire_memalloc_mutex();
|
||||
void release_memalloc_mutex();
|
@@ -1,29 +0,0 @@
|
||||
#ifndef __INPUT_PRIV_H
|
||||
#define __INPUT_PRIV_H
|
||||
|
||||
#include "main.h"
|
||||
#include "flipper_hal.h"
|
||||
|
||||
#define DEBOUNCE_TICKS 10
|
||||
|
||||
const GpioPin input_gpio[] = {
|
||||
{"Up", 0},
|
||||
{"Down", 0},
|
||||
{"Right", 0},
|
||||
{"Left", 0},
|
||||
{"Ok", 0},
|
||||
{"Back", 0},
|
||||
{"Charg", 0}
|
||||
};
|
||||
|
||||
const bool input_invert[] = {
|
||||
false, // {BUTTON_UP_GPIO_Port, BUTTON_UP_Pin},
|
||||
false, // {BUTTON_DOWN_GPIO_Port, BUTTON_DOWN_Pin},
|
||||
false, // {BUTTON_RIGHT_GPIO_Port, BUTTON_RIGHT_Pin},
|
||||
false, // {BUTTON_LEFT_GPIO_Port, BUTTON_LEFT_Pin},
|
||||
false, // {BUTTON_OK_GPIO_Port, BUTTON_OK_Pin},
|
||||
false, // {BUTTON_BACK_GPIO_Port, BUTTON_BACK_Pin},
|
||||
true, // {CHRG_GPIO_Port, CHRG_Pin}
|
||||
};
|
||||
|
||||
#endif /* __INPUT_PRIV_H */
|
@@ -1,26 +0,0 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define HAL_MAX_DELAY INT_MAX
|
||||
|
||||
typedef uint32_t UART_HandleTypeDef;
|
||||
uint16_t
|
||||
HAL_UART_Transmit(UART_HandleTypeDef* handle, uint8_t* bufer, uint16_t size, uint32_t wait_ms);
|
||||
|
||||
typedef uint32_t TIM_HandleTypeDef;
|
||||
|
||||
#define LED_RED_Pin 1
|
||||
#define LED_RED_GPIO_Port "Red:"
|
||||
#define LED_GREEN_Pin 1
|
||||
#define LED_GREEN_GPIO_Port "Green:"
|
||||
#define LED_BLUE_Pin 1
|
||||
#define LED_BLUE_GPIO_Port "Blue:"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
Flipper devices inc.
|
||||
|
||||
GPIO and HAL implementations
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "flipper_hal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
HAL_StatusTypeDef
|
||||
HAL_SPI_Transmit(SPI_HandleTypeDef* hspi, uint8_t* pData, uint16_t size, uint32_t Timeout) {
|
||||
printf("[SPI] write %d to %s: ", size, *hspi);
|
||||
for(size_t i = 0; i < size; i++) {
|
||||
printf("%02X ", pData[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPI_HandleTypeDef hspi1 = "spi1";
|
@@ -1,389 +0,0 @@
|
||||
/*
|
||||
* FreeRTOS Kernel V10.2.1
|
||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://aws.amazon.com/freertos
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*/
|
||||
|
||||
/*
|
||||
* A sample implementation of pvPortMalloc() and vPortFree() that combines
|
||||
* (coalescences) adjacent memory blocks as they are freed, and in so doing
|
||||
* limits memory fragmentation.
|
||||
*
|
||||
* See heap_1.c, heap_2.c and heap_3.c for alternative implementations, and the
|
||||
* memory management pages of http://www.FreeRTOS.org for more information.
|
||||
*/
|
||||
#include "heap.h"
|
||||
|
||||
osMutexId_t heap_managment_mutex = NULL;
|
||||
|
||||
/* Block sizes must not get too small. */
|
||||
#define heapMINIMUM_BLOCK_SIZE ((size_t)(xHeapStructSize << 1))
|
||||
|
||||
/* Assumes 8bit bytes! */
|
||||
#define heapBITS_PER_BYTE ((size_t)8)
|
||||
|
||||
/* Allocate the memory for the heap. */
|
||||
#if(configAPPLICATION_ALLOCATED_HEAP == 1)
|
||||
/* The application writer has already defined the array used for the RTOS
|
||||
heap - probably so it can be placed in a special segment or address. */
|
||||
extern uint8_t ucHeap[configTOTAL_HEAP_SIZE];
|
||||
#else
|
||||
static uint8_t ucHeap[configTOTAL_HEAP_SIZE];
|
||||
#endif /* configAPPLICATION_ALLOCATED_HEAP */
|
||||
|
||||
/* Define the linked list structure. This is used to link free blocks in order
|
||||
of their memory address. */
|
||||
typedef struct A_BLOCK_LINK {
|
||||
struct A_BLOCK_LINK* pxNextFreeBlock; /*<< The next free block in the list. */
|
||||
size_t xBlockSize; /*<< The size of the free block. */
|
||||
} BlockLink_t;
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* Inserts a block of memory that is being freed into the correct position in
|
||||
* the list of free memory blocks. The block being freed will be merged with
|
||||
* the block in front it and/or the block behind it if the memory blocks are
|
||||
* adjacent to each other.
|
||||
*/
|
||||
static void prvInsertBlockIntoFreeList(BlockLink_t* pxBlockToInsert);
|
||||
|
||||
// this function is not thread-safe, so it must be called in single thread context
|
||||
bool prvHeapInit(void);
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* The size of the structure placed at the beginning of each allocated memory
|
||||
block must by correctly byte aligned. */
|
||||
static const size_t xHeapStructSize = (sizeof(BlockLink_t) + ((size_t)(portBYTE_ALIGNMENT - 1))) &
|
||||
~((size_t)portBYTE_ALIGNMENT_MASK);
|
||||
|
||||
/* Create a couple of list links to mark the start and end of the list. */
|
||||
static BlockLink_t xStart, *pxEnd = NULL;
|
||||
|
||||
/* Keeps track of the number of free bytes remaining, but says nothing about
|
||||
fragmentation. */
|
||||
static size_t xFreeBytesRemaining = 0U;
|
||||
static size_t xMinimumEverFreeBytesRemaining = 0U;
|
||||
|
||||
/* Gets set to the top bit of an size_t type. When this bit in the xBlockSize
|
||||
member of an BlockLink_t structure is set then the block belongs to the
|
||||
application. When the bit is free the block is still part of the free heap
|
||||
space. */
|
||||
static size_t xBlockAllocatedBit = 0;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void* pvPortMalloc(size_t xWantedSize) {
|
||||
BlockLink_t *pxBlock, *pxPreviousBlock, *pxNewBlockLink;
|
||||
void* pvReturn = NULL;
|
||||
|
||||
acquire_memalloc_mutex();
|
||||
{
|
||||
/* If this is the first call to malloc then the heap will require
|
||||
initialisation to setup the list of free blocks. */
|
||||
if(pxEnd == NULL) {
|
||||
prvHeapInit();
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
/* Check the requested block size is not so large that the top bit is
|
||||
set. The top bit of the block size member of the BlockLink_t structure
|
||||
is used to determine who owns the block - the application or the
|
||||
kernel, so it must be free. */
|
||||
if((xWantedSize & xBlockAllocatedBit) == 0) {
|
||||
/* The wanted size is increased so it can contain a BlockLink_t
|
||||
structure in addition to the requested amount of bytes. */
|
||||
if(xWantedSize > 0) {
|
||||
xWantedSize += xHeapStructSize;
|
||||
|
||||
/* Ensure that blocks are always aligned to the required number
|
||||
of bytes. */
|
||||
if((xWantedSize & portBYTE_ALIGNMENT_MASK) != 0x00) {
|
||||
/* Byte alignment required. */
|
||||
xWantedSize += (portBYTE_ALIGNMENT - (xWantedSize & portBYTE_ALIGNMENT_MASK));
|
||||
configASSERT((xWantedSize & portBYTE_ALIGNMENT_MASK) == 0);
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
if((xWantedSize > 0) && (xWantedSize <= xFreeBytesRemaining)) {
|
||||
/* Traverse the list from the start (lowest address) block until
|
||||
one of adequate size is found. */
|
||||
pxPreviousBlock = &xStart;
|
||||
pxBlock = xStart.pxNextFreeBlock;
|
||||
while((pxBlock->xBlockSize < xWantedSize) && (pxBlock->pxNextFreeBlock != NULL)) {
|
||||
pxPreviousBlock = pxBlock;
|
||||
pxBlock = pxBlock->pxNextFreeBlock;
|
||||
}
|
||||
|
||||
/* If the end marker was reached then a block of adequate size
|
||||
was not found. */
|
||||
if(pxBlock != pxEnd) {
|
||||
/* Return the memory space pointed to - jumping over the
|
||||
BlockLink_t structure at its start. */
|
||||
pvReturn =
|
||||
(void*)(((uint8_t*)pxPreviousBlock->pxNextFreeBlock) + xHeapStructSize);
|
||||
|
||||
/* This block is being returned for use so must be taken out
|
||||
of the list of free blocks. */
|
||||
pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;
|
||||
|
||||
/* If the block is larger than required it can be split into
|
||||
two. */
|
||||
if((pxBlock->xBlockSize - xWantedSize) > heapMINIMUM_BLOCK_SIZE) {
|
||||
/* This block is to be split into two. Create a new
|
||||
block following the number of bytes requested. The void
|
||||
cast is used to prevent byte alignment warnings from the
|
||||
compiler. */
|
||||
pxNewBlockLink = (void*)(((uint8_t*)pxBlock) + xWantedSize);
|
||||
configASSERT((((size_t)pxNewBlockLink) & portBYTE_ALIGNMENT_MASK) == 0);
|
||||
|
||||
/* Calculate the sizes of two blocks split from the
|
||||
single block. */
|
||||
pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
|
||||
pxBlock->xBlockSize = xWantedSize;
|
||||
|
||||
/* Insert the new block into the list of free blocks. */
|
||||
prvInsertBlockIntoFreeList(pxNewBlockLink);
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
xFreeBytesRemaining -= pxBlock->xBlockSize;
|
||||
|
||||
if(xFreeBytesRemaining < xMinimumEverFreeBytesRemaining) {
|
||||
xMinimumEverFreeBytesRemaining = xFreeBytesRemaining;
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
/* The block is being returned - it is allocated and owned
|
||||
by the application and has no "next" block. */
|
||||
pxBlock->xBlockSize |= xBlockAllocatedBit;
|
||||
pxBlock->pxNextFreeBlock = NULL;
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
traceMALLOC(pvReturn, xWantedSize);
|
||||
}
|
||||
release_memalloc_mutex();
|
||||
|
||||
#if(configUSE_MALLOC_FAILED_HOOK == 1)
|
||||
{
|
||||
if(pvReturn == NULL) {
|
||||
extern void vApplicationMallocFailedHook(void);
|
||||
vApplicationMallocFailedHook();
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
configASSERT((((size_t)pvReturn) & (size_t)portBYTE_ALIGNMENT_MASK) == 0);
|
||||
return pvReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vPortFree(void* pv) {
|
||||
uint8_t* puc = (uint8_t*)pv;
|
||||
BlockLink_t* pxLink;
|
||||
|
||||
if(pv != NULL) {
|
||||
/* The memory being freed will have an BlockLink_t structure immediately
|
||||
before it. */
|
||||
puc -= xHeapStructSize;
|
||||
|
||||
/* This casting is to keep the compiler from issuing warnings. */
|
||||
pxLink = (void*)puc;
|
||||
|
||||
/* Check the block is actually allocated. */
|
||||
configASSERT((pxLink->xBlockSize & xBlockAllocatedBit) != 0);
|
||||
configASSERT(pxLink->pxNextFreeBlock == NULL);
|
||||
|
||||
if((pxLink->xBlockSize & xBlockAllocatedBit) != 0) {
|
||||
if(pxLink->pxNextFreeBlock == NULL) {
|
||||
/* The block is being returned to the heap - it is no longer
|
||||
allocated. */
|
||||
pxLink->xBlockSize &= ~xBlockAllocatedBit;
|
||||
|
||||
acquire_memalloc_mutex();
|
||||
{
|
||||
/* Add this block to the list of free blocks. */
|
||||
xFreeBytesRemaining += pxLink->xBlockSize;
|
||||
traceFREE(pv, pxLink->xBlockSize);
|
||||
prvInsertBlockIntoFreeList(((BlockLink_t*)pxLink));
|
||||
}
|
||||
release_memalloc_mutex();
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
size_t xPortGetFreeHeapSize(void) {
|
||||
return xFreeBytesRemaining;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
size_t xPortGetMinimumEverFreeHeapSize(void) {
|
||||
return xMinimumEverFreeBytesRemaining;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vPortInitialiseBlocks(void) {
|
||||
/* This just exists to keep the linker quiet. */
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
bool prvHeapInit(void) {
|
||||
BlockLink_t* pxFirstFreeBlock;
|
||||
uint8_t* pucAlignedHeap;
|
||||
size_t uxAddress;
|
||||
size_t xTotalHeapSize = configTOTAL_HEAP_SIZE;
|
||||
|
||||
/* Ensure the heap starts on a correctly aligned boundary. */
|
||||
uxAddress = (size_t)ucHeap;
|
||||
|
||||
if((uxAddress & portBYTE_ALIGNMENT_MASK) != 0) {
|
||||
uxAddress += (portBYTE_ALIGNMENT - 1);
|
||||
uxAddress &= ~((size_t)portBYTE_ALIGNMENT_MASK);
|
||||
xTotalHeapSize -= uxAddress - (size_t)ucHeap;
|
||||
}
|
||||
|
||||
pucAlignedHeap = (uint8_t*)uxAddress;
|
||||
|
||||
/* xStart is used to hold a pointer to the first item in the list of free
|
||||
blocks. The void cast is used to prevent compiler warnings. */
|
||||
xStart.pxNextFreeBlock = (void*)pucAlignedHeap;
|
||||
xStart.xBlockSize = (size_t)0;
|
||||
|
||||
/* pxEnd is used to mark the end of the list of free blocks and is inserted
|
||||
at the end of the heap space. */
|
||||
uxAddress = ((size_t)pucAlignedHeap) + xTotalHeapSize;
|
||||
uxAddress -= xHeapStructSize;
|
||||
uxAddress &= ~((size_t)portBYTE_ALIGNMENT_MASK);
|
||||
pxEnd = (void*)uxAddress;
|
||||
pxEnd->xBlockSize = 0;
|
||||
pxEnd->pxNextFreeBlock = NULL;
|
||||
|
||||
/* To start with there is a single free block that is sized to take up the
|
||||
entire heap space, minus the space taken by pxEnd. */
|
||||
pxFirstFreeBlock = (void*)pucAlignedHeap;
|
||||
pxFirstFreeBlock->xBlockSize = uxAddress - (size_t)pxFirstFreeBlock;
|
||||
pxFirstFreeBlock->pxNextFreeBlock = pxEnd;
|
||||
|
||||
/* Only one block exists - and it covers the entire usable heap space. */
|
||||
xMinimumEverFreeBytesRemaining = pxFirstFreeBlock->xBlockSize;
|
||||
xFreeBytesRemaining = pxFirstFreeBlock->xBlockSize;
|
||||
|
||||
/* Work out the position of the top bit in a size_t variable. */
|
||||
xBlockAllocatedBit = ((size_t)1) << ((sizeof(size_t) * heapBITS_PER_BYTE) - 1);
|
||||
|
||||
// now we can use malloc, so we init heap managment mutex
|
||||
const osMutexAttr_t heap_managment_mutext_attr = {
|
||||
.name = NULL, .attr_bits = 0, .cb_mem = NULL, .cb_size = 0U};
|
||||
|
||||
heap_managment_mutex = osMutexNew(&heap_managment_mutext_attr);
|
||||
|
||||
return heap_managment_mutex != NULL;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvInsertBlockIntoFreeList(BlockLink_t* pxBlockToInsert) {
|
||||
BlockLink_t* pxIterator;
|
||||
uint8_t* puc;
|
||||
|
||||
/* Iterate through the list until a block is found that has a higher address
|
||||
than the block being inserted. */
|
||||
for(pxIterator = &xStart; pxIterator->pxNextFreeBlock < pxBlockToInsert;
|
||||
pxIterator = pxIterator->pxNextFreeBlock) {
|
||||
/* Nothing to do here, just iterate to the right position. */
|
||||
}
|
||||
|
||||
/* Do the block being inserted, and the block it is being inserted after
|
||||
make a contiguous block of memory? */
|
||||
puc = (uint8_t*)pxIterator;
|
||||
if((puc + pxIterator->xBlockSize) == (uint8_t*)pxBlockToInsert) {
|
||||
pxIterator->xBlockSize += pxBlockToInsert->xBlockSize;
|
||||
pxBlockToInsert = pxIterator;
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
/* Do the block being inserted, and the block it is being inserted before
|
||||
make a contiguous block of memory? */
|
||||
puc = (uint8_t*)pxBlockToInsert;
|
||||
if((puc + pxBlockToInsert->xBlockSize) == (uint8_t*)pxIterator->pxNextFreeBlock) {
|
||||
if(pxIterator->pxNextFreeBlock != pxEnd) {
|
||||
/* Form one big block from the two blocks. */
|
||||
pxBlockToInsert->xBlockSize += pxIterator->pxNextFreeBlock->xBlockSize;
|
||||
pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock->pxNextFreeBlock;
|
||||
} else {
|
||||
pxBlockToInsert->pxNextFreeBlock = pxEnd;
|
||||
}
|
||||
} else {
|
||||
pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock;
|
||||
}
|
||||
|
||||
/* If the block being inserted plugged a gab, so was merged with the block
|
||||
before and the block after, then it's pxNextFreeBlock pointer will have
|
||||
already been set, and should not be set here as that would make it point
|
||||
to itself. */
|
||||
if(pxIterator != pxBlockToInsert) {
|
||||
pxIterator->pxNextFreeBlock = pxBlockToInsert;
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
at first run (heap init) it not work properly and prvHeapInit
|
||||
is not thread-safe. But then we init mutex or die
|
||||
*/
|
||||
void acquire_memalloc_mutex() {
|
||||
if(heap_managment_mutex != NULL) {
|
||||
osMutexAcquire(heap_managment_mutex, osWaitForever);
|
||||
}
|
||||
}
|
||||
|
||||
void release_memalloc_mutex() {
|
||||
if(heap_managment_mutex != NULL) {
|
||||
osMutexRelease(heap_managment_mutex);
|
||||
}
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
Flipper devices inc.
|
||||
|
||||
Dummy hal for local fw build
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "main.h"
|
||||
#include <unistd.h>
|
||||
|
||||
UART_HandleTypeDef DEBUG_UART = 0;
|
||||
|
||||
uint16_t
|
||||
HAL_UART_Transmit(UART_HandleTypeDef* handle, uint8_t* bufer, uint16_t size, uint32_t wait_ms) {
|
||||
uint16_t res = write(1, (const char*)bufer, size);
|
||||
return res;
|
||||
}
|
||||
|
||||
uint8_t BSP_SD_Init() {
|
||||
return 0;
|
||||
}
|
@@ -1,313 +0,0 @@
|
||||
#include "cmsis_os.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
|
||||
void osDelay(uint32_t ms) {
|
||||
// printf("[DELAY] %d ms\n", ms);
|
||||
usleep(ms * 1000);
|
||||
}
|
||||
|
||||
// temporary struct to pass function ptr and param to wrapper
|
||||
typedef struct {
|
||||
TaskFunction_t func;
|
||||
void* param;
|
||||
} PthreadTask;
|
||||
|
||||
void* pthread_wrapper(void* p) {
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0x00);
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0x00);
|
||||
|
||||
PthreadTask* task = (PthreadTask*)p;
|
||||
|
||||
task->func(task->param);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TaskHandle_t xTaskCreateStatic(
|
||||
TaskFunction_t pxTaskCode,
|
||||
const char* const pcName,
|
||||
const uint32_t ulStackDepth,
|
||||
void* const pvParameters,
|
||||
UBaseType_t uxPriority,
|
||||
StackType_t* const puxStackBuffer,
|
||||
StaticTask_t* const pxTaskBuffer) {
|
||||
TaskHandle_t thread = malloc(sizeof(TaskHandle_t));
|
||||
PthreadTask* task = malloc(sizeof(PthreadTask));
|
||||
|
||||
task->func = pxTaskCode;
|
||||
task->param = pvParameters;
|
||||
|
||||
pthread_create(thread, NULL, pthread_wrapper, (void*)task);
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
void vTaskDelete(TaskHandle_t xTask) {
|
||||
if(xTask == NULL) {
|
||||
// kill itself
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
// maybe thread already join
|
||||
if(pthread_kill(*xTask, 0) == ESRCH) return;
|
||||
|
||||
// send thread_child signal to stop it сигнал, который ее завершает
|
||||
pthread_cancel(*xTask);
|
||||
|
||||
// wait for join and close descriptor
|
||||
pthread_join(*xTask, 0x00);
|
||||
|
||||
// cleanup thread handler
|
||||
*xTask = 0;
|
||||
}
|
||||
|
||||
TaskHandle_t xTaskGetCurrentTaskHandle(void) {
|
||||
TaskHandle_t thread = malloc(sizeof(TaskHandle_t));
|
||||
*thread = pthread_self();
|
||||
return thread;
|
||||
}
|
||||
|
||||
BaseType_t xQueueSend(QueueHandle_t xQueue, const void* pvItemToQueue, TickType_t xTicksToWait) {
|
||||
// TODO: add implementation
|
||||
return pdTRUE;
|
||||
}
|
||||
|
||||
BaseType_t xQueueReceive(QueueHandle_t xQueue, void* pvBuffer, TickType_t xTicksToWait) {
|
||||
// TODO: add implementation
|
||||
osDelay(100);
|
||||
|
||||
return pdFALSE;
|
||||
}
|
||||
|
||||
static uint32_t queue_global_id = 0;
|
||||
|
||||
QueueHandle_t xQueueCreateStatic(
|
||||
UBaseType_t uxQueueLength,
|
||||
UBaseType_t uxItemSize,
|
||||
uint8_t* pucQueueStorageBuffer,
|
||||
StaticQueue_t* pxQueueBuffer) {
|
||||
// TODO: check this implementation
|
||||
int* msgid = malloc(sizeof(int));
|
||||
|
||||
key_t key = queue_global_id;
|
||||
queue_global_id++;
|
||||
|
||||
*msgid = msgget(key, IPC_CREAT);
|
||||
|
||||
return (QueueHandle_t)msgid;
|
||||
}
|
||||
|
||||
QueueHandle_t xQueueCreate(UBaseType_t uxQueueLength, UBaseType_t uxItemSize) {
|
||||
return xQueueCreateStatic(uxQueueLength, uxItemSize, 0, NULL);
|
||||
}
|
||||
|
||||
SemaphoreHandle_t xSemaphoreCreateCountingStatic(
|
||||
UBaseType_t uxMaxCount,
|
||||
UBaseType_t uxInitialCount,
|
||||
StaticSemaphore_t* pxSemaphoreBuffer) {
|
||||
pxSemaphoreBuffer->type = SemaphoreTypeCounting;
|
||||
pxSemaphoreBuffer->take_counter = 0;
|
||||
pxSemaphoreBuffer->give_counter = 0;
|
||||
return pxSemaphoreBuffer;
|
||||
}
|
||||
|
||||
SemaphoreHandle_t xSemaphoreCreateMutexStatic(StaticSemaphore_t* pxMutexBuffer) {
|
||||
pxMutexBuffer->type = SemaphoreTypeMutex;
|
||||
pthread_mutex_init(&pxMutexBuffer->mutex, NULL);
|
||||
pxMutexBuffer->take_counter = 0;
|
||||
pxMutexBuffer->give_counter = 0;
|
||||
return pxMutexBuffer;
|
||||
}
|
||||
|
||||
BaseType_t xSemaphoreTake(volatile SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait) {
|
||||
if(xSemaphore == NULL) return pdFALSE;
|
||||
|
||||
if(xSemaphore->type == SemaphoreTypeMutex) {
|
||||
if(xTicksToWait == portMAX_DELAY) {
|
||||
if(pthread_mutex_lock(&xSemaphore->mutex) == 0) {
|
||||
return pdTRUE;
|
||||
} else {
|
||||
return pdFALSE;
|
||||
}
|
||||
} else {
|
||||
TickType_t ticks = xTicksToWait;
|
||||
while(ticks >= 0) {
|
||||
if(pthread_mutex_trylock(&xSemaphore->mutex) == 0) {
|
||||
return pdTRUE;
|
||||
}
|
||||
if(ticks > 0) {
|
||||
osDelay(1);
|
||||
}
|
||||
ticks--;
|
||||
}
|
||||
return pdFALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: need to add inter-process sync or use POSIX primitives
|
||||
xSemaphore->take_counter++;
|
||||
|
||||
TickType_t ticks = xTicksToWait;
|
||||
|
||||
while(xSemaphore->take_counter != xSemaphore->give_counter &&
|
||||
(ticks > 0 || xTicksToWait == portMAX_DELAY)) {
|
||||
osDelay(1);
|
||||
ticks--;
|
||||
}
|
||||
|
||||
if(xTicksToWait != 0 && ticks == 0) return pdFALSE;
|
||||
|
||||
return pdTRUE;
|
||||
}
|
||||
|
||||
BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore) {
|
||||
if(xSemaphore == NULL) return pdFALSE;
|
||||
|
||||
if(xSemaphore->type == SemaphoreTypeMutex) {
|
||||
if(pthread_mutex_unlock(&xSemaphore->mutex) == 0) {
|
||||
return pdTRUE;
|
||||
} else {
|
||||
return pdFALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: need to add inter-process sync or use POSIX primitives
|
||||
xSemaphore->give_counter++;
|
||||
|
||||
return pdTRUE;
|
||||
}
|
||||
|
||||
#define TLS_ITEM_COUNT 1
|
||||
static pthread_key_t tls_keys[TLS_ITEM_COUNT];
|
||||
static pthread_once_t tls_keys_once = PTHREAD_ONCE_INIT;
|
||||
|
||||
static void create_tls_keys() {
|
||||
for(size_t i = 0; i < TLS_ITEM_COUNT; i++) {
|
||||
pthread_key_create(&tls_keys[i], NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void* pvTaskGetThreadLocalStoragePointer(TaskHandle_t xTaskToQuery, BaseType_t xIndex) {
|
||||
// Non-current task TLS access is not allowed
|
||||
if(xTaskToQuery != NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(xIndex >= TLS_ITEM_COUNT) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pthread_once(&tls_keys_once, create_tls_keys);
|
||||
|
||||
return pthread_getspecific(tls_keys[xIndex]);
|
||||
}
|
||||
|
||||
void vTaskSetThreadLocalStoragePointer(TaskHandle_t xTaskToSet, BaseType_t xIndex, void* pvValue) {
|
||||
// Non-current task TLS access is not allowed
|
||||
if(xTaskToSet != NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(xIndex >= TLS_ITEM_COUNT) {
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_once(&tls_keys_once, create_tls_keys);
|
||||
|
||||
pthread_setspecific(tls_keys[xIndex], pvValue);
|
||||
}
|
||||
|
||||
|
||||
osMutexId_t osMutexNew(const osMutexAttr_t *attr) {
|
||||
StaticSemaphore_t* pxMutexBuffer = malloc(sizeof(StaticSemaphore_t));
|
||||
xSemaphoreCreateMutexStatic(pxMutexBuffer);
|
||||
|
||||
return (osMutexId_t)pxMutexBuffer;
|
||||
}
|
||||
|
||||
osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout) {
|
||||
if(xSemaphoreTake((SemaphoreHandle_t)mutex_id, (TickType_t)timeout) == pdTRUE) {
|
||||
return osOK;
|
||||
} else {
|
||||
return osErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
osStatus_t osMutexRelease (osMutexId_t mutex_id) {
|
||||
if(xSemaphoreGive((SemaphoreHandle_t)mutex_id) == pdTRUE) {
|
||||
return osOK;
|
||||
} else {
|
||||
return osError;
|
||||
}
|
||||
}
|
||||
|
||||
osStatus_t osMutexDelete (osMutexId_t mutex_id) {
|
||||
osMutexRelease(mutex_id);
|
||||
|
||||
int res = 0;
|
||||
if((res = pthread_mutex_destroy(&mutex_id->mutex)) == 0) {
|
||||
return osOK;
|
||||
} else {
|
||||
printf("res = %d\n", res);
|
||||
return osError;
|
||||
}
|
||||
}
|
||||
|
||||
osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr) {
|
||||
if(max_count != 1) {
|
||||
// Non-binary semaphors are not supported at the moment
|
||||
return NULL;
|
||||
}
|
||||
if(attr != NULL) {
|
||||
// Attributes are not supported at the moment
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SemaphoreHandle_t handle = osMutexNew(NULL);
|
||||
if(handle == NULL) return NULL;
|
||||
|
||||
if(initial_count == 0) {
|
||||
xSemaphoreTake(handle, 0);
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout) {
|
||||
if(semaphore_id == NULL) {
|
||||
return osErrorParameter;
|
||||
}
|
||||
|
||||
if(xSemaphoreTake(semaphore_id, timeout) == pdTRUE) {
|
||||
return osOK;
|
||||
} else {
|
||||
return osErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id) {
|
||||
if(semaphore_id == NULL) {
|
||||
return osErrorParameter;
|
||||
}
|
||||
|
||||
if(xSemaphoreGive(semaphore_id) == pdTRUE) {
|
||||
return osOK;
|
||||
} else {
|
||||
return osErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id) {
|
||||
if(semaphore_id == NULL) {
|
||||
return osErrorParameter;
|
||||
}
|
||||
|
||||
return osMutexDelete(semaphore_id);
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
#include "heap.h"
|
||||
#include "errno.h"
|
||||
|
||||
/*
|
||||
Flipper devices inc.
|
||||
|
||||
Local fw build entry point.
|
||||
*/
|
||||
|
||||
int app();
|
||||
|
||||
int main() {
|
||||
// this function is not thread-safe, so it must be called in single thread context
|
||||
if(!prvHeapInit()){
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
return app();
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
#include "api-hal-delay.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void delay_us(float microseconds) {
|
||||
usleep(microseconds);
|
||||
}
|
||||
|
||||
void delay(float milliseconds) {
|
||||
usleep(milliseconds * 1000);
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
#include "api-hal-gpio.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// init GPIO
|
||||
void hal_gpio_init(
|
||||
const GpioPin* gpio,
|
||||
const GpioMode mode,
|
||||
const GpioPull pull,
|
||||
const GpioSpeed speed) {
|
||||
// TODO more mode
|
||||
if(gpio->pin != 0) {
|
||||
switch(mode) {
|
||||
case GpioModeInput:
|
||||
printf("[GPIO] %s%d input\n", gpio->port, gpio->pin);
|
||||
break;
|
||||
|
||||
case GpioModeOutputPushPull:
|
||||
printf("[GPIO] %s%d push pull\n", gpio->port, gpio->pin);
|
||||
break;
|
||||
|
||||
case GpioModeOutputOpenDrain:
|
||||
printf("[GPIO] %s%d open drain\n", gpio->port, gpio->pin);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("[GPIO] %s%d mode %d unsupported\n", gpio->port, gpio->pin, mode);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
printf("[GPIO] no pin\n");
|
||||
}
|
||||
}
|
||||
|
||||
// write value to GPIO, false = LOW, true = HIGH
|
||||
void hal_gpio_write(const GpioPin* gpio, const bool state) {
|
||||
if(gpio->pin != 0) {
|
||||
if(state) {
|
||||
printf("[GPIO] %s%d on\n", gpio->port, gpio->pin);
|
||||
} else {
|
||||
printf("[GPIO] %s%d off\n", gpio->port, gpio->pin);
|
||||
}
|
||||
} else {
|
||||
printf("[GPIO] no pin\n");
|
||||
}
|
||||
}
|
||||
|
||||
// read value from GPIO, false = LOW, true = HIGH
|
||||
bool hal_gpio_read(const GpioPin* gpio) {
|
||||
// TODO emulate pin state?
|
||||
return false;
|
||||
}
|
||||
|
||||
void enable_cc1101_irq() {
|
||||
printf("enable cc1101 irq\n");
|
||||
}
|
@@ -1,63 +0,0 @@
|
||||
#pragma once
|
||||
#include "main.h"
|
||||
#include "stdbool.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// hw-api
|
||||
|
||||
typedef char GPIO_TypeDef;
|
||||
|
||||
typedef enum {
|
||||
GpioModeInput,
|
||||
GpioModeOutputPushPull,
|
||||
GpioModeOutputOpenDrain,
|
||||
GpioModeAltFunctionPushPull,
|
||||
GpioModeAltFunctionOpenDrain,
|
||||
GpioModeAnalog,
|
||||
GpioModeInterruptRise,
|
||||
GpioModeInterruptFall,
|
||||
GpioModeInterruptRiseFall,
|
||||
GpioModeEventRise,
|
||||
GpioModeEventFall,
|
||||
GpioModeEventRiseFall,
|
||||
} GpioMode;
|
||||
|
||||
typedef enum {
|
||||
GpioSpeedLow,
|
||||
GpioSpeedMedium,
|
||||
GpioSpeedHigh,
|
||||
GpioSpeedVeryHigh,
|
||||
} GpioSpeed;
|
||||
|
||||
typedef enum {
|
||||
GpioPullNo,
|
||||
GpioPullUp,
|
||||
GpioPullDown,
|
||||
} GpioPull;
|
||||
|
||||
typedef struct {
|
||||
GPIO_TypeDef* port;
|
||||
uint16_t pin;
|
||||
} GpioPin;
|
||||
|
||||
// init GPIO
|
||||
void hal_gpio_init(
|
||||
const GpioPin* gpio,
|
||||
const GpioMode mode,
|
||||
const GpioPull pull,
|
||||
const GpioSpeed speed);
|
||||
|
||||
// write value to GPIO, false = LOW, true = HIGH
|
||||
void hal_gpio_write(const GpioPin* gpio, const bool state);
|
||||
|
||||
// read value from GPIO, false = LOW, true = HIGH
|
||||
bool hal_gpio_read(const GpioPin* gpio);
|
||||
|
||||
void enable_cc1101_irq();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -1,14 +0,0 @@
|
||||
#include "api-hal-task.h"
|
||||
|
||||
bool task_equal(TaskHandle_t a, TaskHandle_t b) {
|
||||
if(a == NULL || b == NULL) return false;
|
||||
return pthread_equal(*a, *b) != 0;
|
||||
}
|
||||
|
||||
bool task_is_isr_context(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void taskDISABLE_INTERRUPTS(void){
|
||||
// we cant disable main os sheduler
|
||||
};
|
@@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
#include "main.h"
|
||||
#include <cmsis_os.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Task stack size in bytes
|
||||
#define DEFAULT_STACK_SIZE 4096
|
||||
|
||||
// Max system tasks count
|
||||
#define MAX_TASK_COUNT 10
|
||||
|
||||
bool task_equal(TaskHandle_t a, TaskHandle_t b);
|
||||
bool task_is_isr_context(void);
|
||||
__attribute__((unused)) void taskDISABLE_INTERRUPTS(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "api-hal-gpio.h"
|
||||
#include "api-hal-delay.h"
|
||||
#include "flipper_hal.h"
|
@@ -1,56 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file fatfs.c
|
||||
* @brief Code for fatfs applications
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "fatfs.h"
|
||||
|
||||
uint8_t retUSER; /* Return value for USER */
|
||||
char USERPath[4]; /* USER logical drive path */
|
||||
FATFS USERFatFS; /* File system object for USER logical drive */
|
||||
FIL USERFile; /* File object for USER */
|
||||
|
||||
/* USER CODE BEGIN Variables */
|
||||
|
||||
/* USER CODE END Variables */
|
||||
|
||||
void MX_FATFS_Init(void)
|
||||
{
|
||||
/*## FatFS: Link the USER driver ###########################*/
|
||||
retUSER = FATFS_LinkDriver(&USER_Driver, USERPath);
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
/* additional user code for init */
|
||||
/* USER CODE END Init */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets Time from RTC
|
||||
* @param None
|
||||
* @retval Time in DWORD
|
||||
*/
|
||||
DWORD get_fattime(void)
|
||||
{
|
||||
/* USER CODE BEGIN get_fattime */
|
||||
return 0;
|
||||
/* USER CODE END get_fattime */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Application */
|
||||
|
||||
/* USER CODE END Application */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@@ -1,49 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file fatfs.h
|
||||
* @brief Header for fatfs applications
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __fatfs_H
|
||||
#define __fatfs_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "fatfs/ff.h"
|
||||
#include "fatfs/ff_gen_drv.h"
|
||||
#include "user_diskio.h" /* defines USER_Driver as external */
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern uint8_t retUSER; /* Return value for USER */
|
||||
extern char USERPath[4]; /* USER logical drive path */
|
||||
extern FATFS USERFatFS; /* File system object for USER logical drive */
|
||||
extern FIL USERFile; /* File object for USER */
|
||||
|
||||
void MX_FATFS_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*__fatfs_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@@ -1,269 +0,0 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* FatFs - Generic FAT file system module R0.12c (C)ChaN, 2017
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef _FFCONF
|
||||
#define _FFCONF 68300 /* Revision ID */
|
||||
|
||||
/*-----------------------------------------------------------------------------/
|
||||
/ Additional user header to be used
|
||||
/-----------------------------------------------------------------------------*/
|
||||
|
||||
#include "main.h"
|
||||
#include "cmsis_os.h" /* _FS_REENTRANT set to 1 and CMSIS API chosen */
|
||||
|
||||
/*-----------------------------------------------------------------------------/
|
||||
/ Function Configurations
|
||||
/-----------------------------------------------------------------------------*/
|
||||
|
||||
#define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */
|
||||
/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
|
||||
/ Read-only configuration removes writing API functions, f_write(), f_sync(),
|
||||
/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
|
||||
/ and optional writing functions as well. */
|
||||
|
||||
#define _FS_MINIMIZE 0 /* 0 to 3 */
|
||||
/* This option defines minimization level to remove some basic API functions.
|
||||
/
|
||||
/ 0: All basic functions are enabled.
|
||||
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
|
||||
/ are removed.
|
||||
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
|
||||
/ 3: f_lseek() function is removed in addition to 2. */
|
||||
|
||||
#define _USE_STRFUNC 2 /* 0:Disable or 1-2:Enable */
|
||||
/* This option switches string functions, f_gets(), f_putc(), f_puts() and
|
||||
/ f_printf().
|
||||
/
|
||||
/ 0: Disable string functions.
|
||||
/ 1: Enable without LF-CRLF conversion.
|
||||
/ 2: Enable with LF-CRLF conversion. */
|
||||
|
||||
#define _USE_FIND 0
|
||||
/* This option switches filtered directory read functions, f_findfirst() and
|
||||
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
|
||||
|
||||
#define _USE_MKFS 1
|
||||
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
|
||||
|
||||
#define _USE_FASTSEEK 1
|
||||
/* This option switches fast seek feature. (0:Disable or 1:Enable) */
|
||||
|
||||
#define _USE_EXPAND 0
|
||||
/* This option switches f_expand function. (0:Disable or 1:Enable) */
|
||||
|
||||
#define _USE_CHMOD 0
|
||||
/* This option switches attribute manipulation functions, f_chmod() and f_utime().
|
||||
/ (0:Disable or 1:Enable) Also _FS_READONLY needs to be 0 to enable this option. */
|
||||
|
||||
#define _USE_LABEL 1
|
||||
/* This option switches volume label functions, f_getlabel() and f_setlabel().
|
||||
/ (0:Disable or 1:Enable) */
|
||||
|
||||
#define _USE_FORWARD 0
|
||||
/* This option switches f_forward() function. (0:Disable or 1:Enable) */
|
||||
|
||||
/*-----------------------------------------------------------------------------/
|
||||
/ Locale and Namespace Configurations
|
||||
/-----------------------------------------------------------------------------*/
|
||||
|
||||
#define _CODE_PAGE 850
|
||||
/* This option specifies the OEM code page to be used on the target system.
|
||||
/ Incorrect setting of the code page can cause a file open failure.
|
||||
/
|
||||
/ 1 - ASCII (No extended character. Non-LFN cfg. only)
|
||||
/ 437 - U.S.
|
||||
/ 720 - Arabic
|
||||
/ 737 - Greek
|
||||
/ 771 - KBL
|
||||
/ 775 - Baltic
|
||||
/ 850 - Latin 1
|
||||
/ 852 - Latin 2
|
||||
/ 855 - Cyrillic
|
||||
/ 857 - Turkish
|
||||
/ 860 - Portuguese
|
||||
/ 861 - Icelandic
|
||||
/ 862 - Hebrew
|
||||
/ 863 - Canadian French
|
||||
/ 864 - Arabic
|
||||
/ 865 - Nordic
|
||||
/ 866 - Russian
|
||||
/ 869 - Greek 2
|
||||
/ 932 - Japanese (DBCS)
|
||||
/ 936 - Simplified Chinese (DBCS)
|
||||
/ 949 - Korean (DBCS)
|
||||
/ 950 - Traditional Chinese (DBCS)
|
||||
*/
|
||||
|
||||
#define _USE_LFN 2 /* 0 to 3 */
|
||||
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
|
||||
/* The _USE_LFN switches the support of long file name (LFN).
|
||||
/
|
||||
/ 0: Disable support of LFN. _MAX_LFN has no effect.
|
||||
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
|
||||
/ 2: Enable LFN with dynamic working buffer on the STACK.
|
||||
/ 3: Enable LFN with dynamic working buffer on the HEAP.
|
||||
/
|
||||
/ To enable the LFN, Unicode handling functions (option/unicode.c) must be added
|
||||
/ to the project. The working buffer occupies (_MAX_LFN + 1) * 2 bytes and
|
||||
/ additional 608 bytes at exFAT enabled. _MAX_LFN can be in range from 12 to 255.
|
||||
/ It should be set 255 to support full featured LFN operations.
|
||||
/ When use stack for the working buffer, take care on stack overflow. When use heap
|
||||
/ memory for the working buffer, memory management functions, ff_memalloc() and
|
||||
/ ff_memfree(), must be added to the project. */
|
||||
|
||||
#define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
|
||||
/* This option switches character encoding on the API. (0:ANSI/OEM or 1:UTF-16)
|
||||
/ To use Unicode string for the path name, enable LFN and set _LFN_UNICODE = 1.
|
||||
/ This option also affects behavior of string I/O functions. */
|
||||
|
||||
#define _STRF_ENCODE 3
|
||||
/* When _LFN_UNICODE == 1, this option selects the character encoding ON THE FILE to
|
||||
/ be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
|
||||
/
|
||||
/ 0: ANSI/OEM
|
||||
/ 1: UTF-16LE
|
||||
/ 2: UTF-16BE
|
||||
/ 3: UTF-8
|
||||
/
|
||||
/ This option has no effect when _LFN_UNICODE == 0. */
|
||||
|
||||
#define _FS_RPATH 0 /* 0 to 2 */
|
||||
/* This option configures support of relative path.
|
||||
/
|
||||
/ 0: Disable relative path and remove related functions.
|
||||
/ 1: Enable relative path. f_chdir() and f_chdrive() are available.
|
||||
/ 2: f_getcwd() function is available in addition to 1.
|
||||
*/
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Drive/Volume Configurations
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
#define _VOLUMES 1
|
||||
/* Number of volumes (logical drives) to be used. */
|
||||
|
||||
/* USER CODE BEGIN Volumes */
|
||||
#define _STR_VOLUME_ID 0 /* 0:Use only 0-9 for drive ID, 1:Use strings for drive ID */
|
||||
#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
|
||||
/* _STR_VOLUME_ID switches string support of volume ID.
|
||||
/ When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
|
||||
/ number in the path name. _VOLUME_STRS defines the drive ID strings for each
|
||||
/ logical drives. Number of items must be equal to _VOLUMES. Valid characters for
|
||||
/ the drive ID strings are: A-Z and 0-9. */
|
||||
/* USER CODE END Volumes */
|
||||
|
||||
#define _MULTI_PARTITION 0 /* 0:Single partition, 1:Multiple partition */
|
||||
/* This option switches support of multi-partition on a physical drive.
|
||||
/ By default (0), each logical drive number is bound to the same physical drive
|
||||
/ number and only an FAT volume found on the physical drive will be mounted.
|
||||
/ When multi-partition is enabled (1), each logical drive number can be bound to
|
||||
/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
|
||||
/ funciton will be available. */
|
||||
#define _MIN_SS 512 /* 512, 1024, 2048 or 4096 */
|
||||
#define _MAX_SS 4096 /* 512, 1024, 2048 or 4096 */
|
||||
/* These options configure the range of sector size to be supported. (512, 1024,
|
||||
/ 2048 or 4096) Always set both 512 for most systems, all type of memory cards and
|
||||
/ harddisk. But a larger value may be required for on-board flash memory and some
|
||||
/ type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured
|
||||
/ to variable sector size and GET_SECTOR_SIZE command must be implemented to the
|
||||
/ disk_ioctl() function. */
|
||||
|
||||
#define _USE_TRIM 0
|
||||
/* This option switches support of ATA-TRIM. (0:Disable or 1:Enable)
|
||||
/ To enable Trim function, also CTRL_TRIM command should be implemented to the
|
||||
/ disk_ioctl() function. */
|
||||
|
||||
#define _FS_NOFSINFO 0 /* 0,1,2 or 3 */
|
||||
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
|
||||
/ option, and f_getfree() function at first time after volume mount will force
|
||||
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
|
||||
/
|
||||
/ bit0=0: Use free cluster count in the FSINFO if available.
|
||||
/ bit0=1: Do not trust free cluster count in the FSINFO.
|
||||
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
|
||||
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
|
||||
*/
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ System Configurations
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
#define _FS_TINY 1 /* 0:Normal or 1:Tiny */
|
||||
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
|
||||
/ At the tiny configuration, size of file object (FIL) is reduced _MAX_SS bytes.
|
||||
/ Instead of private sector buffer eliminated from the file object, common sector
|
||||
/ buffer in the file system object (FATFS) is used for the file data transfer. */
|
||||
|
||||
#define _FS_EXFAT 1
|
||||
/* This option switches support of exFAT file system. (0:Disable or 1:Enable)
|
||||
/ When enable exFAT, also LFN needs to be enabled. (_USE_LFN >= 1)
|
||||
/ Note that enabling exFAT discards C89 compatibility. */
|
||||
|
||||
#define _FS_NORTC 0
|
||||
#define _NORTC_MON 6
|
||||
#define _NORTC_MDAY 4
|
||||
#define _NORTC_YEAR 2015
|
||||
/* The option _FS_NORTC switches timestamp functiton. If the system does not have
|
||||
/ any RTC function or valid timestamp is not needed, set _FS_NORTC = 1 to disable
|
||||
/ the timestamp function. All objects modified by FatFs will have a fixed timestamp
|
||||
/ defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR in local time.
|
||||
/ To enable timestamp function (_FS_NORTC = 0), get_fattime() function need to be
|
||||
/ added to the project to get current time form real-time clock. _NORTC_MON,
|
||||
/ _NORTC_MDAY and _NORTC_YEAR have no effect.
|
||||
/ These options have no effect at read-only configuration (_FS_READONLY = 1). */
|
||||
|
||||
#define _FS_LOCK 2 /* 0:Disable or >=1:Enable */
|
||||
/* The option _FS_LOCK switches file lock function to control duplicated file open
|
||||
/ and illegal operation to open objects. This option must be 0 when _FS_READONLY
|
||||
/ is 1.
|
||||
/
|
||||
/ 0: Disable file lock function. To avoid volume corruption, application program
|
||||
/ should avoid illegal open, remove and rename to the open objects.
|
||||
/ >0: Enable file lock function. The value defines how many files/sub-directories
|
||||
/ can be opened simultaneously under file lock control. Note that the file
|
||||
/ lock control is independent of re-entrancy. */
|
||||
|
||||
#define _FS_REENTRANT 1 /* 0:Disable or 1:Enable */
|
||||
#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */
|
||||
#define _SYNC_t SemaphoreHandle_t
|
||||
/* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
|
||||
/ module itself. Note that regardless of this option, file access to different
|
||||
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
|
||||
/ and f_fdisk() function, are always not re-entrant. Only file/directory access
|
||||
/ to the same volume is under control of this function.
|
||||
/
|
||||
/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
|
||||
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
|
||||
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
|
||||
/ function, must be added to the project. Samples are available in
|
||||
/ option/syscall.c.
|
||||
/
|
||||
/ The _FS_TIMEOUT defines timeout period in unit of time tick.
|
||||
/ The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
|
||||
/ SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be
|
||||
/ included somewhere in the scope of ff.h. */
|
||||
|
||||
/* define the ff_malloc ff_free macros as standard malloc free */
|
||||
#if !defined(ff_malloc) && !defined(ff_free)
|
||||
#include <stdlib.h>
|
||||
#define ff_malloc malloc
|
||||
#define ff_free free
|
||||
#endif
|
||||
|
||||
#endif /* _FFCONF */
|
@@ -1,119 +0,0 @@
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Sample code of OS dependent controls for FatFs */
|
||||
/* (C)ChaN, 2014 */
|
||||
/* Portions COPYRIGHT 2017 STMicroelectronics */
|
||||
/* Portions Copyright (C) 2014, ChaN, all right reserved */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics. All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
**/
|
||||
|
||||
#include "fatfs/ff.h"
|
||||
|
||||
#if _FS_REENTRANT
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Create a Synchronization Object */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called in f_mount() function to create a new
|
||||
/ synchronization object, such as semaphore and mutex. When a 0 is returned,
|
||||
/ the f_mount() function fails with FR_INT_ERR.
|
||||
*/
|
||||
|
||||
int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
|
||||
BYTE vol, /* Corresponding volume (logical drive number) */
|
||||
_SYNC_t *sobj /* Pointer to return the created sync object */
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Delete a Synchronization Object */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called in f_mount() function to delete a synchronization
|
||||
/ object that created with ff_cre_syncobj() function. When a 0 is returned,
|
||||
/ the f_mount() function fails with FR_INT_ERR.
|
||||
*/
|
||||
|
||||
int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any error */
|
||||
_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Request Grant to Access the Volume */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called on entering file functions to lock the volume.
|
||||
/ When a 0 is returned, the file function fails with FR_TIMEOUT.
|
||||
*/
|
||||
|
||||
int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
|
||||
_SYNC_t sobj /* Sync object to wait */
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Release Grant to Access the Volume */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called on leaving file functions to unlock the volume.
|
||||
*/
|
||||
|
||||
void ff_rel_grant (
|
||||
_SYNC_t sobj /* Sync object to be signaled */
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#if _USE_LFN == 3 /* LFN with a working buffer on the heap */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Allocate a memory block */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.
|
||||
*/
|
||||
|
||||
void* ff_memalloc ( /* Returns pointer to the allocated memory block */
|
||||
UINT msize /* Number of bytes to allocate */
|
||||
)
|
||||
{
|
||||
return ff_malloc(msize); /* Allocate a new memory block with POSIX API */
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Free a memory block */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
void ff_memfree (
|
||||
void* mblock /* Pointer to the memory block to free */
|
||||
)
|
||||
{
|
||||
ff_free(mblock); /* Discard the memory block with POSIX API */
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,219 +0,0 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file user_diskio.c
|
||||
* @brief This file includes a diskio driver skeleton to be completed by the user.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifdef USE_OBSOLETE_USER_CODE_SECTION_0
|
||||
/*
|
||||
* Warning: the user section 0 is no more in use (starting from CubeMx version 4.16.0)
|
||||
* To be suppressed in the future.
|
||||
* Kept to ensure backward compatibility with previous CubeMx versions when
|
||||
* migrating projects.
|
||||
* User code previously added there should be copied in the new user sections before
|
||||
* the section contents can be deleted.
|
||||
*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
/* USER CODE END 0 */
|
||||
#endif
|
||||
|
||||
/* USER CODE BEGIN DECL */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "user_diskio.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Disk status */
|
||||
static volatile DSTATUS Stat = STA_NOINIT;
|
||||
|
||||
static DSTATUS User_CheckStatus(BYTE lun) {
|
||||
Stat = STA_NOINIT;
|
||||
|
||||
if(BSP_SD_GetCardState() == MSD_OK) {
|
||||
Stat &= ~STA_NOINIT;
|
||||
}
|
||||
|
||||
return Stat;
|
||||
}
|
||||
/* USER CODE END DECL */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
DSTATUS USER_initialize(BYTE pdrv);
|
||||
DSTATUS USER_status(BYTE pdrv);
|
||||
DRESULT USER_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT USER_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT USER_ioctl(BYTE pdrv, BYTE cmd, void* buff);
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
|
||||
Diskio_drvTypeDef USER_Driver = {
|
||||
USER_initialize,
|
||||
USER_status,
|
||||
USER_read,
|
||||
#if _USE_WRITE
|
||||
USER_write,
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
#if _USE_IOCTL == 1
|
||||
USER_ioctl,
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Initializes a Drive
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS USER_initialize(BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
) {
|
||||
/* USER CODE BEGIN INIT */
|
||||
return User_CheckStatus(pdrv);
|
||||
/* USER CODE END INIT */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets Disk Status
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS USER_status(BYTE pdrv /* Physical drive number to identify the drive */
|
||||
) {
|
||||
/* USER CODE BEGIN STATUS */
|
||||
return Stat;
|
||||
/* USER CODE END STATUS */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads Sector(s)
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @param *buff: Data buffer to store read data
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to read (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
DRESULT USER_read(
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
BYTE* buff, /* Data buffer to store read data */
|
||||
DWORD sector, /* Sector address in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
) {
|
||||
/* USER CODE BEGIN READ */
|
||||
DRESULT res = RES_ERROR;
|
||||
if(BSP_SD_ReadBlocks((uint32_t*)buff, (uint32_t)(sector), count, SD_DATATIMEOUT) == MSD_OK) {
|
||||
/* wait until the read operation is finished */
|
||||
while(BSP_SD_GetCardState() != MSD_OK) {
|
||||
}
|
||||
res = RES_OK;
|
||||
}
|
||||
|
||||
return res;
|
||||
/* USER CODE END READ */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes Sector(s)
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @param *buff: Data to be written
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to write (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT USER_write(
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
const BYTE* buff, /* Data to be written */
|
||||
DWORD sector, /* Sector address in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
) {
|
||||
/* USER CODE BEGIN WRITE */
|
||||
/* USER CODE HERE */
|
||||
DRESULT res = RES_ERROR;
|
||||
|
||||
if(BSP_SD_WriteBlocks((uint32_t*)buff, (uint32_t)(sector), count, SD_DATATIMEOUT) == MSD_OK) {
|
||||
/* wait until the Write operation is finished */
|
||||
while(BSP_SD_GetCardState() != MSD_OK) {
|
||||
}
|
||||
res = RES_OK;
|
||||
}
|
||||
|
||||
return res;
|
||||
/* USER CODE END WRITE */
|
||||
}
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
|
||||
/**
|
||||
* @brief I/O control operation
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @param cmd: Control code
|
||||
* @param *buff: Buffer to send/receive control data
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT USER_ioctl(
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void* buff /* Buffer to send/receive control data */
|
||||
) {
|
||||
/* USER CODE BEGIN IOCTL */
|
||||
DRESULT res = RES_ERROR;
|
||||
BSP_SD_CardInfo CardInfo;
|
||||
|
||||
if(Stat & STA_NOINIT) return RES_NOTRDY;
|
||||
|
||||
switch(cmd) {
|
||||
/* Make sure that no pending write process */
|
||||
case CTRL_SYNC:
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
/* Get number of sectors on the disk (DWORD) */
|
||||
case GET_SECTOR_COUNT:
|
||||
BSP_SD_GetCardInfo(&CardInfo);
|
||||
*(DWORD*)buff = CardInfo.LogBlockNbr;
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
/* Get R/W sector size (WORD) */
|
||||
case GET_SECTOR_SIZE:
|
||||
BSP_SD_GetCardInfo(&CardInfo);
|
||||
*(WORD*)buff = CardInfo.LogBlockSize;
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
/* Get erase block size in unit of sector (DWORD) */
|
||||
case GET_BLOCK_SIZE:
|
||||
BSP_SD_GetCardInfo(&CardInfo);
|
||||
*(DWORD*)buff = CardInfo.LogBlockSize;
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
default:
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
return res;
|
||||
/* USER CODE END IOCTL */
|
||||
}
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@@ -1,47 +0,0 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file user_diskio.h
|
||||
* @brief This file contains the common defines and functions prototypes for
|
||||
* the user_diskio driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USER_DISKIO_H
|
||||
#define __USER_DISKIO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "fatfs/ff_gen_drv.h"
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
extern Diskio_drvTypeDef USER_Driver;
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USER_DISKIO_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@@ -1,25 +0,0 @@
|
||||
TOOLCHAIN = x86
|
||||
|
||||
# Sources
|
||||
C_SOURCES += $(TARGET_DIR)/Src/main.c
|
||||
C_SOURCES += $(TARGET_DIR)/Src/flipper_hal.c
|
||||
C_SOURCES += $(TARGET_DIR)/Src/lo_os.c
|
||||
C_SOURCES += $(TARGET_DIR)/Src/lo_hal.c
|
||||
|
||||
# CFLAGS += -DFURI_DEBUG
|
||||
CFLAGS += -I$(TARGET_DIR)/Inc
|
||||
CFLAGS += -Wall -fdata-sections -ffunction-sections -pthread
|
||||
LDFLAGS += -pthread
|
||||
|
||||
# FatFs library
|
||||
CFLAGS += -I$(TARGET_DIR)/fatfs
|
||||
C_SOURCES += $(TARGET_DIR)/fatfs/syscall.c
|
||||
|
||||
# memory manager
|
||||
C_SOURCES += $(TARGET_DIR)/Src/heap_4.c
|
||||
|
||||
CFLAGS += -I$(TARGET_DIR)/api-hal
|
||||
C_SOURCES += $(wildcard $(TARGET_DIR)/api-hal/*.c)
|
||||
|
||||
run: all
|
||||
$(OBJ_DIR)/$(PROJECT).elf
|
Reference in New Issue
Block a user