Skip to content

Commit

Permalink
Merge pull request #11 from dhalbert/merges_and_np_fix
Browse files Browse the repository at this point in the history
Merges and np fix
  • Loading branch information
ladyada authored Feb 24, 2018
2 parents ae5806e + 72e311b commit 96aa5ea
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ifeq ($(CHIP_FAMILY), samd51)
COMMON_FLAGS = -mthumb -mcpu=cortex-m4 -O2 -g -DSAMD51
endif
WFLAGS = \
-Wall -Wstrict-prototypes \
-Werror -Wall -Wstrict-prototypes \
-Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 \
-ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 \
-Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch \
Expand Down Expand Up @@ -175,6 +175,6 @@ drop-pkg:
rm -rf build/uf2-samd21-$(UF2_VERSION_BASE)

all-boards:
for f in `cd boards; ls` ; do "$(MAKE)" BOARD=$$f drop-board ; done
for f in `cd boards; ls` ; do "$(MAKE)" BOARD=$$f drop-board || break; done

drop: all-boards drop-pkg
8 changes: 4 additions & 4 deletions scripts/samd51j19a.ld
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ SEARCH_DIR(.)
/* Memory Spaces Definitions */
MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x00080000
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00030000
rom (rx) : ORIGIN = 0x00000000, LENGTH = 16K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 192K
}

/* The stack size used by the application. NOTE: you need to adjust according to your application. */
STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : DEFINED(__stack_size__) ? __stack_size__ : 0xC000;
STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : DEFINED(__stack_size__) ? __stack_size__ : 48K;

/* Section Definitions */
SECTIONS
Expand Down Expand Up @@ -144,7 +144,7 @@ SECTIONS
. = ALIGN(4);
_end = . ;

_binfo_start = 0x00002000 - 4 * 4;
_binfo_start = 16K - 4 * 4;
.binfo _binfo_start : {
KEEP(*(.binfo)) ;
} > rom
Expand Down
45 changes: 22 additions & 23 deletions src/cdc_enumerate.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ const char hidDescriptor[] = {
};
#endif

#ifndef USB_POWER_MA
#define USB_POWER_MA 500
#endif
__attribute__((__aligned__(4)))
char cfgDescriptor[] = {
/* ============== CONFIGURATION 1 =========== */
Expand All @@ -117,7 +120,7 @@ char cfgDescriptor[] = {
0x01, // CbConfigurationValue
0x00, // CiConfiguration
0x80, // CbmAttributes 0x80 - bus-powered
250, // 500mA
USB_POWER_MA/2, // MaxPower (*2mA)

#if USE_CDC
// IAD for CDC
Expand Down Expand Up @@ -171,7 +174,7 @@ char cfgDescriptor[] = {
/* Endpoint 1 descriptor */
0x07, // bLength
0x05, // bDescriptorType
0x83, // bEndpointAddress, Endpoint 03 - IN
USB_EP_COMM | 0x80, // bEndpointAddress, Endpoint 03 - IN
0x03, // bmAttributes INT
0x08, // wMaxPacketSize
0x00,
Expand All @@ -192,7 +195,7 @@ char cfgDescriptor[] = {
/* Endpoint 1 descriptor */
0x07, // bLength
0x05, // bDescriptorType
0x81, // bEndpointAddress, Endpoint 01 - IN
USB_EP_IN | 0x80, // bEndpointAddress, Endpoint 01 - IN
0x02, // bmAttributes BULK
PKT_SIZE, // wMaxPacketSize
0x00,
Expand All @@ -201,7 +204,7 @@ char cfgDescriptor[] = {
/* Endpoint 2 descriptor */
0x07, // bLength
0x05, // bDescriptorType
0x02, // bEndpointAddress, Endpoint 02 - OUT
USB_EP_OUT, // bEndpointAddress, Endpoint 02 - OUT
0x02, // bmAttributes BULK
PKT_SIZE, // wMaxPacketSize
0x00,
Expand Down Expand Up @@ -387,15 +390,8 @@ static void load_serial_number(char serial_number[SERIAL_NUMBER_LENGTH]) {
#endif
uint32_t serial_number_idx = 0;
for (int i = 0; i < 4; i++) {
uint32_t word = *(addresses[i]);
for (int j = 0; j < 8; j++) {
// Get top 4 bits.
uint8_t nibble = word >> 28;
word <<= 4;
serial_number[serial_number_idx++] = (nibble >= 10) ? 'A' + (nibble - 10) : '0' + nibble;
}
serial_number_idx += writeNum(&(serial_number[serial_number_idx]), *(addresses[i]), true);
}

serial_number[serial_number_idx] = '\0';
}

Expand Down Expand Up @@ -799,22 +795,25 @@ void AT91F_CDC_Enumerate() {
sendCtrl(cfgDescriptor, sizeof(cfgDescriptor));
else if (ctrlOutCache.buf[3] == 3) {
if (ctrlOutCache.buf[2] >= STRING_DESCRIPTOR_COUNT)
{
stall_ep(0);
StringDescriptor desc = {0};
desc.type = 3;
if (ctrlOutCache.buf[2] == 0) {
desc.len = 4;
desc.data[0] = 0x09;
desc.data[1] = 0x04;
} else {
StringDescriptor desc = {0};
desc.type = 3;
if (ctrlOutCache.buf[2] == 0) {
desc.len = 4;
desc.data[0] = 0x09;
desc.data[1] = 0x04;
} else {
load_serial_number(serial_number);
const char *ptr = string_descriptors[ctrlOutCache.buf[2]];
desc.len = strlen(ptr) * 2 + 2;
for (int i = 0; ptr[i]; i++) {
desc.data[i * 2] = ptr[i];
const char *ptr = string_descriptors[ctrlOutCache.buf[2]];
desc.len = strlen(ptr) * 2 + 2;
for (int i = 0; ptr[i]; i++) {
desc.data[i * 2] = ptr[i];
}
}
sendCtrl(&desc, desc.len);
}
sendCtrl(&desc, sizeof(StringDescriptor));
} else if (ctrlOutCache.buf[3] == 0x0F) {
sendCtrl(bosDescriptor, sizeof(bosDescriptor));
}
Expand Down
14 changes: 8 additions & 6 deletions src/flash_samd51.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ bool row_same[FLASH_SIZE / NVMCTRL_BLOCK_SIZE][NVMCTRL_BLOCK_SIZE / FLASH_ROW_SI
#define QUICK_FLASH 1

void flash_write_row(uint32_t *dst, uint32_t *src) {
const uint32_t FLASH_ROW_SIZE_WORDS = FLASH_ROW_SIZE / 4;

// The cache in Rev A isn't reliable when reading and writing to the NVM.
NVMCTRL->CTRLA.bit.CACHEDIS0 = true;
NVMCTRL->CTRLA.bit.CACHEDIS1 = true;
Expand All @@ -85,7 +87,7 @@ void flash_write_row(uint32_t *dst, uint32_t *src) {
uint8_t row = (((uint32_t) dst) % NVMCTRL_BLOCK_SIZE) / FLASH_ROW_SIZE;
#if QUICK_FLASH
bool src_different = false;
for (uint32_t i = 0; i < FLASH_ROW_SIZE / 4; ++i) {
for (uint32_t i = 0; i < FLASH_ROW_SIZE_WORDS; ++i) {
if (src[i] != dst[i]) {
src_different = true;
break;
Expand All @@ -102,17 +104,17 @@ void flash_write_row(uint32_t *dst, uint32_t *src) {

if (!block_erased[block]) {
uint8_t rows_per_block = NVMCTRL_BLOCK_SIZE / FLASH_ROW_SIZE;
uint8_t* block_address = block * NVMCTRL_BLOCK_SIZE;
uint32_t* block_address = (uint32_t *) (block * NVMCTRL_BLOCK_SIZE);

bool some_rows_same = false;
for (uint8_t i = 0; i < rows_per_block; i++) {
some_rows_same = some_rows_same || row_same[block][i];
}
uint32_t row_cache[rows_per_block][FLASH_ROW_SIZE / 4];
uint32_t row_cache[rows_per_block][FLASH_ROW_SIZE_WORDS];
if (some_rows_same) {
for (uint8_t i = 0; i < rows_per_block; i++) {
if(row_same[block][i]) {
memcpy(row_cache[i], block_address + i * FLASH_ROW_SIZE, FLASH_ROW_SIZE);
memcpy(row_cache[i], block_address + i * FLASH_ROW_SIZE_WORDS, FLASH_ROW_SIZE);
}
}
}
Expand All @@ -123,13 +125,13 @@ void flash_write_row(uint32_t *dst, uint32_t *src) {
if(row_same[block][i]) {
// dst is a uint32_t pointer so we add the number of words,
// not bytes.
flash_write_words(block_address + i * FLASH_ROW_SIZE, row_cache[i], FLASH_ROW_SIZE / 4);
flash_write_words(block_address + i * FLASH_ROW_SIZE_WORDS, row_cache[i], FLASH_ROW_SIZE_WORDS);
}
}
}
}

flash_write_words(dst, src, FLASH_ROW_SIZE / 4);
flash_write_words(dst, src, FLASH_ROW_SIZE_WORDS);

// Don't return until we're done writing in case something after us causes
// a reset.
Expand Down
3 changes: 2 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ int main(void) {
while (1) {
}

#if USB_PID == 0x0013 // Metro m0
#if (USB_VID == 0x239a) && (USB_PID == 0x0013) // Adafruit Metro M0
// Delay a bit so SWD programmer can have time to attach.
delay(100);
#endif
led_init();
Expand Down
3 changes: 1 addition & 2 deletions src/usart_sam_ba.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ uint8_t mode_of_transfer;
* \brief Open the given USART
*/
void usart_open() {
uint32_t inst;
uint32_t port;
uint8_t pin;

Expand Down Expand Up @@ -103,7 +102,7 @@ void usart_open() {
}

#ifdef SAMD21
inst = uart_get_sercom_index(BOOT_USART_MODULE);
uint32_t inst = uart_get_sercom_index(BOOT_USART_MODULE);
/* Enable clock for BOOT_USART_MODULE */
PM->APBCMASK.reg |= (1u << (inst + PM_APBCMASK_SERCOM0_Pos));

Expand Down
2 changes: 1 addition & 1 deletion src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ void led_init() {
// using APA102, set pins to outputs
PINOP(BOARD_RGBLED_CLOCK_PIN, DIRSET);
PINOP(BOARD_RGBLED_DATA_PIN, DIRSET);
#endif

// This won't work for neopixel, because we're running at 1MHz or thereabouts...
RGBLED_set_color(COLOR_LEAVE);
#endif
}

#if defined(BOARD_RGBLED_CLOCK_PIN)
Expand Down

0 comments on commit 96aa5ea

Please sign in to comment.