Skip to content

Update MIMXRT clocking to hopefully fix deep sleep, fix boot issues on Teensy4 #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ target_sources(mbed-mimxrt105x
sleep.c
trng_api.c
us_ticker.c
fsl_clock_config.c
clock_config.c
PeripheralPins.c
pinmap.c
specific.c
mimxrt_clock_adjustment.c
lpm.c
mbed_overrides.c

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,39 @@

#include "PeripheralPins.h"

// Note on MIMXRT pin functions:
// The MIMXRT's pin function system is pretty dang complicated, and Mbed's pin function data for this chip
// (the 3rd element in each pinmap entry) has to be pretty complicated to match.
// It's a 32-bit bitfield with the following format:
// __________________________________________________________________________________________________
// | | | | |
// | Daisy Reg Value (bits 19:16) | Daisy Register (bits 15:4) | SION (bit 3) | Mux Mode (bits 2:0) |
// |_______________________________|____________________________|______________|_____________________|
//
// Mux mode:
// This value gets written to the IOMUXC_SW_MUX_CTL_PAD_xxx.MUX_MODE bitfield for the given pin.
// It's a number from 0 to 7 that selects the possible mux mode.
// See Table 10-1 in the datasheet for the possible muxing options
//
// SION:
// This is a somewhat unusual setting used to "force the pin mode to input regardless of MUX_MODE
// functionality". It's a setting needed for certain peripherals to work that use pins in input mode.
// I'm not quite sure of the logic for when to use it...
//
// Daisy Register:
// If nonzero, this field specifies the offset for a "daisy chain register" to use when setting up the pin
// function. "Daisy chain" is actually kinda a misnomer, this register is used to select which of multiple
// pin options a peripheral is connected to, it doesn't daisy chain pins together. It would be better to
// call it "top-level mux register" or something.
//
// The daisy register is specified as an offset relative to the IOMUXC peripheral base. For example, for the
// LPI2C3 peripheral, the daisy chain register for SCL is IOMUXC_LPI2C3_SDA_SELECT_INPUT. So, since the address
// of that register is IOMUXC + 0x4E0, I'd put 0x4E0 as the daisy register.
//
// Daisy Reg Value:
// Numeric option to select in the above daisy register, if the address is given.
//

/************RTC***************/
const PinMap PinMap_RTC[] = {
{NC, OSC32KCLK, 0},
Expand Down Expand Up @@ -62,15 +95,15 @@ const PinMap PinMap_I2C_SCL[] = {
/************UART***************/
const PinMap PinMap_UART_TX[] = {
{GPIO_AD_B0_12, UART_1, 2},
{GPIO_AD_B1_06, UART_3, 2},
{GPIO_AD_B0_02, UART_6, 2},
{GPIO_AD_B1_06, UART_3, ((0 << DAISY_REG_VALUE_SHIFT) | (0x53C << DAISY_REG_SHIFT) | 2)},
{GPIO_AD_B0_02, UART_6, ((1 << DAISY_REG_VALUE_SHIFT) | (0x554 << DAISY_REG_SHIFT) | 2)},
{NC , NC , 0}
};

const PinMap PinMap_UART_RX[] = {
{GPIO_AD_B0_13, UART_1, 2},
{GPIO_AD_B1_07, UART_3, 2},
{GPIO_AD_B0_03, UART_6, 2},
{GPIO_AD_B1_07, UART_3, ((0 << DAISY_REG_VALUE_SHIFT) | (0x538 << DAISY_REG_SHIFT) | 2)},
{GPIO_AD_B0_03, UART_6, ((1 << DAISY_REG_VALUE_SHIFT) | (0x550 << DAISY_REG_SHIFT) | 2)},
{NC , NC , 0}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ const uint8_t dcd_data[] = {
0x40, 0x1F, 0x82, 0xA8, 0x00, 0x01, 0x10, 0xF9,
/* #1.95, command: write_value, address: SEMC_MCR, value: 0x10000004, size: 4 */
0x40, 0x2F, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04,
/* #1.96, command: write_value, address: SEMC_BMCR0, value: 0x30524, size: 4 */
/* #1.96, command: write_value, address: SEMC_BMCR0, value: 0x81, size: 4 */
0x40, 0x2F, 0x00, 0x08, 0x00, 0x00, 0x00, 0x81,
/* #1.97, command: write_value, address: SEMC_BMCR1, value: 0x6030524, size: 4 */
/* #1.97, command: write_value, address: SEMC_BMCR1, value: 0x81, size: 4 */
0x40, 0x2F, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x81,
/* #1.98, command: write_value, address: SEMC_BR0, value: 0x8000001B, size: 4 */
0x40, 0x2F, 0x00, 0x10, 0x80, 0x00, 0x00, 0x1B,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@

// This file is adapted from bootdata.c in the Teensy4 Arduino core.
// https://github.com/PaulStoffregen/cores/blob/a2368ad57e9470608a234d942c55a2278c6cd72b/teensy4/bootdata.c
// The only changes made were:
// - Section names had to be modified to match what is expected by Mbed's linker script.
// - #define names had to be modified to match Mbed
// - _flashimagelen replaced with __USED_FLASH_END
// - _flashimagelen replaced with __USED_FLASH_SIZE
// - ResetHandler replaced with Reset_Handler

/* Teensyduino Core Library
* http://www.pjrc.com/teensy/
* Copyright (c) 2017 PJRC.COM, LLC.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
Expand Down Expand Up @@ -40,14 +43,14 @@

extern void Reset_Handler(void);
extern unsigned long _estack;
extern unsigned long __USED_FLASH_END;
extern unsigned long __USED_FLASH_SIZE;



__attribute__ ((section(".boot_hdr.boot_data"), used))
const uint32_t BootData[3] = {
0x60000000,
(uint32_t)&__USED_FLASH_END,
(uint32_t)&__USED_FLASH_SIZE,
0
};

Expand Down
Loading