How To Using FMC Write?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-18 2:49 AM - last edited on ‎2024-06-19 12:58 AM by mƎALLEm
I encountered a problem when trying to send more than 5 bytes of data using the FMC.
// impossible example --
#define SD_DATA (*(volatile unsigned char *)0x60000001)
SD_DATA = 0x01;
SD_DATA = 0x02;
SD_DATA = 0x03;
// possible example -- 1
#define SD_DATA (*(volatile unsigned char *)0x60000001)
SD_DATA = 0x01;
HAL_Delay(1);
SD_DATA = 0x02;
HAL_Delay(1);
SD_DATA = 0x03;
// possible example -- 2
#define SD_DATA1 (*(volatile unsigned char *)0x60000001)
#define SD_DATA2 (*(volatile unsigned char *)0x60000002)
#define SD_DATA3 (*(volatile unsigned char *)0x60000003)
SD_DATA1 = 0x01;
SD_DATA2 = 0x02;
SD_DATA3 = 0x03;
static void MX_FMC_Init(void)
{
FMC_NORSRAM_TimingTypeDef Timing;
/** Perform the NOR1 memory initialization sequence
*/
hnor1.Instance = FMC_NORSRAM_DEVICE;
hnor1.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
/* hnor1.Init */
hnor1.Init.NSBank = FMC_NORSRAM_BANK1;
hnor1.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
hnor1.Init.MemoryType = FMC_MEMORY_TYPE_NOR;
hnor1.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_8;
hnor1.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
hnor1.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
hnor1.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
hnor1.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
hnor1.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
hnor1.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
hnor1.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
hnor1.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
hnor1.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
hnor1.Init.WriteFifo = FMC_WRITE_FIFO_ENABLE;
hnor1.Init.PageSize = FMC_PAGE_SIZE_NONE;
/* Timing */
Timing.AddressSetupTime = 15;
Timing.AddressHoldTime = 15;
Timing.DataSetupTime = 31;
Timing.BusTurnAroundDuration = 8;
Timing.CLKDivision = 16;
Timing.DataLatency = 17;
Timing.AccessMode = FMC_ACCESS_MODE_A;
/* ExtTiming */
if (HAL_NOR_Init(&hnor1, &Timing, NULL) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
Solved! Go to Solution.
- Labels:
-
STM32Cube MCU Packages
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-26 6:32 PM
Due to repeated swap errors, I resolved the issue by clearing the cache.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-18 2:58 AM
Hello and welcome to the community.
Please use the button </> to insert your code.
Please read these recommendations on how to post a thread: https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228
Thank you for your understanding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-18 5:29 AM
In MPU, set given area to be Device (it's Normal by default, which implies that the processor can merge accesses as it sees fit).
Alternatively, you can use the remap using SYSCFG_MEMRMP.SWP_FMC, the memory area starting at 0xC000'0000 is in MPU set as Device by default.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-18 5:29 PM
We used NE1 of the FMC to map the address in the hardware. Does this mean it needs to be remapped to 0xC0000000? What is the reason for mapping to 0xC0000000?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-18 11:31 PM
I used this code to swap 0x60000000 to 0xC0000000, but a hard fault occurs.
void FMC_MemoryRemap(void) {
SYSCFG->MEMRMP |= SYSCFG_MEMRMP_SWP_FMC_0;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-19 1:51 AM - edited ‎2024-06-19 1:53 AM
> What is the reason for mapping to 0xC0000000?
As I've said above, to have the SRAM in a MPU area tagged as Device. As I've said above, the alternative to remap is to set the SRAM area to Device in MPU.
> but a hard fault occurs
Where? Why? Do you still attempt to write to 0x6000'0000?
Else, debug the hardfault as usually.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-19 2:19 AM
I wrote the following code and changed all instances of 0x60000000 to 0xC0000000. However, a HardFault is occurring.
ex)
#define ZD_DATA (*(volatile unsigned char *)0xC0000000)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-19 2:43 AM
You have the FMC properly initialized and the swap performed?
> HardFault is occurring
Where? Single-step in disasm to find out the exact instruction.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-20 1:59 AM
Upon running, a HardFault occurs immediately.
If I remove the line
SYSCFG->MEMRMP |= SYSCFG_MEMRMP_SWP_FMC_0;
the HardFault disappears.
Even without this code, attempting to access the address 0xC0000000 results in a HardFault.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-20 3:35 AM
I have noticed that using BANK1 in FMC_Init causes a hard fault at addresses starting from 0x6000.0000. This issue does not occur with BANK2. What could be the reason for this? Isn't the address for BANK2 starting from 0x7000.0000?
