External SRAM with STMHAL: how to use it?

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
formica
Posts: 6
Joined: Thu Mar 30, 2017 10:47 pm

External SRAM with STMHAL: how to use it?

Post by formica » Tue Sep 19, 2017 4:43 pm

Hi all,
I'm using micropython on a custom board with STM32F439ZIT6 and an external SRAM connected to the FMC port (Flexible Memory Controller).
I guess that there is no micropython module to use it.
So, I'm considering two alternatives:
1. Writing a module upon the Cubo STMHAL library, exporting the functions to micropython
2. Accessing the SRAM in Asm/Thumb

Any Idea or suggestion?
Regards

User avatar
dhylands
Posts: 3240
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: External SRAM with STMHAL: how to use it?

Post by dhylands » Tue Sep 19, 2017 8:23 pm

Depending on how the SRAM will be used, you could adjust the linker map so that the heap comes out of that memory. Not sure of performance implications.

There are also some posts in the forum about accessing the 4K RAM area that the RTC has.
viewtopic.php?f=6&t=953

You could use the same technique for accessing the FMC SRAM.

formica
Posts: 6
Joined: Thu Mar 30, 2017 10:47 pm

Re: External SRAM with STMHAL: how to use it?

Post by formica » Thu Sep 21, 2017 3:17 pm

Ok, I'm trying to follows your hints.
I didn't test the code enough but this is my first try:
[code]
import stm

#### GPIO INIT ###
### GPIOx_MODER INIT - Offset: 0x00 #####
stm.mem32[stm.GPIOD + 0x00] |= 0xAAAA0A0A
stm.mem32[stm.GPIOE + 0x00] |= 0xAAAA8A8A
stm.mem32[stm.GPIOF + 0x00] |= 0xAA000AAA
stm.mem32[stm.GPIOG + 0x00] |= 0x00080AAA

### GPIOx_AFRL INIT - Offset: 0x20 ######
stm.mem32[stm.GPIOD + 0x20] |= 0x00220022 ## or 0x00320022
stm.mem32[stm.GPIOE + 0x20] |= 0x30003023
stm.mem32[stm.GPIOF + 0x20] |= 0x00111222
stm.mem32[stm.GPIOF + 0x20] |= 0x00111111

### GPIOx_AFRH INIT - Offset: 0x24 ######
stm.mem32[stm.GPIOD + 0x24] |= 0x22232222
stm.mem32[stm.GPIOE + 0x24] |= 0x23333233
stm.mem32[stm.GPIOF + 0x24] |= 0x11110000
stm.mem32[stm.GPIOG + 0x24] |= 0x00000020 ## or 0x00000030

### GPIOx_OTYPER INIt - Offset: 0x04 ####
stm.mem32[stm.GPIOD + 0x04] |= 0x00000000
stm.mem32[stm.GPIOE + 0x04] |= 0x00000000
stm.mem32[stm.GPIOF + 0x04] |= 0x00000000
stm.mem32[stm.GPIOG + 0x04] |= 0x00000000

### GPIOx_PUPDR INIt - Offset: 0x0C #####
stm.mem32[stm.GPIOD + 0x0C] |= 0x00000000
stm.mem32[stm.GPIOE + 0x0C] |= 0x00000000
stm.mem32[stm.GPIOF + 0x0C] |= 0x00000000
stm.mem32[stm.GPIOG + 0x0C] |= 0x00000000

### GPIOx_PUPDR INIt - Offset: 0x08 #####
stm.mem32[stm.GPIOD + 0x08] |= 0xFFFF0F0F
stm.mem32[stm.GPIOE + 0x08] |= 0xFFFFC0CF
stm.mem32[stm.GPIOF + 0x08] |= 0xFF000FFF
stm.mem32[stm.GPIOG + 0x08] |= 0x000C0FFF

#### END GPIO INIT #####

#### RCC CLOCK INIT #####################

stm.mem32[stm.RCC_AHB1ENR] |= 0x00000078
stm.mem32[stm.RCC_AHB3RSTR] |= 0x00000001
stm.mem32[stm.RCC_AHB3ENR] |= 0x00000001

#### END RCC CLOCK INIT #################

#### FMC INIT ###########################

stm.mem32[0xA0000000] |= 0x00081091 ## or 0x00089091
stm.mem32[0xA0000004] |= 0x00110202
stm.mem32[0xA0000104] |= 0x00110202 ## maybe not neeeded

#### TRY TO WRITE AND READ #############
stm.mem32[0x64000000] = 0 ## Try to use 0x64000002

[/code]

After running it with ampy, entering in REPL and trying to write/read I obtain this:

[code]
>>> stm.mem32[0x64000000] = 1
>>> stm.mem32[0x64000000]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: address 64000003 is not aligned to 4 bytes
[/code]

Any idea?

Post Reply