Skip to content

chore: update to stm32_mw_fatfs v4.0.0 #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2015, ChaN, all right reserved.
# Copyright (c) 2019 STMicroelectronics.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 changes: 0 additions & 21 deletions Licence.md

This file was deleted.

49 changes: 49 additions & 0 deletions ffsystem/ffsystem_baremetal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
******************************************************************************
* @file ffsystem_baremetal.c
* @author MCD Application Team
* @brief ffsystem baremetal functions implementation
******************************************************************************
* @attention
*
* Copyright (C) 2018, ChaN, all right reserved
* Copyright (c) 2023 STMicroelectronics
� *
� * This software is licensed under terms that can be found in the LICENSE file
� * in the root directory of this software component.
� * If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/

/* Includes -------------------------------------------------------------*/
#include "ff.h"
#include <stdlib.h>

#if FF_FS_REENTRANT
#error "The flag FF_FS_REENTRANT should be set to 0"
#endif

/* Dynamic memory allocation */
#if FF_USE_LFN == 3

/*------------------------------------------------------------------------*/
/* Allocate a memory block */
/*------------------------------------------------------------------------*/

void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
UINT msize /* Number of bytes to allocate */
)
{
return malloc((size_t)msize); /* Allocate a new memory block */
}


void ff_memfree (
void* mblock /* Pointer to the memory block to free (no effect if null) */
)
{
free(mblock); /* Free the memory block */
}

#endif
151 changes: 151 additions & 0 deletions ffsystem/ffsystem_cmsis_os.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/**
******************************************************************************
* @file ffsystem_cmsis_os.c
* @author MCD Application Team
* @brief ffsystem cmsis_os functions implementation
******************************************************************************
* @attention
*
* Copyright (C) 2018, ChaN, all right reserved
* Copyright (c) 2023 STMicroelectronics
� *
� * This software is licensed under terms that can be found in the LICENSE file
� * in the root directory of this software component.
� * If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/

/* Includes -------------------------------------------------------------*/
#include "ff.h"

#if FF_USE_LFN == 3
#include "FreeRTOS.h"
#endif

#if FF_FS_REENTRANT
#include "cmsis_os2.h"
#endif

/* Dynamic memory allocation */
#if FF_USE_LFN == 3

/*------------------------------------------------------------------------*/
/* Allocate/Free a Memory Block */
/*------------------------------------------------------------------------*/

void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
UINT msize /* Number of bytes to allocate */
)
{
return (void *) pvPortMalloc((size_t)msize); /* Allocate a new memory block */
}


/*------------------------------------------------------------------------*/
/* Free a memory block */
/*------------------------------------------------------------------------*/

void ff_memfree (
void* mblock /* Pointer to the memory block to free (no effect if null) */
)
{
vPortFree(mblock); /* Free the memory block */
}

#endif


/* Mutal exclusion */
#if FF_FS_REENTRANT

/* Definition table of Mutex */
static osMutexId_t Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */

/*------------------------------------------------------------------------*/
/* Create a Mutex */
/*------------------------------------------------------------------------*/
/* This function is called in f_mount function to create a new mutex
/ or semaphore for the volume. When a 0 is returned, the f_mount function
/ fails with FR_INT_ERR.
*/

int ff_mutex_create ( /* Returns 1:Function succeeded or 0:Could not create the mutex */
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
)
{
int ret;
const osMutexAttr_t attr = {
"FatFsMutex",
osMutexRecursive,
NULL,
0U
};

Mutex[vol] = osMutexNew(&attr);
if (Mutex[vol] != NULL)
{
ret = 1;
}
else
{
ret = 0;
}

return ret;
}


/*------------------------------------------------------------------------*/
/* Delete a Mutex */
/*------------------------------------------------------------------------*/
/* This function is called in f_mount function to delete a mutex or
/ semaphore of the volume created with ff_mutex_create function.
*/

void ff_mutex_delete ( /* Returns 1:Function succeeded or 0:Could not delete due to an error */
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
)
{
osMutexDelete(Mutex[vol]);
}


/*------------------------------------------------------------------------*/
/* Request a Grant to Access the Volume */
/*------------------------------------------------------------------------*/
/* This function is called on enter file functions to lock the volume.
/ When a 0 is returned, the file function fails with FR_TIMEOUT.
*/

int ff_mutex_take ( /* Returns 1:Succeeded or 0:Timeout */
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
)
{
int ret;

if(osMutexAcquire(Mutex[vol], FF_FS_TIMEOUT) == osOK)
{
ret = 1;
}
else
{
ret = 0;
}

return ret;
}

/*------------------------------------------------------------------------*/
/* Release a Grant to Access the Volume */
/*------------------------------------------------------------------------*/
/* This function is called on leave file functions to unlock the volume.
*/

void ff_mutex_give (
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
)
{
osMutexRelease(Mutex[vol]);
}
#endif
99 changes: 99 additions & 0 deletions ffsystem/ffsystem_template.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*------------------------------------------------------------------------*/
/* A Sample Code of User Provided OS Dependent Functions for FatFs */
/*------------------------------------------------------------------------*/

#include "ff.h"


#if FF_USE_LFN == 3 /* Use dynamic memory allocation */

/*------------------------------------------------------------------------*/
/* Allocate/Free a Memory Block */
/*------------------------------------------------------------------------*/


void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
UINT msize /* Number of bytes to allocate */
)
{
void* mem_ptr = NULL; /* Memory block to be allocated */

return mem_ptr;
}


void ff_memfree (
void* mblock /* Pointer to the memory block to free (no effect if null) */
)
{
free(mblock); /* Free the memory block */
}

#endif




#if FF_FS_REENTRANT /* Mutal exclusion */
/*------------------------------------------------------------------------*/
/* Create a Mutex */
/*------------------------------------------------------------------------*/
/* This function is called in f_mount function to create a new mutex
/ or semaphore for the volume. When a 0 is returned, the f_mount function
/ fails with FR_INT_ERR.
*/

int ff_mutex_create ( /* Returns 1:Function succeeded or 0:Could not create the mutex */
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
)
{
return 1;
}


/*------------------------------------------------------------------------*/
/* Delete a Mutex */
/*------------------------------------------------------------------------*/
/* This function is called in f_mount function to delete a mutex or
/ semaphore of the volume created with ff_mutex_create function.
*/

void ff_mutex_delete ( /* Returns 1:Function succeeded or 0:Could not delete due to an error */
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
)
{
return 1;
}


/*------------------------------------------------------------------------*/
/* Request a Grant to Access the Volume */
/*------------------------------------------------------------------------*/
/* This function is called on enter file functions to lock the volume.
/ When a 0 is returned, the file function fails with FR_TIMEOUT.
*/

int ff_mutex_take ( /* Returns 1:Succeeded or 0:Timeout */
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
)
{
return 1;
}



/*------------------------------------------------------------------------*/
/* Release a Grant to Access the Volume */
/*------------------------------------------------------------------------*/
/* This function is called on leave file functions to unlock the volume.
*/

void ff_mutex_give (
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
)
{
return 1;
}

#endif /* FF_FS_REENTRANT */

Loading