Skip to content

Commit 6e25d95

Browse files
author
Daniel Campora
committed
cc3200: Enable long filename support in FatFS.
This has implications all over the place. I have to admit that you can instantly see that usability improves, but it costs 3K. At the same time I took the oportunity to rename the '/SFLASH' drive to '/flash' which improves compatibility with the pyboard.
1 parent d35ac95 commit 6e25d95

13 files changed

Lines changed: 154 additions & 82 deletions

File tree

cc3200/FreeRTOS/FreeRTOSConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
#define configUSE_TICK_HOOK 1
8484
#define configCPU_CLOCK_HZ ( ( unsigned long ) 80000000 )
8585
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
86-
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 72 )
86+
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 64 )
8787
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 16384 ) )
8888
#define configMAX_TASK_NAME_LEN ( 8 )
8989
#define configUSE_TRACE_FACILITY 0

cc3200/application.mk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ APP_MAIN_SRC_C = \
139139
serverstask.c
140140

141141
APP_LIB_SRC_C = $(addprefix lib/,\
142-
libc/string0.c \
143142
fatfs/ff.c \
143+
fatfs/option/ccsbcs.c \
144+
libc/string0.c \
144145
mp-readline/readline.c \
145146
)
146147

@@ -206,7 +207,7 @@ endif
206207
SHELL = bash
207208
APP_SIGN = appsign.sh
208209

209-
all: $(BUILD)/MCUIMG.BIN
210+
all: $(BUILD)/mcuimg.bin
210211

211212
$(BUILD)/application.axf: $(OBJ) $(LINKER_SCRIPT)
212213
$(ECHO) "LINK $@"
@@ -217,7 +218,7 @@ $(BUILD)/application.bin: $(BUILD)/application.axf
217218
$(ECHO) "Create $@"
218219
$(Q)$(OBJCOPY) -O binary $< $@
219220

220-
$(BUILD)/MCUIMG.BIN: $(BUILD)/application.bin
221+
$(BUILD)/mcuimg.bin: $(BUILD)/application.bin
221222
$(ECHO) "Create $@"
222223
$(Q)$(SHELL) $(APP_SIGN) $(BOARD) $(BTYPE)
223224

cc3200/appsign.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ BUILD=build/${BOARD}/${BTYPE}
1616
echo -n `md5sum --binary $BUILD/application.bin | awk '{ print $1 }'` > __md5hash.bin
1717

1818
# Concatenate it with the application binary
19-
cat $BUILD/application.bin __md5hash.bin > $BUILD/MCUIMG.BIN
19+
cat $BUILD/application.bin __md5hash.bin > $BUILD/mcuimg.bin
2020
RET=$?
2121

2222
# Remove the tmp files
2323
rm -f __md5hash.bin
2424

25-
# Remove hte unsigned binary
25+
# Remove the unsigned binary
2626
rm -f $BUILD/application.bin
2727

2828
exit $RET

cc3200/fatfs/src/ffconf.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ extern BYTE ff_CurrVol;
3838
#endif
3939

