Skip to content

Conversation

@sago35
Copy link
Member Author

sago35 commented May 10, 2020

I have confirmed the following.

  • Each field of arm.SCB has the correct address.
  • The CPACR is 0x00F00000 at the beginning of main().
  • Do not crash with feather-m4 and pyportal
    • I don't have any other boards.

result:

temperature: 79.699997
value : {00F00000} => {00F00000}
CPUID    : E000ED00
ICSR     : E000ED04
VTOR     : E000ED08
AIRCR    : E000ED0C
SCR      : E000ED10
CCR      : E000ED14
SHP[0]   : E000ED1C
SHP[1]   : E000ED20
SHCSR    : E000ED24
CFSR     : E000ED28
HFSR     : E000ED2C
DFSR     : E000ED30
MMFAR    : E000ED34
BFAR     : E000ED38
AFSR     : E000ED3C
ID_PFR0  : E000ED40
ID_PFR1  : E000ED44
ID_DFR0  : E000ED48
ID_AFR0  : E000ED4C
ID_MMFR0 : E000ED50
ID_MMFR1 : E000ED54
ID_MMFR2 : E000ED58
ID_MMFR3 : E000ED5C
ID_ISAR0 : E000ED60
ID_ISAR1 : E000ED64
ID_ISAR2 : E000ED68
ID_ISAR3 : E000ED6C
ID_ISAR4 : E000ED70
CPACR    : E000ED88

testcode:

package main

import (
	"fmt"
	"machine"
	"time"
	"unsafe"

	"runtime/volatile"

	"device/arm"

	"tinygo.org/x/drivers/adt7410"
)

var (
	i2c    = &machine.I2C0
	sensor = adt7410.New(i2c, 0)
)

func enableCortexM4FPU() {
	// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0439b/BEHBJHIG.html
	cpacraddr := (*uint32)(unsafe.Pointer(uintptr(0xE000ED88)))
	tmp := *cpacraddr
	tmp |= (0xF << 20)
	volatile.StoreUint32(cpacraddr, tmp)
}

func main() {
	orgCPACR := arm.SCB.CPACR
	//enableCortexM4FPU()

	led := machine.LED
	led.Configure(machine.PinConfig{Mode: machine.PinOutput})

	i2c.Configure(machine.I2CConfig{Frequency: machine.TWI_FREQ_400KHZ})
	sensor.Configure()

	cnt := 0
	for {
		temp := sensor.ReadTempF()
		fmt.Printf("temperature: %f\r\n", temp)
		fmt.Printf("value : %08X => %08X\r\n", orgCPACR, arm.SCB.CPACR)
		fmt.Printf("CPUID    : %08X\r\n", &(arm.SCB.CPUID.Reg))
		fmt.Printf("ICSR     : %08X\r\n", &(arm.SCB.ICSR.Reg))
		fmt.Printf("VTOR     : %08X\r\n", &(arm.SCB.VTOR.Reg))
		fmt.Printf("AIRCR    : %08X\r\n", &(arm.SCB.AIRCR.Reg))
		fmt.Printf("SCR      : %08X\r\n", &(arm.SCB.SCR.Reg))
		fmt.Printf("CCR      : %08X\r\n", &(arm.SCB.CCR.Reg))
		fmt.Printf("SHP[0]   : %08X\r\n", &(arm.SCB.SHP[0].Reg))
		fmt.Printf("SHP[1]   : %08X\r\n", &(arm.SCB.SHP[1].Reg))
		fmt.Printf("SHCSR    : %08X\r\n", &(arm.SCB.SHCSR.Reg))
		fmt.Printf("CFSR     : %08X\r\n", &(arm.SCB.CFSR.Reg))
		fmt.Printf("HFSR     : %08X\r\n", &(arm.SCB.HFSR.Reg))
		fmt.Printf("DFSR     : %08X\r\n", &(arm.SCB.DFSR.Reg))
		fmt.Printf("MMFAR    : %08X\r\n", &(arm.SCB.MMFAR.Reg))
		fmt.Printf("BFAR     : %08X\r\n", &(arm.SCB.BFAR.Reg))
		fmt.Printf("AFSR     : %08X\r\n", &(arm.SCB.AFSR.Reg))
		fmt.Printf("ID_PFR0  : %08X\r\n", &(arm.SCB.ID_PFR0.Reg))
		fmt.Printf("ID_PFR1  : %08X\r\n", &(arm.SCB.ID_PFR1.Reg))
		fmt.Printf("ID_DFR0  : %08X\r\n", &(arm.SCB.ID_DFR0.Reg))
		fmt.Printf("ID_AFR0  : %08X\r\n", &(arm.SCB.ID_AFR0.Reg))
		fmt.Printf("ID_MMFR0 : %08X\r\n", &(arm.SCB.ID_MMFR0.Reg))
		fmt.Printf("ID_MMFR1 : %08X\r\n", &(arm.SCB.ID_MMFR1.Reg))
		fmt.Printf("ID_MMFR2 : %08X\r\n", &(arm.SCB.ID_MMFR2.Reg))
		fmt.Printf("ID_MMFR3 : %08X\r\n", &(arm.SCB.ID_MMFR3.Reg))
		fmt.Printf("ID_ISAR0 : %08X\r\n", &(arm.SCB.ID_ISAR0.Reg))
		fmt.Printf("ID_ISAR1 : %08X\r\n", &(arm.SCB.ID_ISAR1.Reg))
		fmt.Printf("ID_ISAR2 : %08X\r\n", &(arm.SCB.ID_ISAR2.Reg))
		fmt.Printf("ID_ISAR3 : %08X\r\n", &(arm.SCB.ID_ISAR3.Reg))
		fmt.Printf("ID_ISAR4 : %08X\r\n", &(arm.SCB.ID_ISAR4.Reg))
		fmt.Printf("CPACR    : %08X\r\n", &(arm.SCB.CPACR.Reg))

		if cnt%2 == 0 {
			led.High()
		} else {
			led.Low()
		}
		cnt++
		time.Sleep(time.Second)
	}

}

@sago35
Copy link
Member Author

sago35 commented May 10, 2020

I've changed it to the following, but is this good?

  • Create an initFPU() and call it immediately after preinit().

@aykevl
Copy link
Member

aykevl commented May 12, 2020

Thank you for this contribution!

I've looked further into it and found the underlying issue, which I've fixed in #1105.
With that found (and hopefully soon merged), I don't think there is a reason to enable the FPU. It will consume power and use more stack space in interrupts when enabled.
However, we might want to use the FPU in the future. Therefore I'm leaving this PR open for now. It will be useful once full support for the FPU is included in TinyGo.

@deadprogram
Copy link
Member

Closing due to age. Thanks to everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants