Code: Select all
#
# MAIN.PY
#
import micropython
import array
class FloatingPointMath:
def __init__(self):
self.x = array.array('f', [0.0])
self.y = array.array('f', [0.0])
self.res = array.array('f', [0.0])
# multiplication in assembler
@staticmethod
@micropython.asm_thumb
def f_mult(r0, r1, r2):
vldr(s0, [r1, 0])
vldr(s1, [r2, 0])
vmul(s1, s1, s0)
vstr(s1, [r0, 0])
# function call for external use
def mult(self, a, b):
self.x[0] = a
self.y[0] = b
self.f_mult(self.res, self.x, self.y)
return self.res
def isr(timer):
global f
global output # used as global to expose to REPL
input1 = 1.2 # causes no problem
input2 = 2.0
output = f.mult(input1, input2) # array('f', [2.4])
result = output[0] # causes MemoryError exception
f = FloatingPointMath()
output = array.array('f', [0.0])
timer_test = pyb.Timer(3)
timer_test.init(freq = 1)
timer_test.callback(isr)