This commit is contained in:
Bernard Xiong
2015-10-14 14:48:22 +08:00
25 changed files with 704 additions and 436 deletions
+2 -5
View File
@@ -30,8 +30,5 @@ Export('rtconfig')
# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
# build program
env.Program(TARGET, objs)
# end building
EndBuilding(TARGET)
# do building
DoBuilding(TARGET, objs)
+2 -2
View File
@@ -18,8 +18,8 @@ if rtconfig.CROSS_TOOL == 'gcc':
src = src + ['CMSIS/ST/STM32F4xx/Source/Templates/gcc_ride7/startup_stm32f4xx.s']
elif rtconfig.CROSS_TOOL == 'keil':
src = src + ['CMSIS/ST/STM32F4xx/Source/Templates/arm/startup_stm32f4xx.s']
# elif rtconfig.CROSS_TOOL == 'iar':
# src = src + ['CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/iar/' + startup_scripts[rtconfig.STM32_TYPE]]
elif rtconfig.CROSS_TOOL == 'iar':
src = src + ['CMSIS/ST/STM32F4xx/Source/Templates/iar/startup_stm32f4xx.s']
path = [cwd + '/STM32F4xx_StdPeriph_Driver/inc',
cwd + '/CMSIS/ST/STM32F4xx/Include',
+25
View File
@@ -0,0 +1,25 @@
board info:
STM32F4 discovery
http://www.st.com/internet/evalboard/product/252419.jsp
note:
in drivers/stm32f4xx_conf.h
/* Redefine the HSE value; it's equal to 8 MHz on the STM32F4-DISCOVERY Kit */
#define HSE_VALUE ((uint32_t)8000000)
**================= IAR WARNING =================**
after use `scons --target=iar -s` cmd to product IAR project, you have to add iar link file by hand
IAR steps:
1. Project-->Options-->Linker
2. Config-->Linker Configuration file
3. select `Override Default`, then select `bsp/stm32f40x/stm32f40x_flash.icf`
4. rebuild project
**TODO**
auto add *.icf by scons script
-9
View File
@@ -1,9 +0,0 @@
board info:
STM32F4 discovery
http://www.st.com/internet/evalboard/product/252419.jsp
note:
in drivers/stm32f4xx_conf.h
/* Redefine the HSE value; it's equal to 8 MHz on the STM32F4-DISCOVERY Kit */
#define HSE_VALUE ((uint32_t)8000000)
+33
View File
@@ -0,0 +1,33 @@
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
define symbol __ICFEDIT_region_ROM_end__ = 0x0807FFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x2001FFFF; /*STM32 F446RE*/
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x200;
define symbol __ICFEDIT_size_heap__ = 0x000;
/**** End of ICF editor section. ###ICF###*/
define memory mem with size = 4G;
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
initialize by copy { readwrite };
do not initialize { section .noinit };
keep { section FSymTab };
keep { section VSymTab };
keep { section .rti_fn* };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place in ROM_region { readonly };
place in RAM_region { readwrite, block CSTACK, last block HEAP};
+2 -2
View File
@@ -25,7 +25,7 @@
#include <rtthread.h>
#include "board.h"
#include "sram.h"
#include "drv_mpu.h"
/**
* @addtogroup STM32
@@ -165,7 +165,7 @@ void HAL_ResumeTick(void)
void rt_hw_board_init()
{
/* Configure the MPU attributes as Write Through */
//mpu_init();
mpu_init();
/* Enable the CPU Cache */
CPU_CACHE_Enable();
+1 -1
View File
@@ -81,4 +81,4 @@ int mpu_init(void)
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
return 0;
}
INIT_BOARD_EXPORT(mpu_init);
//INIT_BOARD_EXPORT(mpu_init);
@@ -29,6 +29,7 @@ struct hostent *gethostbyname(const char *name)
{
return lwip_gethostbyname(name);
}
RTM_EXPORT(gethostbyname);
int gethostbyname_r(const char *name, struct hostent *ret, char *buf,
size_t buflen, struct hostent **result, int *h_errnop)
@@ -40,6 +41,7 @@ void freeaddrinfo(struct addrinfo *ai)
{
lwip_freeaddrinfo(ai);
}
RTM_EXPORT(freeaddrinfo);
int getaddrinfo(const char *nodename,
const char *servname,
@@ -48,3 +50,4 @@ int getaddrinfo(const char *nodename,
{
return lwip_getaddrinfo(nodename, servname, hints, res);
}
RTM_EXPORT(getaddrinfo);
@@ -118,5 +118,6 @@ select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
return result;
}
RTM_EXPORT(select);
#endif
File diff suppressed because it is too large Load Diff
@@ -29,9 +29,11 @@
extern "C" {
#endif
#include <inttypes.h>
#include <lwip/sockets.h>
typedef uint16_t sa_family_t;
typedef uint16_t in_port_t;
struct sockaddr_storage
{
+2 -1
View File
@@ -96,7 +96,8 @@ struct romfs_dirent *dfs_romfs_lookup(struct romfs_dirent *root_dirent, const ch
{
if (check_dirent(&dirent[index]) != 0)
return RT_NULL;
if (rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0)
if (rt_strlen(dirent[index].name) == (subpath_end - subpath) &&
rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0)
{
dirent_size = dirent[index].size;
+4
View File
@@ -255,6 +255,9 @@
#define DFS_S_IWOTH 00002
#define DFS_S_IXOTH 00001
#ifdef _MSC_VER
#include <wchar.h>
#else
struct stat
{
rt_device_t st_dev;
@@ -262,6 +265,7 @@ struct stat
rt_uint32_t st_size;
rt_time_t st_mtime;
};
#endif
struct statfs
{
+2 -1
View File
@@ -22,8 +22,9 @@ finsh_token.c
''')
msh_src = Split('''
msh_cmd.c
msh.c
msh_cmd.c
msh_file.c
''')
CPPPATH = [cwd]
+52 -52
View File
File diff suppressed because it is too large Load Diff
+40 -26
View File
@@ -37,7 +37,7 @@
#endif
#define RT_FINSH_ARG_MAX 10
typedef int (*cmd_function_t)(int argc, char** argv);
typedef int (*cmd_function_t)(int argc, char **argv);
#ifdef FINSH_USING_MSH
#ifdef FINSH_USING_MSH_ONLY
@@ -56,7 +56,7 @@ rt_bool_t msh_is_used(void)
return __msh_state;
}
static int msh_exit(int argc, char** argv)
static int msh_exit(int argc, char **argv)
{
/* return to finsh shell mode */
__msh_state = RT_FALSE;
@@ -74,15 +74,15 @@ static int msh_enter(void)
FINSH_FUNCTION_EXPORT_ALIAS(msh_enter, msh, use module shell);
#endif
int msh_help(int argc, char** argv)
int msh_help(int argc, char **argv)
{
rt_kprintf("RT-Thread shell commands:\n");
{
struct finsh_syscall *index;
for (index = _syscall_table_begin;
index < _syscall_table_end;
FINSH_NEXT_SYSCALL(index))
index < _syscall_table_end;
FINSH_NEXT_SYSCALL(index))
{
if (strncmp(index->name, "__cmd_", 6) != 0) continue;
#if defined(FINSH_USING_DESCRIPTION) && defined(FINSH_USING_SYMTAB)
@@ -98,7 +98,7 @@ int msh_help(int argc, char** argv)
}
FINSH_FUNCTION_EXPORT_ALIAS(msh_help, __cmd_help, RT-Thread shell help.);
static int msh_split(char* cmd, rt_size_t length, char* argv[RT_FINSH_ARG_MAX])
static int msh_split(char *cmd, rt_size_t length, char *argv[RT_FINSH_ARG_MAX])
{
char *ptr;
rt_size_t position;
@@ -161,13 +161,13 @@ static cmd_function_t msh_get_cmd(char *cmd, int size)
cmd_function_t cmd_func = RT_NULL;
for (index = _syscall_table_begin;
index < _syscall_table_end;
FINSH_NEXT_SYSCALL(index))
index < _syscall_table_end;
FINSH_NEXT_SYSCALL(index))
{
if (strncmp(index->name, "__cmd_", 6) != 0) continue;
if (strncmp(&index->name[6], cmd, size) == 0 &&
index->name[6 + size] == '\0')
index->name[6 + size] == '\0')
{
cmd_func = (cmd_function_t)index->func;
break;
@@ -180,7 +180,7 @@ static cmd_function_t msh_get_cmd(char *cmd, int size)
#if defined(RT_USING_MODULE) && defined(RT_USING_DFS)
/* Return 0 on module executed. Other value indicate error.
*/
int msh_exec_module(const char* cmd_line, int size)
int msh_exec_module(const char *cmd_line, int size)
{
int ret;
int fd = -1;
@@ -197,7 +197,7 @@ int msh_exec_module(const char* cmd_line, int size)
length = cmd_length + 32;
/* allocate program name memory */
pg_name = (char*) rt_malloc(length);
pg_name = (char *) rt_malloc(length);
if (pg_name == RT_NULL)
return -RT_ENOMEM;
@@ -251,12 +251,21 @@ int msh_exec_module(const char* cmd_line, int size)
int system(const char *command)
{
return msh_exec_module(command, rt_strlen(command));
int ret = -RT_ENOMEM;
char *cmd = rt_strdup(command);
if (cmd)
{
ret = msh_exec(cmd, rt_strlen(cmd));
rt_free(cmd);
}
return ret;
}
RTM_EXPORT(system);
#endif
static int _msh_exec_cmd(char* cmd, rt_size_t length, int *retp)
static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp)
{
int argc;
int cmd0_size = 0;
@@ -287,12 +296,12 @@ static int _msh_exec_cmd(char* cmd, rt_size_t length, int *retp)
return 0;
}
int msh_exec(char* cmd, rt_size_t length)
int msh_exec(char *cmd, rt_size_t length)
{
int cmd_ret;
/* strim the beginning of command */
while(*cmd == ' ' || *cmd == '\t')
/* strim the beginning of command */
while (*cmd == ' ' || *cmd == '\t')
{
cmd++;
length--;
@@ -318,7 +327,12 @@ int msh_exec(char* cmd, rt_size_t length)
#endif
#if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR)
/* change to this directory */
if (msh_exec_script(cmd, length) == 0)
{
return 0;
}
/* change to this directory */
if (chdir(cmd) == 0)
{
return 0;
@@ -329,7 +343,7 @@ int msh_exec(char* cmd, rt_size_t length)
{
char *tcmd;
tcmd = cmd;
while(*tcmd != ' ' && *tcmd != '\0')
while (*tcmd != ' ' && *tcmd != '\0')
{
tcmd++;
}
@@ -355,14 +369,14 @@ static int str_common(const char *str1, const char *str2)
#ifdef RT_USING_DFS
void msh_auto_complete_path(char *path)
{
DIR* dir = RT_NULL;
DIR *dir = RT_NULL;
struct dirent *dirent = RT_NULL;
char *full_path, *ptr, *index;
if (!path)
return;
full_path = (char*)rt_malloc(256);
full_path = (char *)rt_malloc(256);
if (full_path == RT_NULL) return; /* out of memory */
if (*path != '/')
@@ -434,9 +448,9 @@ void msh_auto_complete_path(char *path)
/* save dirent name */
strcpy(full_path, dirent->d_name);
}
length = str_common(dirent->d_name, full_path);
if (length < min_length)
{
min_length = length;
@@ -460,7 +474,7 @@ void msh_auto_complete_path(char *path)
rt_kprintf("%s\n", dirent->d_name);
}
}
length = index - path;
memcpy(index, full_path, min_length);
path[length + min_length] = '\0';
@@ -481,7 +495,7 @@ void msh_auto_complete(char *prefix)
min_length = 0;
name_ptr = RT_NULL;
if (*prefix == '\0')
if (*prefix == '\0')
{
msh_help(0, RT_NULL);
return;
@@ -522,7 +536,7 @@ void msh_auto_complete(char *prefix)
/* skip finsh shell function */
if (strncmp(index->name, "__cmd_", 6) != 0) continue;
cmd_name = (const char*) &index->name[6];
cmd_name = (const char *) &index->name[6];
if (strncmp(prefix, cmd_name, strlen(prefix)) == 0)
{
if (min_length == 0)
+4 -1
View File
@@ -33,7 +33,10 @@
#include <rtthread.h>
rt_bool_t msh_is_used(void);
int msh_exec(char* cmd, rt_size_t length);
int msh_exec(char *cmd, rt_size_t length);
void msh_auto_complete(char *prefix);
int msh_exec_module(const char *cmd_line, int size);
int msh_exec_script(const char *cmd_line, int size);
#endif
File diff suppressed because it is too large Load Diff
+159
View File
@@ -0,0 +1,159 @@
/*
* script for RT-Thread module shell
*
* COPYRIGHT (C) 2013-2015, Shanghai Real-Thread Technology Co., Ltd
*
* This file is part of RT-Thread (http://www.rt-thread.org)
* Maintainer: bernard.xiong <bernard.xiong at gmail.com>
*
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2015-09-25 Bernard the first verion for FinSH
*/
#include <rtthread.h>
#include <finsh.h>
#include "msh.h"
#if defined(FINSH_USING_MSH) && defined(RT_USING_DFS)
#include <dfs_posix.h>
static int msh_readline(int fd, char *line_buf, int size)
{
char ch;
int index = 0;
do
{
if (read(fd, &ch, 1) != 1)
{
/* nothing in this file */
return 0;
}
}
while (ch == '\n' || ch == '\r');
/* set the first character */
line_buf[index ++] = ch;
while (index < size)
{
if (read(fd, &ch, 1) == 1)
{
if (ch == '\n' || ch == '\r')
{
line_buf[index] = '\0';
break;
}
line_buf[index++] = ch;
}
else
{
line_buf[index] = '\0';
break;
}
}
return index;
}
int msh_exec_script(const char *cmd_line, int size)
{
int ret;
int fd = -1;
char *pg_name;
int length, cmd_length = 0;
if (size == 0) return -RT_ERROR;
/* get the length of command0 */
while ((cmd_line[cmd_length] != ' ' && cmd_line[cmd_length] != '\t') && cmd_length < size)
cmd_length ++;
/* get name length */
length = cmd_length + 32;
/* allocate program name memory */
pg_name = (char *) rt_malloc(length);
if (pg_name == RT_NULL) return -RT_ENOMEM;
/* copy command0 */
memcpy(pg_name, cmd_line, cmd_length);
pg_name[cmd_length] = '\0';
if (strstr(pg_name, ".sh") != RT_NULL || strstr(pg_name, ".SH") != RT_NULL)
{
/* try to open program */
fd = open(pg_name, O_RDONLY, 0);
/* search in /bin path */
if (fd < 0)
{
rt_snprintf(pg_name, length - 1, "/bin/%.*s", cmd_length, cmd_line);
fd = open(pg_name, O_RDONLY, 0);
}
}
rt_free(pg_name);
if (fd >= 0)
{
/* found script */
char *line_buf;
int length;
line_buf = (char *) rt_malloc(RT_CONSOLEBUF_SIZE);
/* read line by line and then exec it */
do
{
length = msh_readline(fd, line_buf, RT_CONSOLEBUF_SIZE);
if (length > 0)
{
char ch = '\0';
int index;
for (index = 0; index < length; index ++)
{
ch = line_buf[index];
if (ch == ' ' || ch == '\t') continue;
else break;
}
if (ch != '#') /* not a comment */
msh_exec(line_buf, length);
}
}
while (length > 0);
close(fd);
rt_free(line_buf);
ret = 0;
}
else
{
ret = -1;
}
return ret;
}
#endif
+1 -1
View File
@@ -425,7 +425,7 @@ void finsh_thread_entry(void *parameter)
if (rt_device_read(shell->device, 0, &next, 1) == 1)
{
if (next == '\0') ch = 'r'; /* linux telnet will issue '\0' */
if (next == '\0') ch = '\r'; /* linux telnet will issue '\0' */
else ch = next;
}
else ch = '\r';
+39
View File
@@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <rtm.h>
/* some export routines for module */
RTM_EXPORT(strstr);
RTM_EXPORT(strlen);
RTM_EXPORT(strchr);
RTM_EXPORT(strcpy);
RTM_EXPORT(strncpy);
RTM_EXPORT(strcmp);
RTM_EXPORT(strncmp);
RTM_EXPORT(strcat);
RTM_EXPORT(strtol);
RTM_EXPORT(memcpy);
RTM_EXPORT(memcmp);
RTM_EXPORT(memmove);
RTM_EXPORT(memset);
RTM_EXPORT(memchr);
RTM_EXPORT(toupper);
RTM_EXPORT(atoi);
RTM_EXPORT(localtime);
RTM_EXPORT(time);
/* import the full stdio for printf */
#ifdef __MICROLIB
#error "[RT_USING_LIBC] Please use standard libc but not microlib."
#endif
RTM_EXPORT(puts);
RTM_EXPORT(printf);
+4
View File
@@ -22,18 +22,22 @@ void *malloc(int n)
{
return rt_malloc(n);
}
RTM_EXPORT(malloc);
void *realloc(void *rmem, rt_size_t newsize)
{
return rt_realloc(rmem, newsize);
}
RTM_EXPORT(realloc);
void *calloc(rt_size_t nelem, rt_size_t elsize)
{
return rt_calloc(nelem, elsize);
}
RTM_EXPORT(calloc);
void free(void *rmem)
{
rt_free(rmem);
}
RTM_EXPORT(free);
+47
View File
@@ -0,0 +1,47 @@
#include <rtthread.h>
#include <rtm.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
RTM_EXPORT(strcpy);
RTM_EXPORT(strncpy);
RTM_EXPORT(strlen);
RTM_EXPORT(strcat);
RTM_EXPORT(strstr);
RTM_EXPORT(strchr);
RTM_EXPORT(strcmp);
RTM_EXPORT(strtol);
RTM_EXPORT(strtoul);
RTM_EXPORT(strncmp);
RTM_EXPORT(memcpy);
RTM_EXPORT(memcmp);
RTM_EXPORT(memmove);
RTM_EXPORT(memset);
RTM_EXPORT(memchr);
RTM_EXPORT(putchar);
RTM_EXPORT(puts);
RTM_EXPORT(printf);
RTM_EXPORT(sprintf);
RTM_EXPORT(snprintf);
RTM_EXPORT(fwrite);
#include <time.h>
RTM_EXPORT(localtime);
RTM_EXPORT(time);
#include <setjmp.h>
RTM_EXPORT(longjmp);
RTM_EXPORT(setjmp);
RTM_EXPORT(exit);
RTM_EXPORT(abort);
RTM_EXPORT(rand);
#include <assert.h>
RTM_EXPORT(__assert_func);
+32 -16
View File
@@ -267,6 +267,12 @@ def PrepareModuleBuilding(env, root_directory, bsp_directory):
global Env
global Rtt_Root
# patch for win32 spawn
if env['PLATFORM'] == 'win32':
win32_spawn = Win32Spawn()
win32_spawn.env = env
env['SPAWN'] = win32_spawn.spawn
Env = env
Rtt_Root = root_directory
@@ -491,37 +497,35 @@ def DoBuilding(target, objects):
lst.append(item)
return lst
objects = one_list(objects)
# remove source files with local flags setting
for group in Projects:
if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES'):
for source in group['src']:
for obj in objects:
if source.abspath == obj.abspath or (len(obj.sources) > 0 and source.abspath == obj.sources[0].abspath):
objects.remove(obj)
# re-add the source files to the objects
for group in Projects:
# handle local group
def local_group(group, objects):
if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES'):
CCFLAGS = Env.get('CCFLAGS', '') + group.get('LOCAL_CCFLAGS', '')
CPPPATH = Env.get('CPPPATH', ['']) + group.get('LOCAL_CPPPATH', [''])
CPPDEFINES = Env.get('CPPDEFINES', ['']) + group.get('LOCAL_CPPDEFINES', [''])
for source in group['src']:
objects += Env.Object(source, CCFLAGS = CCFLAGS,
CPPPATH = CPPPATH,
CPPDEFINES = CPPDEFINES)
objects.append(Env.Object(source, CCFLAGS = CCFLAGS,
CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES))
return True
return False
objects = one_list(objects)
program = None
# check whether special buildlib option
lib_name = GetOption('buildlib')
if lib_name:
objects = [] # remove all of objects
# build library with special component
for Group in Projects:
if Group['name'] == lib_name:
lib_name = GroupLibName(Group['name'], Env)
objects = Env.Object(Group['src'])
if not local_group(Group, objects):
objects = Env.Object(Group['src'])
program = Env.Library(lib_name, objects)
# add library copy action
@@ -529,6 +533,18 @@ def DoBuilding(target, objects):
break
else:
# remove source files with local flags setting
for group in Projects:
if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES'):
for source in group['src']:
for obj in objects:
if source.abspath == obj.abspath or (len(obj.sources) > 0 and source.abspath == obj.sources[0].abspath):
objects.remove(obj)
# re-add the source files to the objects
for group in Projects:
local_group(group, objects)
program = Env.Program(target, objects)
EndBuilding(target, program)
+85 -170
View File
File diff suppressed because it is too large Load Diff