Skip to content

Flash programming bugfixes #2

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions src/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ uint32_t erased_page_flags = 0;

void flash_erase_page(uint8_t page) {
// Don't let's erase the bootloader, please
if (page < USER_FIRST_PAGE)
if ((page < USER_FIRST_PAGE) || (page >= FLASH_PAGES))
return;

// Waiting for the flash controller to be ready
Expand Down Expand Up @@ -149,10 +149,12 @@ void flash_check_and_erase(uint8_t page) {
}

void flash_check_erase_and_write(uint16_t buff[], uint16_t len, uint16_t flash_addr) {
// NOTE: len is the number of 16-bit words to transfer

uint8_t i, start_page, end_page;

start_page = flash_addr / 1024;
end_page = (flash_addr + len) / 1024;
end_page = (flash_addr + (2 * len) - 1) / 1024;

// Check and erase pages in range
for (i=start_page; i<=end_page; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void bootloader_main ()
case IHX_RECORD_READ:
// Read out a section of flash over USB
read_start_addr = ihx_record_address(buff);
read_len = ihx_data_byte(buff, 0)<<8 + ihx_data_byte(buff, 1);
read_len = (ihx_data_byte(buff, 0)<<8) + ihx_data_byte(buff, 1);
usb_putchar('\n');
ihx_read_print((__xdata uint8_t*)read_start_addr, read_len);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ static void usb_ep0_setup()
}
break;
}
if (usb_ep0_state != USB_EP0_DATA_OUT) {
if (usb_ep0_state == USB_EP0_DATA_IN) {
if (usb_setup.length < usb_ep0_in_len)
usb_ep0_in_len = usb_setup.length;
usb_ep0_flush();
Expand Down