Skip to content

Commit 995a030

Browse files
authored
MPS2_AN385 improvements (FreeRTOS#1225)
* MPS2_AN385 improvements Sync various MPS2_AN385 CORTEX-M3 QEMU targets and improve their Makefiles and cleanup gcc support: - FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2: - Makefile - output image size after linking - move -nostartfiles from compiler to linker flags - modernize compiler warning flags - add --gc-sections to linker flags - TCPEchoClient_SingleTasks.c: fix compiler warnings - main.c: fix compiler warnings (remove unused code) - main_networking.c - remove ipLOCAL_MAC_ADDRESS (unknown) - fix compiler warnings about unused params - startup.c: main(void), remove unused includes, silence unused params - syscalls.c: remove unused defines, silence unused params, more compact _sbrk() - FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC/build/gcc: - Makefile - CFLAGS/LDFLAGS in more readable lines - move -nostartfiles to linker flags - comment out -specs=rdimon.specs as it is not needed - startup_gcc.c: fix typo in comment, remove unused uart code - FreeRTOS/Demo/CORTEX_MPU_M3_MPS2_QEMU_GCC - Makefile - after compilation output size of image - remove -DQEMU_SOC_MPS2, not needed - update many CFLAGS/LDFLAGS settings to more modern gcc/source - -ffunction-sections -fdata-sections is moved to CFLAGS - startup.c: sync with other ports - syscall.c: _write(): param buf is not unused, silence unused params Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com> * remove ipLOCAL_MAC_ADDRESS completely and fix formatting errors remove ipLOCAL_MAC_ADDRESS completely and fix formatting errors Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
1 parent 49bbe71 commit 995a030

File tree

12 files changed

+122
-109
lines changed

12 files changed

+122
-109
lines changed

FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/Makefile

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
CC = arm-none-eabi-gcc
2+
SIZE = arm-none-eabi-size
23
BIN := freertos_tcp_mps2_demo.axf
34

45
BUILD_DIR := build
@@ -51,30 +52,33 @@ SOURCE_FILES += ${FREERTOS_TCP}/source/portable/BufferManagement/BufferAllocatio
5152
SOURCE_FILES += ${FREERTOS_TCP}/source/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c
5253
SOURCE_FILES += ${FREERTOS_TCP}/source/portable/NetworkInterface/MPS2_AN385/ether_lan9118/smsc9220_eth_drv.c
5354

54-
DEFINES := -DQEMU_SOC_MPS2 -DHEAP3
55-
56-
LDFLAGS = -T mps2_m3.ld -specs=nano.specs --specs=rdimon.specs -lc -lrdimon
57-
LDFLAGS += -Xlinker -Map=${BUILD_DIR}/output.map
58-
59-
CFLAGS += -nostartfiles -mthumb -mcpu=cortex-m3 -Wno-error=implicit-function-declaration
60-
CFLAGS += -Wno-builtin-declaration-mismatch -Werror
55+
DEFINES := -DHEAP3
56+
CPPFLAGS += $(DEFINES)
6157

58+
CFLAGS += -mthumb -mcpu=cortex-m3
6259
ifeq ($(DEBUG), 1)
63-
CFLAGS += -ggdb3 -Og
60+
CFLAGS += -g3 -Og -ffunction-sections -fdata-sections
6461
else
65-
CFLAGS += -O3
62+
CFLAGS += -Os -ffunction-sections -fdata-sections
6663
endif
67-
CFLAGS += -fstrict-aliasing -Wstrict-aliasing -Wno-error=address-of-packed-member
64+
CFLAGS += -MMD
65+
CFLAGS += -Wall -Wextra -Wshadow
66+
#CFLAGS += -Wpedantic -fanalyzer
67+
#CFLAGS += -flto
68+
CFLAGS += $(INCLUDE_DIRS)
6869

69-
OBJ_FILES := $(SOURCE_FILES:%.c=$(BUILD_DIR)/%.o)
70+
LDFLAGS = -T mps2_m3.ld
71+
LDFLAGS += -Xlinker -Map=${BUILD_DIR}/output.map
72+
LDFLAGS += -Xlinker --gc-sections
73+
LDFLAGS += -nostartfiles -specs=nano.specs -specs=nosys.specs -specs=rdimon.specs
7074

71-
CPPFLAGS += $(DEFINES)
72-
CFLAGS += $(INCLUDE_DIRS)
75+
OBJ_FILES := $(SOURCE_FILES:%.c=$(BUILD_DIR)/%.o)
7376

7477
.PHONY: clean
7578

7679
$(BUILD_DIR)/$(BIN) : $(OBJ_FILES)
77-
$(CC) -ffunction-sections -fdata-sections $(CFLAGS) $(LDFLAGS) $+ -o $(@)
80+
$(CC) $(CFLAGS) $(LDFLAGS) $+ -o $(@)
81+
$(SIZE) $(@)
7882

7983
%.d: %.c
8084
@set -e; rm -f $@; \
@@ -87,7 +91,7 @@ INCLUDES := $(SOURCE_FILES:%.c=$(BUILD_DIR)/%.d)
8791

8892
${BUILD_DIR}/%.o : %.c Makefile
8993
-mkdir -p $(@D)
90-
$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -c $< -o $@
94+
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
9195

9296
clean:
9397
-rm -rf build

FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/TCPEchoClient_SingleTasks.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,18 @@
206206
lStringLength = prvCreateTxData( pcTransmittedString, echoBUFFER_SIZES );
207207

208208
/* Add in some unique text at the front of the string. */
209-
sprintf( pcTransmittedString, "TxRx message number %u", ulTxCount );
209+
sprintf( pcTransmittedString, "TxRx message number %lu", ulTxCount );
210210
ulTxCount++;
211211

212-
printf( "sending data to the echo server size %d original %d\n",
212+
printf( "sending data to the echo server size %ld original %d\n",
213213
lStringLength,
214214
echoBUFFER_SIZES );
215215
/* Send the string to the socket. */
216216
lTransmitted = FreeRTOS_send( xSocket, /* The socket being sent to. */
217217
( void * ) pcTransmittedString, /* The data being sent. */
218218
lStringLength, /* The length of the data being sent. */
219219
0 ); /* No flags. */
220-
printf( "FreeRTOS_send returned...transmitted %d\n",
220+
printf( "FreeRTOS_send returned...transmitted %ld\n",
221221
lTransmitted );
222222

223223
if( lTransmitted < 0 )
@@ -398,15 +398,24 @@
398398
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
399399
eDHCPCallbackAnswer_t xApplicationDHCPHook( eDHCPCallbackPhase_t eDHCPPhase,
400400
uint32_t ulIPAddress )
401+
{
402+
( void ) eDHCPPhase;
403+
( void ) ulIPAddress;
404+
405+
return eDHCPContinue;
406+
}
401407
#else /* ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) */
402408
eDHCPCallbackAnswer_t xApplicationDHCPHook_Multi( eDHCPCallbackPhase_t eDHCPPhase,
403409
struct xNetworkEndPoint * pxEndPoint,
404410
IP_Address_t * pxIPAddress )
411+
{
412+
( void ) eDHCPPhase;
413+
( void ) pxEndPoint;
414+
( void ) pxIPAddress;
415+
416+
return eDHCPContinue;
417+
}
405418
#endif /* ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) */
406-
{
407-
/* Provide a stub for this function. */
408-
return eDHCPContinue;
409-
}
410419

411420
#endif /* if ( ipconfigUSE_DHCP_HOOK != 0 )*/
412421

FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ void main_tcp_echo_client_tasks( void );
4040
void vApplicationIdleHook( void );
4141
void vApplicationTickHook( void );
4242

43-
extern void initialise_monitor_handles( void );
44-
45-
int main()
43+
int main( void )
4644
{
4745
main_tcp_echo_client_tasks();
4846
return 0;
@@ -84,8 +82,6 @@ void vApplicationStackOverflowHook( TaskHandle_t pxTask,
8482

8583
void vApplicationIdleHook( void )
8684
{
87-
volatile size_t xFreeHeapSpace;
88-
8985
/* This is just a trivial example of an idle hook. It is called on each
9086
* cycle of the idle task. It must *NOT* attempt to block. In this case the
9187
* idle task just queries the amount of FreeRTOS heap that remains. See the

FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/main_networking.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ void main_tcp_echo_client_tasks( void )
180180
}
181181
#endif /* ( ipconfigUSE_DHCP != 0 ) */
182182

183-
memcpy( ipLOCAL_MAC_ADDRESS, ucMACAddress, sizeof( ucMACAddress ) );
184-
185183
FreeRTOS_IPInit_Multi();
186184
#else /* if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
187185
/* Using the old /single /IPv4 library, or using backward compatible mode of the new /multi library. */
@@ -224,6 +222,10 @@ BaseType_t xTasksAlreadyCreated = pdFALSE;
224222
uint32_t ulDNSServerAddress;
225223
char cBuffer[ 16 ];
226224

225+
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
226+
( void ) pxEndPoint;
227+
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
228+
227229
/* If the network has just come up...*/
228230
if( eNetworkEvent == eNetworkUp )
229231
{
@@ -335,6 +337,10 @@ static void prvMiscInitialisation( void )
335337
{
336338
BaseType_t xReturn;
337339

340+
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
341+
( void ) pxEndPoint;
342+
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
343+
338344
/* Determine if a name lookup is for this node. Two names are given
339345
* to this node: that returned by pcApplicationHostnameHook() and that set
340346
* by mainDEVICE_NICK_NAME. */

FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/startup.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@
2828
#include <stdio.h>
2929
#include <stdlib.h>
3030
#include <string.h>
31-
#include "CMSIS/CMSDK_CM3.h"
32-
#include "CMSIS/core_cm3.h"
3331

3432
extern void vPortSVCHandler( void );
3533
extern void xPortPendSVHandler( void );
3634
extern void xPortSysTickHandler( void );
37-
extern void uart_init();
38-
extern int main();
35+
extern void uart_init( void );
36+
extern int main( void );
3937

38+
void _start( void );
4039
void __attribute__( ( weak ) ) EthernetISR( void );
4140

4241
extern uint32_t _estack, _sidata, _sdata, _edata, _sbss, _ebss;
@@ -63,7 +62,6 @@ void Reset_Handler( void )
6362
}
6463

6564
/* jump to board initialisation */
66-
void _start( void );
6765
_start();
6866
}
6967

@@ -96,6 +94,16 @@ void prvGetRegistersFromStack( uint32_t * pulFaultStackAddress )
9694
for( ; ; )
9795
{
9896
}
97+
98+
/* Remove the warning about unused variables. */
99+
( void ) r0;
100+
( void ) r1;
101+
( void ) r2;
102+
( void ) r3;
103+
( void ) r12;
104+
( void ) lr;
105+
( void ) pc;
106+
( void ) psr;
99107
}
100108

101109
static void Default_Handler( void ) __attribute__( ( naked ) );
@@ -114,7 +122,8 @@ void Default_Handler( void )
114122
"NVIC_INT_CTRL_CONST: .word 0xe000ed04\n"
115123
);
116124
}
117-
static void HardFault_Handler( void ) __attribute__( ( naked ) );
125+
126+
static void Default_Handler2( void ) __attribute__( ( naked ) );
118127
void Default_Handler2( void )
119128
{
120129
__asm volatile
@@ -158,7 +167,7 @@ void Default_Handler6( void )
158167
}
159168
}
160169

161-
const uint32_t * isr_vector[] __attribute__( ( section( ".isr_vector" ) ) ) =
170+
const uint32_t * const isr_vector[] __attribute__( ( section( ".isr_vector" ) ) ) =
162171
{
163172
( uint32_t * ) &_estack,
164173
( uint32_t * ) &Reset_Handler, /* Reset -15 */
@@ -195,7 +204,7 @@ const uint32_t * isr_vector[] __attribute__( ( section( ".isr_vector" ) ) ) =
195204
void _start( void )
196205
{
197206
uart_init();
198-
main( 0, 0 );
207+
main();
199208
exit( 0 );
200209
}
201210

@@ -212,4 +221,6 @@ __attribute__( ( naked ) ) void exit( int status )
212221
"bkpt 0xab\n"
213222
"end: b end\n"
214223
);
224+
225+
( void ) status;
215226
}

FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/syscalls.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,21 @@ typedef struct UART_t
3838
volatile uint32_t BAUDDIV;
3939
} UART_t;
4040

