Skip to content

Fixing dfu.c to allow compiling with -Os #9

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 4 commits into from
Apr 23, 2014
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ ST_LIB = stm32_lib
ST_USB = usb_lib

# Optimization level [0,1,2,3,s]
OPT = 0
DEBUG = -g
OPT ?= 0
DEBUG =
#DEBUG = dwarf-2

INCDIRS = ./$(ST_LIB) ./$(ST_USB)
Expand Down
24 changes: 12 additions & 12 deletions dfu.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@
#include "usb.h"

/* DFU globals */
u32 userAppAddr = USER_CODE_RAM; /* default RAM user code location */
u32 userAppEnd = RAM_END;
DFUStatus dfuAppStatus; /* includes state */
bool userFlash = FALSE;
bool dfuBusy = FALSE;
static volatile u32 userAppAddr = USER_CODE_RAM; /* default RAM user code location */
static volatile u32 userAppEnd = RAM_END;
static volatile DFUStatus dfuAppStatus; /* includes state */
static volatile bool userFlash = FALSE;
volatile bool dfuBusy = FALSE;

u8 recvBuffer[wTransferSize];
u32 userFirmwareLen = 0;
u16 thisBlockLen = 0;
u16 uploadBlockLen = 0;
static volatile u8 recvBuffer[wTransferSize] __attribute__((aligned(4)));
static volatile u32 userFirmwareLen = 0;
static volatile u16 thisBlockLen = 0;
static volatile u16 uploadBlockLen = 0;


PLOT code_copy_lock;
volatile PLOT code_copy_lock;

/* todo: force dfu globals to be singleton to avoid re-inits? */
void dfuInit(void) {
Expand Down Expand Up @@ -330,7 +330,7 @@ u8 *dfuCopyStatus(u16 length) {
pInformation->Ctrl_Info.Usb_wLength = 6;
return NULL;
} else {
return(&dfuAppStatus);
return (u8*)(&dfuAppStatus);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some reason why you cast to u8_, instead of DFUStatus_?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because it's the return type of the method

}
}

Expand Down Expand Up @@ -371,7 +371,7 @@ void dfuCopyBufferToExec() {
flashErasePage((u32)(userSpace));

for (i = 0; i < thisBlockLen; i = i + 4) {
flashWriteWord(userSpace++, *(u32 *)(recvBuffer + i));
flashWriteWord((u32)(userSpace++), *(u32 *)(recvBuffer +i));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The built-in unaligned access support will make this work, but can you please add an __attribute__((aligned(4)) to the recvBuffer definition, above, just for speed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it's done

}

}
Expand Down
2 changes: 1 addition & 1 deletion dfu.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ typedef enum _PLOT {



extern bool dfuBusy;
extern volatile bool dfuBusy;

/* exposed functions */
void dfuInit(void); /* singleton dfu initializer */
Expand Down