обновлен bootloader, в SS все функции, связанные с прерываниями, вынесены в ram. на 115200 работает, но в обработчике нужная функция вызывается напрямую

This commit is contained in:
klassents committed 2024-10-08 13:15:45 +07:00
1 parent d228bc7ff9
commit 8f2f29987b
4 files changed
+252 -249

No files matched your search

+18 -29
View File
@@ -34,7 +34,7 @@ volatile uint8_t SoftwareSerial::_receive_buffer_head = 0;
// Private methods
// function placed in ram. Should not call other function placed in flash
void SoftwareSerial::tunedDelay(uint32_t delayTicks)
void SoftwareSerial::tunedDelay(uint32_t delayTicks) // .ram_text
{
if (delayTicks > 1)
{
@@ -82,25 +82,25 @@ bool SoftwareSerial::stopListening()
//
// The receive routine called by the interrupt handler
//
void SoftwareSerial::recv()
void SoftwareSerial::recv() // .ram_text
{
uint8_t data = 0;
// If RX line is high, then we don't see any start bit
// so interrupt is probably not for us
bool rxState = (bool)GPIO_READ_PIN((GPIO_TypeDef *)_receivePortRegister, (HAL_PinsTypeDef)_receiveBitMask);
if (_inverse_logic ? rxState : !rxState)
{
// Disable further interrupts during reception, this prevents
// triggering another interrupt directly after we return, which can
// cause problems at higher baudrates.
setRxIntMsk(false); // __always_inline__
// Wait approximately 1/2 of a bit width to "center" the sample
tunedDelay(_rx_delay_centering); // __always_inline__
if (_rx_delay_centering > 0)
tunedDelay(_rx_delay_centering); // .ram_text
GPIO_0->OUTPUT_ ^= GPIO_PIN_1;
// Read each of the 8 bits
uint8_t data = 0;
for (uint8_t i=8; i > 0; --i)
{
tunedDelay(_rx_delay_intrabit);
@@ -147,7 +147,7 @@ uint8_t SoftwareSerial::rx_pin_read()
// Interrupt handling
/* static */
inline void SoftwareSerial::handle_interrupt()
void SoftwareSerial::handle_interrupt() // .ram_text
{
if (active_object)
{
@@ -155,7 +155,8 @@ inline void SoftwareSerial::handle_interrupt()
}
}
extern "C" void softSerial_handler_wrapper(void)
extern "C" void softSerial_handler_wrapper(void) __attribute__((noinline, section(".ram_text")));
extern "C" void softSerial_handler_wrapper(void)
{
SoftwareSerial::handle_interrupt();
}
@@ -237,28 +238,16 @@ void SoftwareSerial::begin(long speed)
// Only setup rx when we have a valid INT for this pin
if (digitalPinToInterrupt(_receivePin) != NOT_AN_INTERRUPT)
{
// We want to have a total delay of 1.5 bit time from start bit.
// Inside the loop, we already wait for 1 bit time, so here we
// wait for 0.5 bit time
// _rx_delay_centering = subtract_cap(bit_delay / 2, 750); // spifi
_rx_delay_centering = subtract_cap(bit_delay / 2, 315); // ram
// 1 bit time
// _rx_delay_intrabit = subtract_cap(bit_delay, 200); // spifi
_rx_delay_intrabit = subtract_cap(bit_delay, 60); // ram
// This delay aims at 3/4 of a bit time, meaning the end of the
// delay will be at 1/4th of the stopbit. This allows some extra
// time for ISR cleanup, which makes 115200 baud at 16Mhz work more
// reliably
// _rx_delay_stopbit = subtract_cap(bit_delay * 3 / 4, 950); // spifi
_rx_delay_stopbit = subtract_cap(bit_delay * 3 / 4, 142); // ram
// We want to have a total delay of 1.5 bit time from start bit. Inside the loop, we already
// wait for 1 bit time, so here we wait for 0.5 bit time
_rx_delay_centering = subtract_cap(bit_delay / 2, 315);
if (speed==115200)
{
_rx_delay_intrabit = subtract_cap(_rx_delay_intrabit, 10);
_rx_delay_stopbit+=30;
}
// 1 bit time
_rx_delay_intrabit = subtract_cap(bit_delay, 60);
// This delay aims at 3/4 of a bit time, meaning the end of the delay will be at 1/4th of the stopbit.
// This allows some extra time for ISR cleanup, which makes 115200 baud at 16Mhz work more reliably
_rx_delay_stopbit = subtract_cap(bit_delay * 3 / 4, 142);
// Save gpio_line for turning on/off interrupts
_int_maskLine = digitalPinToGpioIntLine(_receivePin);
@@ -274,7 +263,7 @@ void SoftwareSerial::begin(long speed)
tunedDelay(_tx_delay); // if we were low this establishes the end
// todo убрать
HAL_GPIO_PinConfig(GPIO_0, GPIO_PIN_8, HAL_GPIO_MODE_GPIO_OUTPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
HAL_GPIO_PinConfig(GPIO_0, GPIO_PIN_0, HAL_GPIO_MODE_GPIO_OUTPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
HAL_GPIO_PinConfig(GPIO_0, GPIO_PIN_1, HAL_GPIO_MODE_GPIO_OUTPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
listen();
@@ -64,7 +64,7 @@ private:
static SoftwareSerial *active_object;
// private methods
inline void recv() __attribute__((__always_inline__));
void recv() __attribute__((noinline, section(".ram_text")));
uint8_t rx_pin_read();
void setTX(uint8_t transmitPin);
void setRX(uint8_t receivePin);
@@ -103,7 +103,7 @@ public:
using Print::write;
// public only for easy access by interrupt handlers
static inline void handle_interrupt() __attribute__((__always_inline__));
static void handle_interrupt() __attribute__((noinline, section(".ram_text")));
};
#endif