Skip to content

Commit b4e915f

Browse files
Fix QSPI flash, add option to use DMA in circular mode
1 parent 40da43e commit b4e915f

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed

storage/blockdevice/COMPONENT_QSPIF/mbed_lib.json renamed to storage/blockdevice/COMPONENT_QSPIF/mbed_lib.json5

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
"MCU_LPC546XX": {
5555
"QSPI_MIN_READ_SIZE": "4",
5656
"QSPI_MIN_PROG_SIZE": "4"
57+
},
58+
"ARDUINO_GIGA": {
59+
"QSPI_POLARITY_MODE": "QSPIF_POLARITY_MODE_1",
60+
// The flash on this board (AT25SF128A) is quite old and does not have reset information in its
61+
// SFDP table.
62+
"enable-and-reset": true
5763
}
5864
}
5965
}

targets/TARGET_STM/qspi_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ qspi_status_t qspi_prepare_command(const qspi_command_t *command, OSPI_RegularCm
234234
#else /* OCTOSPI */
235235
qspi_status_t qspi_prepare_command(const qspi_command_t *command, QSPI_CommandTypeDef *st_command)
236236
{
237-
debug_if(qspi_api_c_debug, "qspi_prepare_command In: instruction.value %x dummy_count %x address.bus_width %x address.disabled %x address.value %x address.size %x\n",
237+
debug_if(qspi_api_c_debug, "qspi_prepare_command In: instruction.value 0x%" PRIx8 " dummy_count 0x%" PRIx8 " address.bus_width 0x%x address.disabled %d address.value 0x%" PRIx32 " address.size %x\n",
238238
command->instruction.value, command->dummy_count, command->address.bus_width, command->address.disabled, command->address.value, command->address.size);
239239

240240
// TODO: shift these around to get more dynamic mapping
@@ -372,7 +372,7 @@ qspi_status_t qspi_prepare_command(const qspi_command_t *command, QSPI_CommandTy
372372

373373
st_command->NbData = 0;
374374

375-
debug_if(qspi_api_c_debug, "qspi_prepare_command Out: InstructionMode %x Instruction %x AddressMode %x AddressSize %x Address %x DataMode %x\n",
375+
debug_if(qspi_api_c_debug, "qspi_prepare_command Out: InstructionMode 0x%" PRIx32 " Instruction 0x%" PRIx32 " AddressMode 0x%" PRIx32 " AddressSize 0x%" PRIx32 " Address 0x%" PRIx32 " DataMode %" PRIx32 "\n",
376376
st_command->InstructionMode, st_command->Instruction, st_command->AddressMode, st_command->AddressSize, st_command->Address, st_command->DataMode);
377377

378378
return QSPI_STATUS_OK;

targets/TARGET_STM/stm_dma_utils.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ DMA_HandleTypeDef *stm_get_dma_handle_for_link(DMALinkInfo const * dmaLink)
572572
}
573573

574574
DMA_HandleTypeDef *stm_init_dma_link(const DMALinkInfo *dmaLink, uint32_t direction, bool periphInc, bool memInc,
575-
uint8_t periphDataAlignment, uint8_t memDataAlignment){
575+
uint8_t periphDataAlignment, uint8_t memDataAlignment, uint32_t mode){
576576

577577
#ifdef DMA_IP_VERSION_V2
578578
// Channels start from 1 in IP v2 only
@@ -640,6 +640,7 @@ DMA_HandleTypeDef *stm_init_dma_link(const DMALinkInfo *dmaLink, uint32_t direct
640640

641641
#endif
642642
dmaHandle->Init.Direction = direction;
643+
dmaHandle->Init.Mode = mode;
643644

644645
// IP v3 uses different fields for... basically everything in this struct
645646
#ifdef DMA_IP_VERSION_V3
@@ -761,8 +762,6 @@ DMA_HandleTypeDef *stm_init_dma_link(const DMALinkInfo *dmaLink, uint32_t direct
761762

762763
#endif
763764

764-
dmaHandle->Init.Mode = DMA_NORMAL;
765-
766765
HAL_DMA_Init(dmaHandle);
767766

768767
// Set up interrupt

targets/TARGET_STM/stm_dma_utils.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,13 @@ DMA_HandleTypeDef * stm_get_dma_handle_for_link(DMALinkInfo const * dmaLink);
122122
* @param periphInc Whether the Peripheral address register should be incremented or not.
123123
* @param memInc Whether the Memory address register should be incremented or not.
124124
* @param periphDataAlignment Alignment value of the peripheral data. 1, 2, or 4.
125-
* @param memDataAlignment \c DMA_MDATAALIGN_BYTE, \c DMA_MDATAALIGN_HALFWORD, or \c DMA_MDATAALIGN_WORD
125+
* @param memDataAlignment Alignment value of the memory data. 1, 2, or 4.
126+
* @param mode Mode of the DMA transaction. DMA_NORMAL, DMA_CIRCULAR, etc
126127
*
127128
* @return Pointer to DMA handle allocated by this module.
128129
* @return NULL if the DMA channel used by the link has already been allocated by something else.
129130
*/
130-
DMA_HandleTypeDef * stm_init_dma_link(DMALinkInfo const * dmaLink, uint32_t direction, bool periphInc, bool memInc, uint8_t periphDataAlignment, uint8_t memDataAlignment);
131+
DMA_HandleTypeDef * stm_init_dma_link(DMALinkInfo const * dmaLink, uint32_t direction, bool periphInc, bool memInc, uint8_t periphDataAlignment, uint8_t memDataAlignment, uint32_t mode);
131132

132133
/**
133134
* @brief Free a DMA link.

targets/TARGET_STM/stm_spi_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ static void spi_init_tx_dma(struct spi_s * obj)
531531
DMALinkInfo const *dmaLink = &SPITxDMALinks[obj->spiIndex - 1];
532532

533533
// Initialize DMA channel
534-
DMA_HandleTypeDef *dmaHandle = stm_init_dma_link(dmaLink, DMA_MEMORY_TO_PERIPH, false, true, 1, 1);
534+
DMA_HandleTypeDef *dmaHandle = stm_init_dma_link(dmaLink, DMA_MEMORY_TO_PERIPH, false, true, 1, 1, DMA_NORMAL);
535535

536536
if(dmaHandle == NULL)
537537
{
@@ -564,7 +564,7 @@ static void spi_init_rx_dma(struct spi_s * obj)
564564
DMALinkInfo const *dmaLink = &SPIRxDMALinks[obj->spiIndex - 1];
565565

566566
// Initialize DMA channel
567-
DMA_HandleTypeDef *dmaHandle = stm_init_dma_link(dmaLink, DMA_PERIPH_TO_MEMORY, false, true, 1, 1);
567+
DMA_HandleTypeDef *dmaHandle = stm_init_dma_link(dmaLink, DMA_PERIPH_TO_MEMORY, false, true, 1, 1, DMA_NORMAL);
568568

569569
if(dmaHandle == NULL)
570570
{

targets/targets.json5

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3684,7 +3684,13 @@
36843684
clock_source: "USE_PLL_HSE_XTAL | USE_PLL_HSI",
36853685
"network-default-interface-type": "WIFI",
36863686
lpuart_clock_source: "USE_LPUART_CLK_HSI",
3687-
"hse_value": 16000000
3687+
"hse_value": 16000000,
3688+
3689+
// Arduino Giga connects the primary USB port (USB-C port) to the USB Full Speed pins.
3690+
// TODO eventually this needs to be runtime configurable so that the two USB ports
3691+
// can use different speeds. With the current setting, Mbed will not be able to use
3692+
// the host mode port as that port uses high speed.
3693+
"usb_speed": "USE_USB_OTG_FS",
36883694
},
36893695
macros_add: [
36903696
"BT_UART_NO_3M_SUPPORT"

0 commit comments

Comments
 (0)