Skip to content

Commit 293730b

Browse files
Merge pull request #19 from autosportlabs/p/jeffc/enable_optimizations
P/jeffc/enable optimizations
2 parents 342daa9 + fd9e00f commit 293730b

File tree

9 files changed

+41
-69
lines changed

9 files changed

+41
-69
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ GDB := $(PREFIX)-gdb
6868
INCLUDES += $(CPU_INCLUDES) $(BOARD_INCLUDES) $(LIB_INCLUDES) $(APP_INCLUDES)
6969
INCLUDES += -Icpu/common -Iboard/common
7070

71-
CFLAGS ?= -Os -g -Wall -fno-common -c -mthumb
71+
CFLAGS ?= -Os -g -Wall -fno-common -c -mthumb -fno-strict-aliasing
7272
CFLAGS += -mcpu=$(CPU_TYPE) -MD -std=gnu99
73-
#CFLAGS += -ffunction-sections -fdata-sections -flto
73+
CFLAGS += -ffunction-sections -fdata-sections
7474
CFLAGS += $(INCLUDES) $(CPU_DEFINES) $(BOARD_DEFINES) $(APP_DEFINES) $(CPU_FLAGS)
7575

7676
ASFLAGS += -mcpu=$(CPU_TYPE) $(FPU) -g -Wa,--warn
@@ -79,8 +79,8 @@ LIBS = -lnosys
7979

8080
LDFLAGS ?= --specs=nano.specs -lc -lgcc $(LIBS) -mcpu=$(CPU_TYPE) -g -gdwarf-2
8181
LDFLAGS += -L. -Lcpu/common -L$(CPU_BASE) -T$(CPU_LINK_MEM) -Tlink_sections.ld
82-
LDFLAGS += -nostartfiles -Wl,--gc-sections -mthumb -mcpu=$(CPU_TYPE)
83-
#LDFLAGS += -ffunction-sections -fdata-sections -flto -Os
82+
LDFLAGS += -nostartfiles -Wl,--gc-sections -mthumb -mcpu=$(CPU_TYPE) -Os
83+
LDFLAGS += -ffunction-sections -fdata-sections
8484
LDFLAGS += -msoft-float -Wl,--Map=$(TARGET).map
8585

8686
# Be silent per default, but 'make V=1' will show all compiler calls.

cpu/stm32f3xx/cdc_acm/hw_config.c

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "hw_config.h"
3535
#include "usb_pwr.h"
3636

37-
37+
#define USB_IRQ_PRIORITY 7
3838
/* Private typedef -----------------------------------------------------------*/
3939
/* Private define ------------------------------------------------------------*/
4040
/* Private macro -------------------------------------------------------------*/
@@ -118,13 +118,6 @@ void Set_System(void)
118118
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_14);
119119
GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_14);
120120

121-
/* USB_DISCONNECT used as USB pull-up */
122-
GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
123-
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
124-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
125-
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
126-
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
127-
GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
128121
#endif /* STM32F37X && STM32F30X */
129122

130123
/* Configure the EXTI line 18 connected internally to the USB IP */
@@ -202,48 +195,19 @@ void USB_Interrupts_Config(void)
202195
{
203196
NVIC_InitTypeDef NVIC_InitStructure;
204197

205-
/* 2 bit for pre-emption priority, 2 bits for subpriority */
198+
/* We use no bits for nested sub priority */
206199
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
207200

208-
#if defined(STM32L1XX_MD) || defined(STM32L1XX_HD)|| defined(STM32L1XX_MD_PLUS)
209-
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQn;
210-
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
211-
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
212-
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
213-
NVIC_Init(&NVIC_InitStructure);
214-
215-
/* Enable the USB Wake-up interrupt */
216-
NVIC_InitStructure.NVIC_IRQChannel = USB_FS_WKUP_IRQn;
217-
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
218-
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
219-
NVIC_Init(&NVIC_InitStructure);
220-
221-
#elif defined(STM32F37X)
222-
/* Enable the USB interrupt */
223-
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQn;
224-
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
225-
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
226-
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
227-
NVIC_Init(&NVIC_InitStructure);
228-
229-
/* Enable the USB Wake-up interrupt */
230-
NVIC_InitStructure.NVIC_IRQChannel = USBWakeUp_IRQn;
231-
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
232-
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
233-
NVIC_Init(&NVIC_InitStructure);
234-
235-
#else
236201
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
237-
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
202+
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = USB_IRQ_PRIORITY;
238203
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
239204
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
240205
NVIC_Init(&NVIC_InitStructure);
241206

242207
/* Enable the USB Wake-up interrupt */
243208
NVIC_InitStructure.NVIC_IRQChannel = USBWakeUp_IRQn;
244-
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
209+
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = USB_IRQ_PRIORITY;
245210
NVIC_Init(&NVIC_InitStructure);
246-
#endif /* STM32L1XX_XD */
247211

248212
/* Enable USART Interrupt */
249213
/* We don't need to do this since we're intercepting traffic directly */

cpu/stm32f3xx/cdc_acm/usb_conf.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,17 @@
6969
/* IMR_MSK */
7070
/* mask defining which events has to be handled */
7171
/* by the device application software */
72-
/*
72+
73+
/* JC: Original configuration
74+
7375
#define IMR_MSK (CNTR_CTRM | CNTR_WKUPM | CNTR_SUSPM | CNTR_ERRM | CNTR_SOFM \
7476
| CNTR_ESOFM | CNTR_RESETM )
7577
*/
7678

79+
/* JC: WKUP/SUSPEND Functionality disabled */
7780
#define IMR_MSK (CNTR_CTRM | CNTR_ERRM | CNTR_SOFM \
7881
| CNTR_ESOFM | CNTR_RESETM )
7982

80-
8183
/*#define CTR_CALLBACK*/
8284
/*#define DOVR_CALLBACK*/
8385
/*#define ERR_CALLBACK*/

cpu/stm32f3xx/cdc_acm/usb_desc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ const uint8_t Virtual_Com_Port_ConfigDescriptor[] =
6262
0x00,
6363
0x02, /* bNumInterfaces: 2 interface */
6464
0x01, /* bConfigurationValue: Configuration value */
65-
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
65+
0x00, /* iConfiguration: Index of string descriptor describing
66+
* the configuration */
6667
0x80, /* bmAttributes: bus powered */
6768
0xFA, /* MaxPower 500 mA */
6869
/*Interface Descriptor*/

cpu/stm32f3xx/cdc_acm/usb_pwr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
/* Private macro -------------------------------------------------------------*/
3838
/* Private variables ---------------------------------------------------------*/
3939
__IO uint32_t bDeviceState = UNCONNECTED; /* USB device status */
40-
__IO bool fSuspendEnabled = FALSE; /* true when suspend is possible */
40+
__IO bool fSuspendEnabled = TRUE; /* true when suspend is possible */
4141
__IO uint32_t EP[8];
4242

4343
struct

cpu/stm32f4xx/cdc_acm/USB-CDC_device_stm32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ int USB_CDC_device_init(void)
2626

2727
int USB_CDC_device_deinit(void)
2828
{
29+
USBD_DeInit(&USB_OTG_dev);
30+
2931
return 0;
3032
}
3133

32-
33-
/* TODO: Plumb */
3434
int USB_CDC_read(uint8_t *dst, int len )
3535
{
3636
return vcp_rx(dst, len, 0xffffffff);

img_utils.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,16 @@ struct app_info_block *scan_for_app(void)
9292
return NULL;
9393
}
9494

95-
__attribute__((__naked__,__noreturn__))
95+
__attribute__((__naked__, __noreturn__))
9696
void jump_to_app(uint32_t address)
9797
{
9898
typedef void (*func_ptr)(void);
9999

100-
/* Function pointer to our app */
101-
func_ptr reset_vec;
102-
103100
/* Variable to hold the start address of the application */
104101
const uint32_t *vec_table = (uint32_t*) address;
105102

106103
/* Get the reset vector from the vector table */
107-
reset_vec = (func_ptr)((uint32_t)vec_table[1]);
104+
const func_ptr reset_vec = (func_ptr)((uint32_t)vec_table[1]);
108105

109106
/* Disable all interrupts */
110107
for (int i = 0; i < 8; i++)
@@ -114,6 +111,13 @@ void jump_to_app(uint32_t address)
114111
__set_MSP((uint32_t)(vec_table[0]));
115112
__set_PSP((uint32_t)(vec_table[0]));
116113

114+
/*
115+
* Perform a pipeline flush to ensure stack pointers are set
116+
* before jumping
117+
*/
118+
__DSB();
119+
__ISB();
120+
117121
/* Execute the reset vector (we don't return from this) */
118122
reset_vec();
119123

upgrade_agent/upgrade_agent_handlers.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,29 @@ void xbvc_handle_verify_command(struct x_verify_command *msg)
4545

4646
void xbvc_handle_run_command(struct x_run_command *msg)
4747
{
48-
struct x_run_response rsp;
49-
rsp.error = ERR_SUCCESS;
48+
struct x_run_response rsp = {.error = ERR_SUCCESS};
5049

51-
if (last_known_info == NULL)
50+
/* If we don't know about any applications, check to see if
51+
* one has been flashed into NVM */
52+
if (NULL == last_known_info) {
5253
last_known_info = scan_for_app();
5354

54-
if (last_known_info == NULL)
55-
rsp.error = ERR_RUN_FAIL;
56-
else
57-
rsp.error = ERR_SUCCESS;
55+
/* Check again, if we still didn't find anything,
56+
* set an appropriate error response*/
57+
if (NULL == last_known_info) {
58+
rsp.error = ERR_RUN_FAIL;
59+
}
60+
}
5861

5962
xbvc_send(&rsp, E_MSG_RUN_RESPONSE);
6063

6164
/* Make sure we sent the run response */
6265
upgrade_agent_usb_flush();
6366

64-
if (last_known_info != NULL) {
65-
/* Shut down the USB interface */
66-
upgrade_agent_usb_deinit();
67-
68-
/* Get going */
69-
jump_to_app(last_known_info->start_addr);
67+
/* Simply perform a reset, the bootloader will pick up the
68+
* application and execute it on the next go around */
69+
if (ERR_SUCCESS == rsp.error) {
70+
NVIC_SystemReset();
7071
}
7172
}
7273

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define _VERSION_H_
33

44
#define VER_MAJOR 0
5-
#define VER_MINOR 2
5+
#define VER_MINOR 3
66
#define VER_BUGFIX 0
77

88
#endif

0 commit comments

Comments
 (0)