4040
STATIC bool check_path(const TCHAR **path, const char *mount_point_str, mp_uint_t mount_point_len) {
41-
stoupper ((char *)(*path));
4241
if (strncmp(*path, mount_point_str, mount_point_len) == 0) {
4342
if ((*path)[mount_point_len] == '/') {
4443
*path += mount_point_len;
@@ -66,11 +65,11 @@ int ff_get_ldnumber (const TCHAR **path) {
6665
#endif
6766
}
6867

69-
if (check_path(path, "/SFLASH", 7)) {
68+
if (check_path(path, "/flash", 6)) {
7069
return 0;
7170
}
7271
#if MICROPY_HW_HAS_SDCARD
73-
else if (check_path(path, "/SD", 3)) {
72+
else if (check_path(path, "/sd", 3)) {
7473
return 1;
7574
}
7675
#endif
@@ -84,13 +83,13 @@ void ff_get_volname(BYTE vol, TCHAR **dest) {
8483
if (vol == 0)
8584
#endif
8685
{
87-
memcpy(*dest, "/SFLASH", 7);
86+
memcpy(*dest, "/flash", 6);
8887
*dest += 7;
8988
}
9089
#if MICROPY_HW_HAS_SDCARD
9190
else
9291
{
93-
memcpy(*dest, "/SD", 3);
92+
memcpy(*dest, "/sd", 3);
9493
*dest += 3;
9594
}
9695
#endif

cc3200/fatfs/src/option/syscall.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
/* (C)ChaN, 2014 */
44
/*------------------------------------------------------------------------*/
55

6-
#include "py/mpconfig.h"
7-
#include MICROPY_HAL_H
86
#include "ff.h"
97

108

@@ -134,7 +132,7 @@ void* ff_memalloc ( /* Returns pointer to the allocated memory block */
134132
UINT msize /* Number of bytes to allocate */
135133
)
136134
{
137-
return malloc(msize); /* Allocate a new memory block with POSIX API */
135+
return pvPortMalloc(msize); /* Allocate a new memory block with POSIX API */
138136
}
139137

140138

@@ -146,7 +144,7 @@ void ff_memfree (
146144
void* mblock /* Pointer to the memory block to free */
147145
)
148146
{
149-
free(mblock); /* Discard the memory block with POSIX API */
147+
vPortFree(mblock); /* Discard the memory block with POSIX API */
150148
}
151149

152150
#endif

cc3200/ftp/ftp.c

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -301,19 +301,21 @@ void ftp_run (void) {
301301
if (SOCKETFIFO_IsEmpty()) {
302302
uint32_t readsize;
303303
ftp_result_t result;
304+
ftp_data.ctimeout = 0;
304305
result = ftp_read_file ((char *)ftp_data.dBuffer, FTP_BUFFER_SIZE, &readsize);
305-
if (readsize > 0 && result != E_FTP_RESULT_FAILED) {
306-
ftp_send_data(readsize);
307-
ftp_data.ctimeout = 0;
306+
if (result == E_FTP_RESULT_FAILED) {
307+
ftp_send_reply(451, NULL);
308+
ftp_data.state = E_FTP_STE_END_TRANSFER;
309+
}
310+
else {
311+
if (readsize > 0) {
312+
ftp_send_data(readsize);
313+
}
308314
if (result == E_FTP_RESULT_OK) {
309315
ftp_send_reply(226, NULL);
310316
ftp_data.state = E_FTP_STE_END_TRANSFER;
311317
}
312318
}
313-
else {
314-
ftp_send_reply(451, NULL);
315-
ftp_data.state = E_FTP_STE_END_TRANSFER;
316-
}
317319
}
318320
break;
319321
case E_FTP_STE_CONTINUE_FILE_RX:
@@ -588,8 +590,12 @@ static void ftp_process_cmd (void) {
588590
char *bufptr = (char *)ftp_cmd_buffer;
589591
ftp_result_t result;
590592
uint32_t listsize;
591-
FILINFO fno;
592593
FRESULT fres;
594+
FILINFO fno;
595+
#if _USE_LFN
596+
fno.lfname = NULL;
597+
fno.lfsize = 0;
598+
#endif
593599

594600
ftp_data.closechild = false;
595601
// also use the reply buffer to receive new commands
@@ -887,12 +893,20 @@ static int ftp_print_eplf_item (char *dest, uint32_t destsize, FILINFO *fno) {
887893
if (FTP_UNIX_SECONDS_180_DAYS < tseconds - fseconds) {
888894
return snprintf(dest, destsize, "%srw-rw-r-- 1 root root %9u %s %2u %5u %s\r\n",
889895
type, (_u32)fno->fsize, ftp_month[mindex].month, day,
896+
#if _USE_LFN
897+
1980 + ((fno->fdate >> 9) & 0x7f), *fno->lfname ? fno->lfname : fno->fname);
898+
#else
890899
1980 + ((fno->fdate >> 9) & 0x7f), fno->fname);
900+
#endif
891901
}
892902
else {
893903
return snprintf(dest, destsize, "%srw-rw-r-- 1 root root %9u %s %2u %02u:%02u %s\r\n",
894904
type, (_u32)fno->fsize, ftp_month[mindex].month, day,
905+
#if _USE_LFN
906+
(fno->ftime >> 11) & 0x1f, (fno->ftime >> 5) & 0x3f, *fno->lfname ? fno->lfname : fno->fname);
907+
#else
895908
(fno->ftime >> 11) & 0x1f, (fno->ftime >> 5) & 0x3f, fno->fname);
909+
#endif
896910
}
897911
}
898912

@@ -956,10 +970,10 @@ static ftp_result_t ftp_open_dir_for_listing (const char *path, char *list, uint
956970
uint next = 0;
957971
// "hack" to list root directory
958972
if (path[0] == '/' && path[1] == '\0') {
959-
next += ftp_print_eplf_drive((list + next), (maxlistsize - next), "SFLASH");
973+
next += ftp_print_eplf_drive((list + next), (maxlistsize - next), "flash");
960974
#if MICROPY_HW_HAS_SDCARD
961975
if (sd_disk_ready()) {
962-
next += ftp_print_eplf_drive((list + next), (maxlistsize - next), "SD");
976+
next += ftp_print_eplf_drive((list + next), (maxlistsize - next), "sd");
963977
}
964978
#endif
965979
*listsize = next;
@@ -979,11 +993,18 @@ static ftp_result_t ftp_list_dir (char *list, uint32_t maxlistsize, uint32_t *li
979993
uint next = 0;
980994
uint count = 0;
981995
FRESULT res;
982-
FILINFO fno;
983996
ftp_result_t result = E_FTP_RESULT_CONTINUE;
984-
985-
/* read up to 4 directory items */
986-
while (count++ < 4) {
997+
FILINFO fno;
998+
#if _USE_LFN
999+
fno.lfname = mem_Malloc(_MAX_LFN);
1000+
fno.lfsize = _MAX_LFN;
1001+
1002+
// read up to 2 directory items
1003+
while (count < 2) {
1004+
#else
1005+
// read up to 4 directory items
1006+
while (count < 4) {
1007+
#endif
9871008
res = f_readdir(&ftp_data.dp, &fno); /* Read a directory item */
9881009
if (res != FR_OK || fno.fname[0] == 0) {
9891010
result = E_FTP_RESULT_OK;
@@ -992,13 +1013,17 @@ static ftp_result_t ftp_list_dir (char *list, uint32_t maxlistsize, uint32_t *li
9921013
if (fno.fname[0] == '.' && fno.fname[1] == 0) continue; /* Ignore . entry */
9931014
if (fno.fname[0] == '.' && fno.fname[1] == '.' && fno.fname[2] == 0) continue; /* Ignore .. entry */
9941015

995-
// Add the entry to the list
1016+
// add the entry to the list
9961017
next += ftp_print_eplf_item((list + next), (maxlistsize - next), &fno);
1018+
count++;
9971019
}
9981020
if (result == E_FTP_RESULT_OK) {
9991021
ftp_close_files();
10001022
}
10011023
*listsize = next;
1024+
#if _USE_LFN
1025+
mem_Free(fno.lfname);
1026+
#endif
10021027
return result;
10031028
}
10041029

cc3200/ftp/updater.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
/******************************************************************************
1515
DEFINE PRIVATE CONSTANTS
1616
******************************************************************************/
17-
#define UPDATER_IMG_PATH "/SFLASH/SYS/MCUIMG.BIN"
18-
#define UPDATER_SRVPACK_PATH "/SFLASH/SYS/SRVPCK.UCF"
19-
#define UPDATER_SIGN_PATH "/SFLASH/SYS/SRVPCK.SIG"
17+
#define UPDATER_IMG_PATH "/flash/sys/mcuimg.bin"
18+
#define UPDATER_SRVPACK_PATH "/flash/sys/servicepack.ucf"
19+
#define UPDATER_SIGN_PATH "/flash/sys/servicepack.sig"
2020

2121
/******************************************************************************
2222
DEFINE TYPES
@@ -37,8 +37,6 @@ static updater_data_t updater_data;
3737
DEFINE PUBLIC FUNCTIONS
3838
******************************************************************************/
3939
bool updater_check_path (void *path) {
40-
// conert the path supplied to upper case
41-
stoupper (path);
4240
if (!strcmp(UPDATER_IMG_PATH, path)) {
4341
updater_data.path = IMG_UPDATE;
4442
updater_data.fsize = IMG_SIZE;

cc3200/mods/moduos.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@
4949
/// The filesystem has `/` as the root directory, and the available physical
5050
/// drives are accessible from here. They are currently:
5151
///
52-
/// /SFLASH -- the serial flash filesystem
53-
/// /SD -- the SD card (if it exists)
52+
/// /flash -- the serial flash filesystem
53+
/// /sd -- the SD card (if it exists)
5454
///
55-
/// On boot up, the current directory is `/SFLASH` if no SD card is inserted,
56-
/// otherwise it is `/SD`.
55+
/// On boot up, the current directory is `/flash` if no SD card is inserted,
56+
/// otherwise it is `/sd`.
5757

5858
/******************************************************************************
5959
DEFINE PRIVATE FUNCTIONS
@@ -109,6 +109,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_getcwd_obj, os_getcwd);
109109
STATIC mp_obj_t os_listdir(mp_uint_t n_args, const mp_obj_t *args) {
110110
bool is_str_type = true;
111111
const char *path;
112+
112113
if (n_args == 1) {
113114
if (mp_obj_get_type(args[0]) == &mp_type_bytes) {
114115
is_str_type = false;
@@ -121,16 +122,21 @@ STATIC mp_obj_t os_listdir(mp_uint_t n_args, const mp_obj_t *args) {
121122
// "hack" to list root directory
122123
if (path[0] == '/' && path[1] == '\0') {
123124
mp_obj_t dir_list = mp_obj_new_list(0, NULL);
124-
mp_obj_list_append(dir_list, MP_OBJ_NEW_QSTR(MP_QSTR_SFLASH));
125+
mp_obj_list_append(dir_list, MP_OBJ_NEW_QSTR(MP_QSTR_flash));
125126
if (sd_in_root()) {
126-
mp_obj_list_append(dir_list, MP_OBJ_NEW_QSTR(MP_QSTR_SD));
127+
mp_obj_list_append(dir_list, MP_OBJ_NEW_QSTR(MP_QSTR_sd));
127128
}
128129
return dir_list;
129130
}
130131

131132
FRESULT res;
132-
FILINFO fno;
133133
DIR dir;
134+
FILINFO fno;
135+
#if _USE_LFN
136+
char lfn_buf[_MAX_LFN + 1];
137+
fno.lfname = lfn_buf;
138+
fno.lfsize = sizeof(lfn_buf);
139+
#endif
134140

135141
res = f_opendir(&dir, path); /* Open the directory */
136142
if (res != FR_OK) {
@@ -145,7 +151,11 @@ STATIC mp_obj_t os_listdir(mp_uint_t n_args, const mp_obj_t *args) {
145151
if (fno.fname[0] == '.' && fno.fname[1] == 0) continue; /* Ignore . entry */
146152
if (fno.fname[0] == '.' && fno.fname[1] == '.' && fno.fname[2] == 0) continue; /* Ignore .. entry */
147153

154+
#if _USE_LFN
155+
char *fn = *fno.lfname ? fno.lfname : fno.fname;
156+
#else
148157
char *fn = fno.fname;
158+
#endif
149159

150160
// make a string object for this entry
151161
mp_obj_t entry_o;
@@ -215,14 +225,18 @@ STATIC bool path_equal(const char *path, const char *path_canonical) {
215225
/// Get the status of a file or directory.
216226
STATIC mp_obj_t os_stat(mp_obj_t path_in) {
217227
const char *path = mp_obj_str_get_str(path_in);
218-
stoupper((char *)path);
219228

220-
FILINFO fno;
221229
FRESULT res;
222-
if (path_equal(path, "/") || path_equal(path, "/SFLASH") || path_equal(path, "/SD")) {
230+
FILINFO fno;
231+
#if _USE_LFN
232+
fno.lfname = NULL;
233+
fno.lfsize = 0;
234+
#endif
235+
236+
if (path_equal(path, "/") || path_equal(path, "/flash") || path_equal(path, "/sd")) {
223237
// stat built-in directory
224-
if (path[1] == 'S' && !sd_in_root()) {
225-
// no /SD directory
238+
if (path[1] == 's' && !sd_in_root()) {
239+
// no /sd directory
226240
res = FR_NO_PATH;
227241
goto error;
228242
}

cc3200/mods/pybsd.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ STATIC mp_obj_t pybsd_enable (mp_obj_t self_in) {
148148
// do the init first
149149
pybsd_init (self);
150150

151-
// try to mount the sd card on /SD
152-
if (FR_OK != f_mount(self->fatfs, "/SD", 1)) {
151+
// try to mount the sd card on /sd
152+
if (FR_OK != f_mount(self->fatfs, "/sd", 1)) {
153153
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_operation_failed));
154154
}
155155

156-
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SD));
157-
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SD_slash_LIB));
156+
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_sd));
157+
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_sd_slash_lib));
158158

159159
// register it with the sleep module
160160
pybsleep_add ((const mp_obj_t)&pybsd_obj, (WakeUpCB_t)pybsd_init);
@@ -172,10 +172,10 @@ STATIC mp_obj_t pybsd_disable (mp_obj_t self_in) {
172172
if (self->enabled) {
173173
self->enabled = false;
174174
// unmount the sd card
175-
f_mount (NULL, "/SD", 1);
175+
f_mount (NULL, "/sd", 1);
176176
// remove sd paths from mp_sys_path
177-
mp_obj_list_remove(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SD));
178-
mp_obj_list_remove(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SD_slash_LIB));
177+
mp_obj_list_remove(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_sd));
178+
mp_obj_list_remove(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_sd_slash_lib));
179179

180180
// disable the peripheral
181181
MAP_PRCMPeripheralClkDisable(PRCM_SDHOST, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
@@ -186,8 +186,8 @@ STATIC mp_obj_t pybsd_disable (mp_obj_t self_in) {
186186
// unregister it with the sleep module
187187
pybsleep_remove (self);
188188

189-
// change the drive in case it was /SD
190-
f_chdrive("/SFLASH");
189+
// change the drive in case it was /sd
190+
f_chdrive("/flash");
191191
}
192192
return mp_const_none;
193193
}

cc3200/mpconfigport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
2: Enable LFN with dynamic working buffer on the STACK.
5555
3: Enable LFN with dynamic working buffer on the HEAP.
5656
*/
57-
#define MICROPY_ENABLE_LFN (0)
58-
#define MICROPY_LFN_CODE_PAGE (1)
57+
#define MICROPY_ENABLE_LFN (2)
58+
#define MICROPY_LFN_CODE_PAGE (437) // 1=SFN/ANSI 437=LFN/U.S.(OEM)
5959
#define MICROPY_STREAMS_NON_BLOCK (1)
6060
#define MICROPY_MODULE_WEAK_LINKS (0)
6161
#define MICROPY_CAN_OVERRIDE_BUILTINS (0)

0 commit comments

Comments
 (0)