Skip to content

Commit 88b794b

Browse files
committed
Fix for bare metal core1
1 parent 6657de1 commit 88b794b

7 files changed

Lines changed: 31 additions & 24 deletions

File tree

.github/workflows/push-master.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ jobs:
8484
cmake -DOVERRIDE_BOOT_WORKAROUND=ON -DOVERRIDE_DATA_PIN=14 -DCMAKE_BUILD_TYPE=Release ..
8585
cmake --build .
8686
rm ../firmware/*_Spi.uf2
87+
rm ../firmware/*_ws2801.uf2
8788
zip -j ../firmware/Adafruit_ItsyBitsy_RP2040.zip ../firmware/*
8889
8990
- uses: actions/upload-artifact@v7.0.0
@@ -104,6 +105,7 @@ jobs:
104105
cmake -DOVERRIDE_DATA_PIN=15 -DCMAKE_BUILD_TYPE=Release ..
105106
cmake --build .
106107
rm ../firmware/*_Spi.uf2
108+
rm ../firmware/*_ws2801.uf2
107109
zip -j ../firmware/Pimoroni_Plasma_Stick_RP2040_W.zip ../firmware/*
108110
109111
- uses: actions/upload-artifact@v7.0.0

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pico_sdk_init()
6868

6969
# generic HyperSerialPico settings
7070
set(HyperSerialPicoCompanionIncludes ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/sdk/config)
71-
set(HyperSerialPicoCompanionLibs FreeRTOS-Kernel freertos_config FreeRTOS-Kernel-Heap4 pico_stdlib pico_multicore hardware_pio hardware_dma hardware_spi)
71+
set(HyperSerialPicoCompanionLibs FreeRTOS-Kernel freertos_config FreeRTOS-Kernel-Heap1 pico_stdlib pico_multicore hardware_pio hardware_dma hardware_spi)
7272
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/generated)
7373
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/firmware)
7474

include/base.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class Base
4646
TaskHandle_t processDataHandle = nullptr;
4747
TaskHandle_t processSerialHandle = nullptr;
4848
// semaphore to synchronize them
49-
semaphore_t serialSemaphore;
5049
SemaphoreHandle_t receiverSemaphore;
5150
// current queue position
5251
volatile int queueCurrent = 0;

include/calibration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class CalibrationConfig
129129
void printCalibration(char (&output)[N])
130130
{
131131
snprintf(output, N, "RGBW => Gain: %i/255, red: %i, green: %i, blue: %i\r\n", gain, red, green, blue);
132-
fputs(output, stdout);
132+
tud_cdc_write_str(output);
133133
}
134134
} calibrationConfig;
135135

include/main.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ void processData()
7373
if (base.queueCurrent >= MAX_BUFFER)
7474
{
7575
base.queueCurrent = 0;
76-
yield();
7776
}
7877

7978
switch (frameState.getState())
@@ -294,8 +293,6 @@ void processData()
294293
currentTime = millis();
295294
deltaTime = currentTime - statistics.getStartTime();
296295
updateMainStatistics(currentTime, deltaTime, true);
297-
298-
yield();
299296
}
300297

301298
frameState.setState(AwaProtocol::HEADER_A);

include/statistics.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,23 @@ class
130130
multicore_fifo_push_blocking(0xFF);
131131
}
132132

133-
void printToSerial(TaskHandle_t taskHandle1, TaskHandle_t taskHandle2)
133+
void printToSerial(TaskHandle_t taskHandleCore0)
134134
{
135135
char output[128];
136136

137-
snprintf(output, sizeof(output), "HyperHDR frames: %u (FPS), receiv.: %u, good: %u, incompl.: %u, mem1: %i, mem2: %i, heap: %zu\r\n",
137+
snprintf(output, sizeof(output), "HyperHDR frames: %u (FPS), receiv.: %u, good: %u, incompl.: %u, core0: %i, heap: %zu\r\n",
138138
finalShowFrames, finalTotalFrames,finalGoodFrames,(finalTotalFrames - finalGoodFrames),
139-
(taskHandle1 != nullptr) ? uxTaskGetStackHighWaterMark(taskHandle1) : 0,
140-
(taskHandle2 != nullptr) ? uxTaskGetStackHighWaterMark(taskHandle2) : 0,
139+
(taskHandleCore0 != nullptr) ? uxTaskGetStackHighWaterMark(taskHandleCore0) : 0,
141140
xPortGetFreeHeapSize());
142-
fputs(output, stdout);
141+
tud_cdc_write_str(output);
143142

144143
#if defined(NEOPIXEL_RGBW)
145144
calibrationConfig.printCalibration(output);
146145
#endif
147146

148147
if (welcomeMessage.exchange(false))
149148
{
150-
fputs(HELLO_MESSAGE, stdout);
149+
tud_cdc_write_str(HELLO_MESSAGE);
151150
}
152151
}
153152

source/main.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "FreeRTOS.h"
3232
#include "task.h"
33+
#include "tusb.h"
3334
#include "pico/multicore.h"
3435
#include "hardware/irq.h"
3536
#include "semphr.h"
@@ -136,10 +137,8 @@ static void core1()
136137
{
137138
for( ;; )
138139
{
139-
if (sem_acquire_timeout_us(&base.serialSemaphore, portMAX_DELAY))
140-
{
141-
processData();
142-
}
140+
[[maybe_unused]] auto val = multicore_fifo_pop_blocking();
141+
processData();
143142
}
144143
}
145144

@@ -153,7 +152,11 @@ static void core0( void *pvParameters )
153152
do
154153
{
155154
wanted = std::min(MAX_BUFFER - base.queueEnd, MAX_BUFFER - 1);
156-
received = stdio_usb.in_chars((char*)(&(base.buffer[base.queueEnd])), wanted);
155+
156+
if (stdio_usb_connected() && tud_cdc_available()) {
157+
received = (int)tud_cdc_read(const_cast<uint8_t*>(&(base.buffer[base.queueEnd])), (uint32_t)wanted);
158+
}
159+
157160
if (received > 0)
158161
{
159162
base.queueEnd = (base.queueEnd + received) % (MAX_BUFFER);
@@ -162,19 +165,28 @@ static void core0( void *pvParameters )
162165

163166
if (statistics.printLogs.exchange(false))
164167
{
165-
statistics.printToSerial(base.processDataHandle, base.processSerialHandle);
168+
statistics.printToSerial(base.processSerialHandle);
169+
tud_cdc_write_flush();
170+
vTaskDelay(pdMS_TO_TICKS(5));
166171
}
167172

168-
sem_release(&base.serialSemaphore);
173+
multicore_fifo_push_blocking(0xAA);
169174
}
170175
}
171176
}
172177

173178
static void serialEvent(void *)
174179
{
175-
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
176-
xSemaphoreGiveFromISR(base.receiverSemaphore, &xHigherPriorityTaskWoken);
177-
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
180+
if (xPortIsInsideInterrupt())
181+
{
182+
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
183+
xSemaphoreGiveFromISR(base.receiverSemaphore, &xHigherPriorityTaskWoken);
184+
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
185+
}
186+
else
187+
{
188+
xSemaphoreGive(base.receiverSemaphore);
189+
}
178190
}
179191

180192
void on_fifo_irq()
@@ -190,8 +202,6 @@ int main(void)
190202
{
191203
stdio_init_all();
192204

193-
sem_init(&base.serialSemaphore, 0, 1);
194-
195205
base.receiverSemaphore = xSemaphoreCreateBinary();
196206

197207
multicore_fifo_clear_irq();

0 commit comments

Comments
 (0)