From 2970de9f92243b11d3beef56f3b1df3ef3579b95 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Jun 2016 22:05:24 -0700 Subject: stmf0: Clear all USB state when resetting chip. Wakeup all sleepers When USB is reset, but the board is not power cycled, all of the internal USB state needs to be reset, and any tasks blocked on sending or receiving packets need to be awoken so they can go wait for USB to start running again. Signed-off-by: Keith Packard --- src/stmf0/ao_usb_stm.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/stmf0') diff --git a/src/stmf0/ao_usb_stm.c b/src/stmf0/ao_usb_stm.c index 253506d5..a67fc868 100644 --- a/src/stmf0/ao_usb_stm.c +++ b/src/stmf0/ao_usb_stm.c @@ -437,6 +437,17 @@ ao_usb_set_ep0(void) ao_usb_set_address(0); ao_usb_running = 0; + + /* Reset our internal state + */ + + ao_usb_ep0_state = AO_USB_EP0_IDLE; + + ao_usb_ep0_in_data = NULL; + ao_usb_ep0_in_len = 0; + + ao_usb_ep0_out_data = 0; + ao_usb_ep0_out_len = 0; } static void @@ -493,6 +504,20 @@ ao_usb_set_configuration(void) STM_USB_EPR_STAT_TX_NAK); #endif + ao_usb_in_flushed = 0; + ao_usb_in_pending = 0; + ao_wakeup(&ao_usb_in_pending); +#if AO_USB_HAS_IN2 + ao_usb_in2_flushed = 0; + ao_usb_in2_pending = 0; + ao_wakeup(&ao_usb_in2_pending); +#endif + + ao_usb_out_avail = 0; + ao_usb_configuration = 0; + + ao_wakeup(AO_USB_OUT_SLEEP_ADDR); + ao_usb_running = 1; #if AO_USB_DIRECTIO ao_wakeup(&ao_usb_running); -- cgit v1.2.3 From 36ba97fabbed2f2a4a89da5be221c630ea3ff66f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Jun 2016 22:06:30 -0700 Subject: stmf0: Do not send more data than requested for GET_DESCRIPTOR When Linux boots, it asks for only the first 8 bytes of the device descriptor; we must limit the amount of data sent back to that amount or USB will get wedged. Signed-off-by: Keith Packard --- src/stmf0/ao_usb_stm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/stmf0') diff --git a/src/stmf0/ao_usb_stm.c b/src/stmf0/ao_usb_stm.c index a67fc868..63b35b24 100644 --- a/src/stmf0/ao_usb_stm.c +++ b/src/stmf0/ao_usb_stm.c @@ -683,7 +683,7 @@ ao_usb_serial_init(void) /* Walk through the list of descriptors and find a match */ static void -ao_usb_get_descriptor(uint16_t value) +ao_usb_get_descriptor(uint16_t value, uint16_t length) { const uint8_t *descriptor; uint8_t type = value >> 8; @@ -704,6 +704,8 @@ ao_usb_get_descriptor(uint16_t value) len = sizeof (ao_usb_serial); } #endif + if (len > length) + len = length; ao_usb_ep0_in_set(descriptor, len); break; } @@ -748,7 +750,7 @@ ao_usb_ep0_setup(void) break; case AO_USB_REQ_GET_DESCRIPTOR: debug ("get descriptor %d\n", ao_usb_setup.value); - ao_usb_get_descriptor(ao_usb_setup.value); + ao_usb_get_descriptor(ao_usb_setup.value, ao_usb_setup.length); break; case AO_USB_REQ_GET_CONFIGURATION: debug ("get configuration %d\n", ao_usb_configuration); -- cgit v1.2.3 From 1704d27248f1845c545ec61cf1bad58bf41189af Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 11 Jun 2016 22:16:12 -0700 Subject: altos/stmf0: Rework the sram allocation to save a few text bytes Boot loaders were going over 4096 bytes of ROM. I suspect we'll need more serious work soon. Signed-off-by: Keith Packard --- src/stmf0/ao_usb_stm.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'src/stmf0') diff --git a/src/stmf0/ao_usb_stm.c b/src/stmf0/ao_usb_stm.c index 63b35b24..6393ee44 100644 --- a/src/stmf0/ao_usb_stm.c +++ b/src/stmf0/ao_usb_stm.c @@ -83,7 +83,9 @@ static uint8_t ao_usb_ep0_out_len; /* Buffer description tables */ static union stm_usb_bdt *ao_usb_bdt; /* USB address of end of allocated storage */ +#if AO_USB_DIRECTIO static uint16_t ao_usb_sram_addr; +#endif /* Pointer to ep0 tx/rx buffers in USB memory */ static uint16_t *ao_usb_ep0_tx_buffer; @@ -362,39 +364,43 @@ ao_usb_init_ep(uint8_t ep, uint32_t addr, uint32_t type, uint32_t stat_rx, uint3 static void ao_usb_alloc_buffers(void) { - ao_usb_sram_addr = 0; + uint16_t sram_addr = 0; ao_usb_bdt = (void *) stm_usb_sram; - ao_usb_sram_addr += 8 * STM_USB_BDT_SIZE; + sram_addr += 8 * STM_USB_BDT_SIZE; - ao_usb_ep0_tx_buffer = ao_usb_packet_buffer_addr(ao_usb_sram_addr); - ao_usb_sram_addr += AO_USB_CONTROL_SIZE; + ao_usb_ep0_tx_buffer = ao_usb_packet_buffer_addr(sram_addr); + sram_addr += AO_USB_CONTROL_SIZE; - ao_usb_ep0_rx_buffer = ao_usb_packet_buffer_addr(ao_usb_sram_addr); - ao_usb_sram_addr += AO_USB_CONTROL_SIZE; + ao_usb_ep0_rx_buffer = ao_usb_packet_buffer_addr(sram_addr); + sram_addr += AO_USB_CONTROL_SIZE; #if AO_USB_HAS_INT - ao_usb_int_tx_offset = ao_usb_sram_addr; - ao_usb_sram_addr += AO_USB_INT_SIZE; + ao_usb_int_tx_offset = sram_addr; + sram_addr += AO_USB_INT_SIZE; #endif #if AO_USB_HAS_OUT - ao_usb_out_rx_buffer = ao_usb_packet_buffer_addr(ao_usb_sram_addr); - ao_usb_out_rx_offset = ao_usb_sram_addr; - ao_usb_sram_addr += AO_USB_OUT_SIZE; + ao_usb_out_rx_buffer = ao_usb_packet_buffer_addr(sram_addr); + ao_usb_out_rx_offset = sram_addr; + sram_addr += AO_USB_OUT_SIZE; #endif #if AO_USB_HAS_IN - ao_usb_in_tx_buffer = ao_usb_packet_buffer_addr(ao_usb_sram_addr); - ao_usb_in_tx_offset = ao_usb_sram_addr; - ao_usb_sram_addr += AO_USB_IN_SIZE; + ao_usb_in_tx_buffer = ao_usb_packet_buffer_addr(sram_addr); + ao_usb_in_tx_offset = sram_addr; + sram_addr += AO_USB_IN_SIZE; #endif #if AO_USB_HAS_IN2 - ao_usb_in2_tx_buffer = ao_usb_packet_buffer_addr(ao_usb_sram_addr); - ao_usb_in2_tx_offset = ao_usb_sram_addr; - ao_usb_sram_addr += AO_USB_IN_SIZE; + ao_usb_in2_tx_buffer = ao_usb_packet_buffer_addr(sram_addr); + ao_usb_in2_tx_offset = sram_addr; + sram_addr += AO_USB_IN_SIZE; +#endif + +#if AO_USB_DIRECTIO + ao_usb_sram_addr = sram_addr; #endif } -- cgit v1.2.3 From eee7fa303fb0d80ac5d7b9c5a86af60333f61951 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 11 Jun 2016 22:17:01 -0700 Subject: altos/stmf0: Remove ao_usb_free This can't work without a lot more effort. Signed-off-by: Keith Packard --- src/stmf0/ao_arch_funcs.h | 3 --- src/stmf0/ao_usb_stm.c | 8 -------- 2 files changed, 11 deletions(-) (limited to 'src/stmf0') diff --git a/src/stmf0/ao_arch_funcs.h b/src/stmf0/ao_arch_funcs.h index ccfa3fc7..64311b23 100644 --- a/src/stmf0/ao_arch_funcs.h +++ b/src/stmf0/ao_arch_funcs.h @@ -408,9 +408,6 @@ static inline void ao_arch_start_scheduler(void) { uint16_t * ao_usb_alloc(void); -void -ao_usb_free(uint16_t *buffer); - void ao_usb_write(uint16_t *buffer, uint16_t len); diff --git a/src/stmf0/ao_usb_stm.c b/src/stmf0/ao_usb_stm.c index 6393ee44..fb3d8c85 100644 --- a/src/stmf0/ao_usb_stm.c +++ b/src/stmf0/ao_usb_stm.c @@ -1191,14 +1191,6 @@ ao_usb_alloc(void) return buffer; } -void -ao_usb_free(uint16_t *addr) -{ - uint16_t offset = ao_usb_packet_buffer_offset(addr); - if (offset < ao_usb_sram_addr) - ao_usb_sram_addr = offset; -} - void ao_usb_write(uint16_t *buffer, uint16_t len) { -- cgit v1.2.3