Questions about stm class

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
photoacoustic
Posts: 24
Joined: Mon Apr 27, 2015 8:25 am

Questions about stm class

Post by photoacoustic » Mon Apr 27, 2015 10:36 am

Dear all,
I just begin with micropython. For instant, I use STM32F4 discovery board. Thanks a lot to micropython team! This is a very great tool!
I would like to play the stm class in order to get access to the MCU registers.
I see some examples in th micropython doc. But these example use inline assembler.
Is it possible to use this class without inline assembler?
I have try the following lines in REPL without success!
--- my input
GPIOD_BaseAdr=stm.GPIOD
GPIOD_BSRRL_Adr=stm.GPIO_BSRRL+GPIOD_BaseAdr
-- my output
No error but I don't know the effect!

Thanks in advance for comments and suggestions
Best regards

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

Re: Questions about stm class

Post by dhylands » Mon Apr 27, 2015 5:45 pm

stm.GPIOD is a numeric constant containing the address of the GPIOD register, stm.GPIO_BSRRL is a numeric constant containing the offset of the BSSRL register within the GPIO peripheral.

To actually modify the register you need to use the stm.mem8, mem16, or mem32 commands.

Something like:

Code: Select all

import stm
stm.mem16(stm.GPIOD + stm.GPIO_BSRRL, 1)
should set D0 and

Code: Select all

import stm
stm.mem16(stm.GPIOD + stm.GPIO_BSRRH, 1)
should clear D0.

photoacoustic
Posts: 24
Joined: Mon Apr 27, 2015 8:25 am

Re: Questions about stm class

Post by photoacoustic » Mon Apr 27, 2015 8:48 pm

Thanks very much!
I will adopt micropython for my courses! Having high level and low level approach is very nice for teaching.
Thanks again.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Questions about stm class

Post by Damien » Wed Apr 29, 2015 9:11 pm

Actually, you need to use the mem8, mem16 and mem32 functions like an array:

Code: Select all

import stm
stm.mem16[stm.GPIOD + stm.GPIO_BSRRL] = 1 # set D0 high
stm.mem16[stm.GPIOD + stm.GPIO_BSRRH] = 1 # set D0 low
dport = stm.mem32[stm.GPIOD + stm.GPIO_IDR] # read all 16 bits on port D

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

Re: Questions about stm class

Post by dhylands » Thu Apr 30, 2015 12:03 am

Sigh - My bad for not testing my suggestion

Post Reply