41-
#define UART0_ADDR ( ( UART_t * ) ( 0x40004000 ) )
41+
#define UART0_ADDR ( ( UART_t * ) ( 0x40004000 ) )
4242
#define UART_DR( baseaddr ) ( *( unsigned int * ) ( baseaddr ) )
4343

44-
#define UART_STATE_TXFULL ( 1 << 0 )
45-
#define UART_CTRL_TX_EN ( 1 << 0 )
46-
#define UART_CTRL_RX_EN ( 1 << 1 )
44+
#define UART_CTRL_TX_EN ( 1 << 0 )
4745

4846

4947
extern unsigned long _heap_bottom;
5048
extern unsigned long _heap_top;
51-
extern unsigned long g_ulBase;
5249

53-
static void * heap_end = 0;
50+
static char * heap_end = ( char * ) &_heap_bottom;
5451

5552
/**
5653
* @brief initializes the UART emulated hardware
5754
*/
58-
void uart_init()
55+
void uart_init( void )
5956
{
6057
UART0_ADDR->BAUDDIV = 16;
6158
UART0_ADDR->CTRL = UART_CTRL_TX_EN;
@@ -68,6 +65,7 @@ void uart_init()
6865
*/
6966
int _fstat( int file )
7067
{
68+
( void ) file;
7169
return 0;
7270
}
7371

@@ -80,6 +78,9 @@ int _read( int file,
8078
char * buf,
8179
int len )
8280
{
81+
( void ) file;
82+
( void ) buf;
83+
( void ) len;
8384
return -1;
8485
}
8586

@@ -97,6 +98,8 @@ int _write( int file,
9798
{
9899
int todo;
99100

101+
( void ) file;
102+
100103
for( todo = 0; todo < len; todo++ )
101104
{
102105
UART_DR( UART0_ADDR ) = *buf++;
@@ -113,16 +116,9 @@ int _write( int file,
113116
*/
114117
void * _sbrk( int incr )
115118
{
116-
char * prev_heap_end;
117-
118-
if( heap_end == 0 )
119-
{
120-
heap_end = ( void * ) &_heap_bottom;
121-
}
122-
123-
prev_heap_end = heap_end;
119+
void * prev_heap_end = heap_end;
124120

125-
if( ( heap_end + incr ) > ( void * ) &_heap_top )
121+
if( ( heap_end + incr ) > ( char * ) &_heap_top )
126122
{
127123
return ( void * ) -1;
128124
}

FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC/build/gcc/Makefile

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ LD = arm-none-eabi-gcc
99
SIZE = arm-none-eabi-size
1010
MAKE = make
1111

12-
13-
CFLAGS += $(INCLUDE_DIRS) -nostartfiles -ffreestanding -mthumb -mcpu=cortex-m3 \
14-
-Wall -Wextra -g3 -Os -ffunction-sections -fdata-sections \
15-
-MMD -MP -MF"$(@:%.o=%.d)" -MT $@
16-
17-
#CFLAGS += -Wpedantic -Wshadow -fanalyzer
12+
CFLAGS += -ffreestanding -mthumb -mcpu=cortex-m3
13+
CFLAGS += -Wall -Wextra -Wshadow
14+
CFLAGS += -g3 -Os -ffunction-sections -fdata-sections
15+
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" -MT $@
16+
#CFLAGS += -std=c99
17+
#CFLAGS += -Wpedantic -fanalyzer
1818
#CFLAGS += -flto
19+
CFLAGS += $(INCLUDE_DIRS)
20+
21+
LDFLAGS = -T ./mps2_m3.ld
22+
LDFLAGS += -Xlinker -Map=$(OUTPUT_DIR)/RTOSDemo.map
23+
LDFLAGS += -Xlinker --gc-sections
24+
LDFLAGS += -nostartfiles
25+
LDFLAGS += -specs=nano.specs -specs=nosys.specs # -specs=rdimon.specs
1926

2027
#
2128
# Kernel build.
@@ -106,9 +113,7 @@ $(IMAGE): ./mps2_m3.ld $(OBJS_OUTPUT) Makefile
106113
@echo ""
107114
@echo "--- Final linking ---"
108115
@echo ""
109-
$(LD) $(OBJS_OUTPUT) $(CFLAGS) -Xlinker --gc-sections -Xlinker -T ./mps2_m3.ld \
110-
-Xlinker -Map=$(OUTPUT_DIR)/RTOSDemo.map -specs=nano.specs \
111-
-specs=nosys.specs -specs=rdimon.specs -o $(IMAGE)
116+
$(LD) $(CFLAGS) $(LDFLAGS) $(OBJS_OUTPUT) -o $(IMAGE)
112117
$(SIZE) $(IMAGE)
113118

114119
$(DEP_OUTPUT):

FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC/build/gcc/startup_gcc.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,6 @@
2727
#include <stdint.h>
2828
#include <stdio.h>
2929

30-
/* UART peripheral register addresses and bits. */
31-
#define UART0_ADDR ( ( UART_t * ) ( 0x40004000 ) )
32-
#define UART_DR( baseaddr ) ( *( uint32_t * ) ( baseaddr ) )
33-
#define UART_STATE( baseaddr ) ( *( uint32_t * ) ( baseaddr + 4 ) )
34-
#define UART_STATE_TXFULL ( 1 << 0 )
35-
36-
typedef struct UART_t
37-
{
38-
volatile uint32_t DATA;
39-
volatile uint32_t STATE;
40-
volatile uint32_t CTRL;
41-
volatile uint32_t INTSTATUS;
42-
volatile uint32_t BAUDDIV;
43-
} UART_t;
44-
45-
4630
/* FreeRTOS interrupt handlers. */
4731
extern void vPortSVCHandler( void );
4832
extern void xPortPendSVHandler( void );
@@ -99,7 +83,7 @@ void Reset_Handler( void )
9983
}
10084

10185
/* Variables used to store the value of registers at the time a hardfault
102-
* occurs. These are volatile to try and prevent the compiler/linker optimising
86+
* occurs. These are volatile to try and prevent the compiler/linker optimizing
10387
* them away as the variables never actually get used. */
10488
volatile uint32_t r0;
10589
volatile uint32_t r1;

0 commit comments

Comments
 (0)