Skip to content

Commit ba65afa

Browse files
Fix QSPI flash, add option to use DMA in circular mode
1 parent a5b8cb3 commit ba65afa

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
@@ -600,7 +600,7 @@ DMA_HandleTypeDef *stm_get_dma_handle_for_link(DMALinkInfo const * dmaLink)
600600
}
601601

602602
DMA_HandleTypeDef *stm_init_dma_link(const DMALinkInfo *dmaLink, uint32_t direction, bool periphInc, bool memInc,
603-
uint8_t periphDataAlignment, uint8_t memDataAlignment){
603+
uint8_t periphDataAlignment, uint8_t memDataAlignment, uint32_t mode){
604604

605605
#ifdef DMA_IP_VERSION_V2
606606
// Channels start from 1 in IP v2 only
@@ -668,6 +668,7 @@ DMA_HandleTypeDef *stm_init_dma_link(const DMALinkInfo *dmaLink, uint32_t direct
668668

669669
#endif
670670
dmaHandle->Init.Direction = direction;
671+
dmaHandle->Init.Mode = mode;
671672

672673
// IP v3 uses different fields for... basically everything in this struct
673674
#ifdef DMA_IP_VERSION_V3
@@ -789,8 +790,6 @@ DMA_HandleTypeDef *stm_init_dma_link(const DMALinkInfo *dmaLink, uint32_t direct
789790

790791
#endif
791792

792-
dmaHandle->Init.Mode = DMA_NORMAL;
793-
794793
HAL_DMA_Init(dmaHandle);
795794

796795
// 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
@@ -541,7 +541,7 @@ static void spi_init_tx_dma(struct spi_s * obj)
541541
DMALinkInfo const *dmaLink = &SPITxDMALinks[obj->spiIndex - 1];
542542

543543
// Initialize DMA channel
544-
DMA_HandleTypeDef *dmaHandle = stm_init_dma_link(dmaLink, DMA_MEMORY_TO_PERIPH, false, true, 1, 1);
544+
DMA_HandleTypeDef *dmaHandle = stm_init_dma_link(dmaLink, DMA_MEMORY_TO_PERIPH, false, true, 1, 1, DMA_NORMAL);
545545

546546
if(dmaHandle == NULL)
547547
{
@@ -574,7 +574,7 @@ static void spi_init_rx_dma(struct spi_s * obj)
574574
DMALinkInfo const *dmaLink = &SPIRxDMALinks[obj->spiIndex - 1];
575575

576576
// Initialize DMA channel
577-
DMA_HandleTypeDef *dmaHandle = stm_init_dma_link(dmaLink, DMA_PERIPH_TO_MEMORY, false, true, 1, 1);
577+
DMA_HandleTypeDef *dmaHandle = stm_init_dma_link(dmaLink, DMA_PERIPH_TO_MEMORY, false, true, 1, 1, DMA_NORMAL);
578578

579579
if(dmaHandle == NULL)
580580
{

targets/targets.json5

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3666,7 +3666,13 @@ mode is recommended for target MCUs with small amounts of flash and RAM.",
36663666
clock_source: "USE_PLL_HSE_XTAL | USE_PLL_HSI",
36673667
"network-default-interface-type": "WIFI",
36683668
lpuart_clock_source: "USE_LPUART_CLK_HSI",
3669-
"hse_value": 16000000
3669+
"hse_value": 16000000,
3670+
3671+
// Arduino Giga connects the primary USB port (USB-C port) to the USB Full Speed pins.
3672+
// TODO eventually this needs to be runtime configurable so that the two USB ports
3673+
// can use different speeds. With the current setting, Mbed will not be able to use
3674+
// the host mode port as that port uses high speed.
3675+
"usb_speed": "USE_USB_OTG_FS",
36703676
},
36713677
macros_add: [
36723678
"BT_UART_NO_3M_SUPPORT"

0 commit comments

Comments
 (0)