integrated usb stack

This commit is contained in:
Bernd Herzog 2023-03-30 11:46:36 +02:00
parent 8dd68a0811
commit a6eb430830
6 changed files with 128 additions and 10 deletions

View File

@ -26,7 +26,17 @@
namespace ui { namespace ui {
SdOverUsbView::SdOverUsbView(NavigationView& nav) : nav_ (nav) { SdOverUsbView::SdOverUsbView(NavigationView& nav) : nav_ (nav) {
baseband::run_image(portapack::spi_flash::image_tag_usb_sd);
sdcDisconnect(&SDCD1);
sdcStop(&SDCD1);
portapack::shutdown();
m4_init(portapack::spi_flash::image_tag_usb_sd, portapack::memory::map::m4_code, true);
//m4_init(portapack::spi_flash::image_tag_hackrf, portapack::memory::map::m4_code_hackrf, true);
m0_halt(); /* will not return*/
//baseband::run_image();
add_children({ add_children({
&labels, &labels,
&button_close &button_close

View File

@ -534,8 +534,29 @@ set(MODE_CPPSRC
${HACKRF_PATH}/firmware/common/usb_queue.c ${HACKRF_PATH}/firmware/common/usb_queue.c
${HACKRF_PATH}/firmware/common/usb_request.c ${HACKRF_PATH}/firmware/common/usb_request.c
${HACKRF_PATH}/firmware/common/usb_standard_request.c ${HACKRF_PATH}/firmware/common/usb_standard_request.c
${HACKRF_PATH}/firmware/common/platform_detect.c
${HACKRF_PATH}/firmware/common/hackrf_core.c
${HACKRF_PATH}/firmware/common/gpio_lpc.c
${HACKRF_PATH}/firmware/common/firmware_info.c
${HACKRF_PATH}/firmware/common/si5351c.c
${HACKRF_PATH}/firmware/common/i2c_bus.c
${HACKRF_PATH}/firmware/common/mixer.c
${HACKRF_PATH}/firmware/common/clkin.c
${HACKRF_PATH}/firmware/common/spi_bus.c
${HACKRF_PATH}/firmware/common/sgpio.c
${HACKRF_PATH}/firmware/common/rf_path.c
${HACKRF_PATH}/firmware/common/i2c_lpc.c
${HACKRF_PATH}/firmware/common/spi_ssp.c
${HACKRF_PATH}/firmware/common/rffc5071_spi.c
${HACKRF_PATH}/firmware/common/rffc5071.c
${HACKRF_PATH}/firmware/common/clkin.c
${HACKRF_PATH}/firmware/common/gpdma.c
${HACKRF_PATH}/firmware/libopencm3/lib/cm3/nvic.c ${HACKRF_PATH}/firmware/libopencm3/lib/cm3/nvic.c
${HACKRF_PATH}/firmware/libopencm3/lib/cm3/sync.c ${HACKRF_PATH}/firmware/libopencm3/lib/cm3/sync.c
${HACKRF_PATH}/firmware/libopencm3/lib/lpc43xx/scu.c
${HACKRF_PATH}/firmware/libopencm3/lib/lpc43xx/timer.c
${HACKRF_PATH}/firmware/libopencm3/lib/lpc43xx/i2c.c
) )
DeclareTargets(PUSB sd_over_usb) DeclareTargets(PUSB sd_over_usb)

View File

@ -40,10 +40,35 @@ CH_IRQ_HANDLER(Vector60) {
} }
int main() { int main() {
EventDispatcher event_dispatcher { std::make_unique<USBProcessor>() }; //EventDispatcher event_dispatcher { std::make_unique<USBProcessor>() };
HALT_UNTIL_DEBUGGING();
//HALT_UNTIL_DEBUGGING();
//LPC_CGU->PLL0USB_CTRL.PD = 1;
//LPC_CGU->PLL0USB_CTRL.AUTOBLOCK = 1;
//LPC_CGU->PLL0USB_CTRL.CLK_SEL = 0x06;
//
//while (LPC_CGU->PLL0USB_STAT.LOCK) {}
//
//LPC_CGU->PLL0USB_MDIV = 0x06167FFA; // 0x71A7FAA; //
//LPC_CGU->PLL0USB_NP_DIV = 0x00302062;
//
////LPC_CGU->PLL0USB_CTRL.PD |= 1;
//LPC_CGU->PLL0USB_CTRL.DIRECTI = 1;
//LPC_CGU->PLL0USB_CTRL.DIRECTO = 1;
//LPC_CGU->PLL0USB_CTRL.CLKEN = 1;
//
//LPC_CGU->PLL0USB_CTRL.PD = 0;
//
//while (!(LPC_CGU->PLL0USB_STAT.LOCK)) {}
////chThdSleepMilliseconds(800);
//
//LPC_CGU->BASE_USB0_CLK.AUTOBLOCK = 1;
//LPC_CGU->BASE_USB0_CLK.CLK_SEL = 0x07;
start_usb(); start_usb();
event_dispatcher.run(); //event_dispatcher.run();
while (true);
stop_usb(); stop_usb();
return 0; return 0;
} }

View File

@ -45,8 +45,59 @@ const usb_request_handlers_t usb_request_handlers = {
}; };
void usb_configuration_changed(usb_device_t* const device)
{
/* Reset transceiver to idle state until other commands are received */
// request_transceiver_mode(TRANSCEIVER_MODE_OFF);
// if (device->configuration->number == 1) {
// // transceiver configuration
// led_on(LED1);
// } else {
// /* Configuration number equal 0 means usb bus reset. */
// led_off(LED1);
// }
usb_endpoint_init(&usb_endpoint_bulk_in);
usb_endpoint_init(&usb_endpoint_bulk_out);
}
void start_usb(void) { void start_usb(void) {
/* use XTAL_OSC as clock source for PLL0USB */
// CGU_PLL0USB_CTRL =
// CGU_PLL0USB_CTRL_PD(1) /* PLL0 power down */ |
// CGU_PLL0USB_CTRL_AUTOBLOCK(1) /* Block clock automatically during frequency change */ |
// CGU_PLL0USB_CTRL_CLK_SEL(CGU_SRC_XTAL); /* Clock source selection */
// while (CGU_PLL0USB_STAT & CGU_PLL0USB_STAT_LOCK_MASK) {}
/* configure PLL0USB to produce 480 MHz clock from 12 MHz XTAL_OSC */
/* Values from User Manual v1.4 Table 94, for 12MHz oscillator. */
// CGU_PLL0USB_MDIV = 0x06167FFA;
// CGU_PLL0USB_NP_DIV = 0x00302062;
// CGU_PLL0USB_CTRL |=
// CGU_PLL0USB_CTRL_PD(1) /* PLL0 power down */ |
// CGU_PLL0USB_CTRL_DIRECTI(1) /* PLL0 direct input */ |
// CGU_PLL0USB_CTRL_DIRECTO(1) /* PLL0 direct output */ |
// CGU_PLL0USB_CTRL_CLKEN(1) /* PLL0 clock enable */;
// /* power on PLL0USB and wait until stable */
// CGU_PLL0USB_CTRL &= ~CGU_PLL0USB_CTRL_PD_MASK /* PLL0 power down */ ;
// while (!(CGU_PLL0USB_STAT & CGU_PLL0USB_STAT_LOCK_MASK)) {}
/* use PLL0USB as clock source for USB0 */
// CGU_BASE_USB0_CLK = CGU_BASE_USB0_CLK_AUTOBLOCK(1) |
// CGU_BASE_USB0_CLK_CLK_SEL(CGU_SRC_PLL0USB);
detect_hardware_platform();
pin_setup();
cpu_clock_init();
usb_set_configuration_changed_cb(usb_configuration_changed);
usb_peripheral_reset(); usb_peripheral_reset();
usb_device_init(0, &usb_device); usb_device_init(0, &usb_device);

View File

@ -30,6 +30,9 @@
#include "usb_device.h" #include "usb_device.h"
#include "usb_endpoint.h" #include "usb_endpoint.h"
#include <libopencm3/lpc43xx/m4/nvic.h> #include <libopencm3/lpc43xx/m4/nvic.h>
#include <libopencm3/lpc43xx/cgu.h>
#include "platform_detect.h"
#include "hackrf_core.h"
void start_usb(void); void start_usb(void);
void stop_usb(void); void stop_usb(void);

View File

@ -186,18 +186,26 @@ uint8_t usb_descriptor_string_manufacturer[] = {
uint8_t usb_descriptor_string_product[] = { uint8_t usb_descriptor_string_product[] = {
#ifdef HACKRF_ONE #ifdef HACKRF_ONE
22, // bLength 43, // bLength
USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType
'H', 0x00, 'P', 0x00,
'o', 0x00,
'r', 0x00,
't', 0x00,
'a', 0x00,
'P', 0x00,
'a', 0x00, 'a', 0x00,
'c', 0x00, 'c', 0x00,
'k', 0x00, 'k', 0x00,
'R', 0x00,
'F', 0x00,
' ', 0x00, ' ', 0x00,
'O', 0x00,
'n', 0x00, 'M', 0x00,
'a', 0x00,
'y', 0x00,
'h', 0x00,
'e', 0x00, 'e', 0x00,
'm', 0x00,
#elif JAWBREAKER #elif JAWBREAKER
36, // bLength 36, // bLength
USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType